Returns the result of executing the transaction, using call
. A call does not require any ether, but cannot change any state. This is useful for calling getters on Contracts.
Don’t have an API key?
Start using this method in your app today.
Description
Returns the result of executing the transaction using call
. A call does not require any ether but cannot change any state. This is useful for calling getters on Contracts.
Starting from Geth 1.9.13,
eth_call
will check the balance of the sender (to make sure that the sender has enough gas to complete the request) before executing the call when one of the following conditions is true:
- the
gas_price
parameter is populated, or- the contract function being called (i.e. in data modifies blockchain state)
In these two cases, even though the
eth_call
requests don't consume any gas, the from address must have enough gas to execute the call as if it were a write transaction becauseeth_call
is being used to simulate the transaction.
Note
eth_call
has a timeout restriction at the node level. Batching multipleeth_call
together on-chain using pre-deployed smart contracts might result in unexpected timeouts that cause none of your calls to complete. Instead, consider serializing these calls, or using smaller batches if they fail with a node error code.
Parameters
Name | Type | Description |
---|---|---|
transaction | string | The transaction to execute |
blockTag | string / number | The optional block number or hash to get the call for. |
transaction
object parameters
transaction
object parametersParameter | Type | Description |
---|---|---|
to | string | DATA , 20 Bytes - The address the transaction is directed to. |
from | string | DATA , 20 Bytes - (optional) The address the transaction is sent from. |
gasPrice? | number / string | QUANTITY - (optional) Integer of the gasPrice used for each paid gas. |
data? | string | DATA - (optional) Hash of the method signature and encoded parameters. For details see Ethereum Contract ABI |
value? | number | QUANTITY - (optional) Integer of the value sent with this transaction |
nonce? | string | A nonce is a value that represents the number of transactions sent by the sender's address, ensuring the transactions are processed in order and preventing replay attacks. |
gasLimit? | string | The maximum gas allowed. |
chainId? | number | optional the Id of the transaction chain. |
type? | number | Optional This is the type of transaction. |
accessList? | array of strings | The accessList is an optional transaction parameter that specifies addresses and storage keys a transaction interacts with, enabling gas cost optimization and compatibility with future Ethereum upgrades. |
maxPriorityFee? | number | This describes the maximum priority fee for this transaction. |
maxFeePerGas? | number | This is the maximum fee per gas for this transaction. |
ccipReadEnabled? | boolean | This specifies if the CCIP read is enabled. |
Response
Property | Type | Description |
---|---|---|
Promise<string> | string | The method returns the output data as a hexadecimal-encoded string without modifying the blockchain state. |
blocktag
parameters
blocktag
parameterspending
- A sample next block built by the client on top of the latest, containing the set of transactions usually taken from the local mempool. Intuitively, you can think of these as blocks that have not been mined yet.latest
- The most recent block in the canonical chain observed by the client. This block may be re-orged out of the canonical chain even under healthy/normal conditions.safe
- The most recent crypto-economically secure block, cannot be re-orged outside of manual intervention driven by community coordination. Intuitively, this block is “unlikely” to be re-orged.finalized
- The most recent crypto-economically secure block, that has been accepted by >2/3 of validators. Cannot be re-orged outside of manual intervention driven by community coordination. Intuitively, this block is very unlikely to be re-orged.earliest
- The lowest numbered block the client has available. Intuitively, you can think of this as the first block created.
Example Request and Response
Prerequisite: You will need to install the Alchemy SDK before making requests with it.
The commands for installing it using npm or yarn are given below:
npm install alchemy-sdk@latest
yarn add alchemy-sdk@latest
Request
// Imports the Alchemy SDK
const { Alchemy, Network } = require("alchemy-sdk");
// Configures the Alchemy SDK
const config = {
apiKey: "alchemy-replit", // Replace with your API key
network: Network.ETH_MAINNET, // Replace with your network
};
// Creates an Alchemy object instance with the config to use for making requests
const alchemy = new Alchemy(config);
// Example of using the call method
const main = async () => {
//Initialize a variable for the transaction object
let tx = {
to: "0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41",
gas: "0x76c0",
gasPrice: "0x9184e72a000",
data: "0x3b3b57debf074faa138b72c65adbdcfb329847e4f2c04bde7f7dd7fcad5a52d2f395a558",
}
let response = await alchemy.core.call(tx)
//Logging the response to the console
console.log(response)
};
main();
Response
0x0000000000000000000000005555763613a12d8f3e73be831dff8598089d3dca
Code Sandbox
You can test out the call
method using the code sandbox below:
Use Cases
The call
method is used for making low-level calls to the EVM blockchains. It can be used for a variety of use cases, including:
-
Reading data from smart contracts: Developers can use the
call
method to read data from a smart contract on the EVM blockchain. -
Querying blockchain data: Developers can use the
call
method to query blockchain data, such as account balances, transaction history, and block data.
Overall, the call
method is a versatile SDK method that can be used for a wide range of tasks related to interacting with the EVM blockchain.