
The eth_call methodology (eth_call
) performs a vital position in Web3 improvement. In spite of everything, it permits dapps to work together with good contracts with out really executing on-chain transactions. When you’re an ETH developer in search of an eth_call instance and find out how to use it throughout your improvement course of, you’ve come to the precise place! On this article, we’ll showcase an instance of the eth_call RPC methodology and present you another resolution as properly. That stated, right here’s one instance of the eth_call methodology:
const Web3 = require('web3'); const web3 = new Web3('YOUR_ETHEREUM_NODE_URL'); const contractAddress="YOUR_CONTRACT_ADDRESS"; const knowledge="YOUR_DATA"; web3.eth.name({ to: contractAddress, knowledge: knowledge }).then(console.log);
Changing the above house holders in caps with the precise values means that you can work together with a wise contract with out modifying the blockchain state. Now, should you’d prefer to dive additional into the eth_call methodology, learn on as we discover the ins and outs of it and in addition spotlight some use instances for this widespread ETH methodology. Nonetheless, as we progress in direction of the top of this text, we’ll additionally take a look at a extra trendy various – the Moralis Blockchain API!
Overview
Though the eth_call instance above is nice, by analyzing it, we additionally acknowledge that there are extra optimum methods of interacting with good contracts. As such, shifting ahead, you’ll have an opportunity to get correctly acquainted with a superior, trendy various to the eth_call RPC methodology – the getBlock endpoint. Nonetheless, earlier than shifting our focus to that endpoint offered by the Moralis Blockchain API, it’s extremely helpful to be acquainted with the unique eth_call methodology. Therefore, we’ll begin this text by overlaying that methodology’s fundamentals, and also you’ll have an opportunity to be taught what eth_call is within the first place. Furthermore, we’ll additionally guarantee you realize what RPC calls are.
Subsequent, we’ll take a look at two further eth_call instance code clusters to additional solidify your understanding of this methodology. Then, we’ll deal with the above-outlined instance and clarify the way it can simply be lined with the getBlock endpoint. That is the place you’ll additionally get an opportunity to be taught extra concerning the Moralis Blockchain API.
After all, in case you’re already acquainted with the eth_call methodology and are simply in search of its trendy substitute, be happy to skip the preliminary sections. As a substitute, dive into the modernized various of the above eth_call instance instantly!

What’s eth_call?
The eth_call methodology is likely one of the JSON-RPC (distant process name) features offered by Ethereum nodes. This methodology means that you can make a read-only or fixed name to a wise contract on the Ethereum blockchain. As such, this methodology has been used to retrieve knowledge from a contract with out making a transaction that might change the state of the blockchain.
Listed below are some key factors concerning the eth_call methodology:
- Learn-Solely: It’s a read-only operation, which means it doesn’t modify the blockchain in any method. It’s helpful for fetching data from a contract’s state variables or executing view or pure features in a contract.
- No Gasoline Price: Because it doesn’t create an on-chain transaction, there are not any fuel prices related to eth_call.
- Enter Information: To make use of eth_call, you should specify the contract tackle, the info (operate name) you need to execute, and the block at which you need to carry out the decision.
- Return Information: The strategy returns the output knowledge from the contract name, usually in hexadecimal format. Chances are you’ll must decode this knowledge right into a human-readable format, relying on the contract’s ABI (software binary interface).
- Error Dealing with: It’s necessary to deal with errors when utilizing eth_call. If the operate name encounters an error or reverts, you’ll must examine the response for an error situation and deal with it appropriately.
- Web3 Libraries: Many Ethereum improvement libraries, akin to Web3.js for JavaScript or ethers.js, present handy interfaces for interacting with Ethereum nodes and making eth_call requests.
Total, eth_call has been a useful gizmo for querying the state of good contracts on the Ethereum blockchain and acquiring data with out making a transaction.

What are RPC calls?
RPC, or distant process name, is a elementary idea in laptop science and community communication. Within the context of blockchain and Ethereum, RPC calls play an important position in enabling interplay with the Ethereum community.
An RPC name is a technique for one program or course of to request the execution of a operate or process in one other program or course of that resides on a distant server. In Ethereum, this implies making requests to an Ethereum node, which serves as a gateway to the blockchain.
Ethereum nodes expose a set of RPC strategies that enable builders to speak with the Ethereum community. These strategies embrace features for studying knowledge from the blockchain, sending transactions, and even deploying good contracts. As defined above, one of many important RPC strategies in Ethereum is the eth_call methodology.
Once you make an eth_call distant process name (RPC), you’re primarily asking an Ethereum node to execute a operate in a wise contract with out making a transaction. That is helpful for retrieving knowledge from the contract’s state or querying the outcomes of view and pure features. Furthermore, any eth_call instance doesn’t alter the state of the blockchain and doesn’t devour any fuel, making it very best for fetching data with out incurring prices.
Total, RPC calls, together with eth_call, are the bridge that connects builders and purposes to the Ethereum blockchain. They permit knowledge retrieval, interplay with good contracts, and the creation of decentralized purposes (dapps), forming the spine of Ethereum’s programmability and utility.

Use Circumstances for eth_call
- Querying Token Balances: You should use eth_call to examine the token stability of an Ethereum tackle inside a selected ERC-20 or ERC-721 token contract. That is helpful for pockets purposes or token explorer instruments.
- Value Oracles: The eth_call methodology can be utilized to entry knowledge from worth oracles, akin to fetching the newest cryptocurrency trade charges. This knowledge is essential for decentralized finance (DeFi) purposes, particularly these involving buying and selling or lending.
- Checking Possession: It’s frequent to make use of eth_call to confirm possession or permissions inside a wise contract. As an example, confirming whether or not an tackle has permission to carry out sure actions in a dapp.
- On-Chain Governance: Many blockchain tasks implement on-chain governance programs. As such, eth_call permits contributors to examine their voting energy in decision-making processes.
- Token Allowance: When interacting with DeFi protocols or decentralized exchanges (DEXs), you could use eth_call to confirm if an tackle has granted permission to spend their tokens on their behalf.
- Decentralized Identification: To confirm identification on a blockchain, you should use eth_call to examine if a selected tackle corresponds to a registered identification. That is necessary for purposes like decentralized social networks or authentication programs.
- Provide Chain Monitoring: In provide chain and logistics options, eth_call may be employed to fetch details about product origins, transport statuses, or authenticity verification, all saved on the blockchain.
- Blockchain Gaming: Blockchain video games usually use eth_call to retrieve in-game merchandise data, participant statistics, or sport state, permitting for transparency and honest gameplay.
- Token Metrics: Traders and merchants use eth_call to entry token metrics, akin to the entire provide, circulating provide, or historic token costs. This data aids in decision-making and portfolio administration.
- Information Verification: In knowledge verification and notarization purposes, eth_call can be utilized to confirm the authenticity of a doc or knowledge saved on the blockchain.

Two Particular eth_call Examples
Beneath, yow will discover two easy examples of code that make the most of the eth_call methodology in Ethereum improvement. These examples assume you have got entry to an Ethereum node and a Web3 library for interplay.
Studying a State Variable
This instance reads a state variable from a wise contract utilizing eth_call. In case you have been to make the most of the code, make sure that to switch the contract tackle and ABI with your personal values:
const Web3 = require('web3'); const web3 = new Web3('YOUR_ETHEREUM_NODE_URL'); const contractAddress="YOUR_CONTRACT_ADDRESS"; const contractABI = [ // Contract ABI goes here ]; const contract = new web3.eth.Contract(contractABI, contractAddress); // Outline the operate selector for the state variable you need to learn const functionSelector = contract.strategies.myStateVariable().encodeABI(); // Make the eth_call web3.eth.name({ to: contractAddress, knowledge: functionSelector, }).then(consequence => { const worth = web3.utils.hexToNumber(consequence); console.log(`Worth of myStateVariable: ${worth}`); });
Calling a View/Pure Perform
On this instance, we’ll name a view or pure operate on a wise contract utilizing eth_call. When you have been to make the most of the code under, don’t neglect to switch the contract tackle and ABI with your personal values:
const Web3 = require('web3'); const web3 = new Web3('YOUR_ETHEREUM_NODE_URL'); const contractAddress="YOUR_CONTRACT_ADDRESS"; const contractABI = [ // Contract ABI goes here ]; const contract = new web3.eth.Contract(contractABI, contractAddress); // Outline the operate selector for the view operate const functionSelector = contract.strategies.myViewFunction(param1, param2).encodeABI(); // Make the eth_call web3.eth.name({ to: contractAddress, knowledge: functionSelector, }).then(consequence => { // Deal with the consequence as wanted console.log(`Results of myViewFunction: ${consequence}`); });
Fast Walkthrough
When you took a correct take a look at the above two eth_call examples, you in all probability observed that they each incorporate the identical traces of code as outlined on the high of this text.
In each instance, the code first requires web3
and an RPC node endpoint. Subsequent, it defines a contract tackle to deal with and the precise knowledge, which may come within the type of the contract’s ABI. Lastly, the code runs web3.eth.name
.
Observe: Be certain to discover the JSON-RPC documentation provided by “ethereum.org”. Within the “eth_call” part, yow will discover all the small print relating to the strategy’s parameters:

An eth_call Instance – Modernized Method
Whereas utilizing eth_call continues to be a authentic method, it’s not the optimum one. For one, it requires you to make use of RPC nodes. Plus, it comes with different limitations, together with decrease pace.
As such, many advancing dapp builders have already changed eth_call with the Moralis Blockchain API. The latter presents a really highly effective getBlock
endpoint. And to make use of it to the identical finish (solely in a extra environment friendly method with higher and sooner outcomes) as eth_call, you’d need to implement these traces of code:
const Moralis = require("moralis").default; const { EvmChain } = require("@moralisweb3/common-evm-utils"); async operate runApp() { await Moralis.begin({ apiKey: "YOUR_API_KEY" }); const blockNumberOrHash = "15863321"; const chain = EvmChain.ETHEREUM; const response = await Moralis.EvmApi.block.getBlock({ blockNumberOrHash, chain, }); console.log(response.toJSON()); } runApp();
By trying on the above traces of code, you’ll be able to see that no RPC node is required. As a substitute, you solely want to make use of your Moralis API key, which you’ll entry with a free account.
We encourage you to go to the “Get block by hash” Blockchain API reference web page. There, you’ll be able to strive the above traces of code for any of the supported blockchains. By doing so, you’ll see the immense worth of the getBlock
methodology’s response. In spite of everything, it presents a variety of on-chain particulars that may be plugged into your dapp improvement.

The Advantages of the Trendy Path of Fetching On-Chain Information
As already talked about above, the core good thing about utilizing Moralis’ getBlock
endpoint over eth_call is effectivity. This contemporary method is sooner, presents enhanced safety protocols, and fetches a wider vary of knowledge with a single name. What’s extra, when you receive your Moralis API key to make use of getBlock
, you additionally achieve entry to different Moralis Web3 APIs. These mean you can cowl all the above-listed use instances for eth_call however in a less complicated, extra environment friendly method.
In truth, with the Moralis Web3 API fleet in your aspect, you get to create all types of dapps with minimal fuss. These instruments mean you can keep away from reinventing the wheel and as a substitute commit your time and assets to creating the absolute best consumer expertise.
As an example, you’ll be able to fetch any token stability with the getWalletTokenBalances
endpoint. Or, maybe you need to question an ERC-20 token spender allowance? In that case, getTokenAllowance
can be the go-to endpoint.
The above two endpoints are simply two of many different highly effective and environment friendly shortcuts that the Moralis Token API presents. And when you plug in different APIs (see the listing under), there’s merely no dapp you’ll be able to’t construct with time and assets to spare!

Going Past getBlock – Moralis API Fleet
The present Moralis API fleet allows you to cowl all facets of dapp improvement with as few traces of code as potential. Listed below are a number of the merchandise that make that potential:

With few exceptions, just like the Market Information API, you should use the above-listed Web3 APIs with a free Moralis account. Plus, these APIs assist all of the main blockchain networks, which lets you effortlessly construct cross-chain dapps.
Full eth_call RPC Technique Instance Walkthrough – Abstract
All through the above sections, we lined fairly a distance. We first ensured that you simply all know what eth_call and RPCs are. Thus, you now know eth_call is a JSON-RPC operate offered by Ethereum nodes. As for the RPC calls, you discovered that they allow interplay with the Ethereum community by way of Ethereum nodes.
Subsequent, we listed many eth_call use instances, together with querying token balances, worth oracles, checking possession, and so on.
Then, we even offered two particular eth_call instance code clusters. These examples reminded you that the eth_call methodology must be utilized in mixture with different strategies for many cases.
Nonetheless, we defined that there’s a extra environment friendly, superior method of fetching on-chain knowledge with Moralis’ getBlock
endpoint. We even confirmed you find out how to use that endpoint when working with JavaScript. So, you now know that this method eliminates the necessity for an RPC node. Moreover, it presents effectivity, enhanced safety, and a variety of knowledge with a single name.
Transferring ahead, we advocate you be taught extra about particular Moralis APIs and their endpoints. To that finish, other than the Moralis documentation, the Moralis weblog may be extraordinarily precious. A few of the newest articles clarify find out how to get an ERC-20 token tackle, what ERC-4337 is, find out how to get the present worth of an NFT, and rather more.
So, what subsequent? Decide which Moralis APIs to make use of, create your free Moralis account, and construct an superior dapp!