Skip to content
On this page

call โ€‹

Executes a new message call immediately without submitting a transaction to the network.

Usage โ€‹

ts
import { account, publicClient } from './config'
 
const data = await publicClient.call({ 
  account,
  data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})
ts
import { createPublicClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet } from 'viem/chains'

// JSON-RPC Account
export const account = '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
// Local Account
export const account = privateKeyToAccount('0x...')

export const publicClient = createPublicClient({
  chain: mainnet,
  transport: http()
})

Returns โ€‹

0x${string}

The call data.

Parameters โ€‹

account โ€‹

  • Type: Account | Address

The Account to call from.

Accepts a JSON-RPC Account or Local Account (Private Key, etc).

ts
const data = await publicClient.call({
  account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', 
  data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})

data โ€‹

  • Type: 0x${string}

A contract hashed method call with encoded args.

ts
const data = await publicClient.call({
  account,
  data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', 
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})

to โ€‹

The contract address or recipient.

ts
const data = await publicClient.call({
  account,
  data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', 
})

accessList (optional) โ€‹

The access list.

ts
const data = await publicClient.call({
  account,
  accessList: [ 
    {
      address: '0x1',
      storageKeys: ['0x1'],
    },
  ],
  data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})

gas (optional) โ€‹

  • Type: bigint

The gas provided for transaction execution.

ts
const data = await publicClient.call({
  account,
  data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
  gas: 1_000_000n, 
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})

gasPrice (optional) โ€‹

  • Type: bigint

The price (in wei) to pay per gas. Only applies to Legacy Transactions.

ts
const data = await publicClient.call({
  account,
  data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
  gasPrice: parseGwei('20'), 
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})

maxFeePerGas (optional) โ€‹

  • Type: bigint

Total fee per gas (in wei), inclusive of maxPriorityFeePerGas. Only applies to EIP-1559 Transactions.

ts
const data = await publicClient.call({
  account,
  data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
  maxFeePerGas: parseGwei('20'), 
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})

maxPriorityFeePerGas (optional) โ€‹

  • Type: bigint

Max priority fee per gas (in wei). Only applies to EIP-1559 Transactions.

ts
const data = await publicClient.call({
  account,
  data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
  maxFeePerGas: parseGwei('20'),
  maxPriorityFeePerGas: parseGwei('2'), 
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})

nonce (optional) โ€‹

  • Type: bigint

Unique number identifying this transaction.

ts
const data = await publicClient.call({
  account,
  data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
  nonce: 420n, 
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})

value (optional) โ€‹

  • Type: bigint

Value (in wei) sent with this transaction.

ts
const data = await publicClient.call({
  account,
  data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: parseEther('1'), 
})

blockNumber (optional) โ€‹

  • Type: number

The block number to perform the call against.

ts
const data = await publicClient.call({
  blockNumber: 15121123n, 
  account,
  data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})

blockTag (optional) โ€‹

  • Type: 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'
  • Default: 'latest'

The block tag to perform the call against.

ts
const data = await publicClient.call({
  blockTag: 'safe', 
  account,
  data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
})

JSON-RPC Methods โ€‹

eth_call

Released under the MIT License.