Web3.js Contract Reads: When to Use .call() Instead of .send()
A practical web3.js decision: use eth.Contract .call() for view/pure reads and .send() for state-changing transactions, with an ERC-20 balance example and verification steps.
08 Feb 2026, 06:57 UTC

The problem: a read that looks like a transaction
If your dApp asks a user to sign a wallet prompt just to display a token balance, the contract call is probably being sent as a transaction. In web3.js, that choice is explicit: contract.methods.balanceOf(address).call() reads state, while .send() submits a state-changing transaction. The useful rule is simple: use .call() for view and pure functions, and .send() only when the function is meant to mutate storage, transfer ether, emit an approval, or change balances.
What .call() actually does
web3.eth.Contract wraps an ABI so JavaScript can encode arguments and decode return values. When you invoke .call(), web3.js sends an eth_call JSON-RPC request to the connected node. The node executes the function against its current state, usually the latest block, and returns the encoded result. No transaction is broadcast, no gas is spent, and no account is required.
That makes .call() the right tool for UI data: balances, allowances, metadata, prices, ownership checks, and preflight validation before a write.
What .send() actually commits
.send() creates a transaction. It needs a sender, a gas budget, and a provider or wallet that can sign and broadcast. The return path is different too: you may get a transaction hash immediately, then a receipt after inclusion. If the transaction reverts, the state change is rolled back, but gas may still be consumed depending on the network and provider behavior.
Use .send() for transfers, mints, approvals, and any function whose ABI marks it non-view or non-payable.
| Decision | .call() | .send() |
|---|---|---|
| JSON-RPC intent | eth_call | eth_sendTransaction or raw signed transaction |
| State change | No | Yes |
| Gas | None | Required |
| Account/wallet | Not required | Required |
| Typical return | Decoded return value | Transaction hash, then receipt |
Worked example: read an ERC-20 balance
These examples target web3.js v4.x with ESM imports. In v1.x, use CommonJS and the older provider setup; the .call()/.send() split remains the same.
Run the install command in your project terminal:
npm install web3@4
npm list web3
Expected check: npm list web3 shows a 4.x version. If it shows 1.x, adjust imports and provider construction before copying the script.
Create read-balance.mjs:
import { Web3 } from 'web3';
const RPC_URL = process.env.RPC_URL; // e.g. a testnet RPC endpoint
const TOKEN_ADDRESS = '0xTOKEN_CONTRACT_ADDRESS';
const WALLET_ADDRESS = '0xWALLET_ADDRESS';
const erc20Abi = [
{
name: 'balanceOf',
type: 'function',
stateMutability: 'view',
inputs: [{ name: 'account', type: 'address' }],
outputs: [{ name: 'balance', type: 'uint256' }],
},
{
name: 'decimals',
type: 'function',
stateMutability: 'view',
inputs: [],
outputs: [{ name: '', type: 'uint8' }],
},
];
const web3 = new Web3(RPC_URL);
const token = new web3.eth.Contract(erc20Abi, TOKEN_ADDRESS);
const rawBalance = await token.methods.balanceOf(WALLET_ADDRESS).call();
const decimals = await token.methods.decimals().call();
console.log({ rawBalance, decimals });
Run it with RPC_URL=https://your-testnet-rpc.example node read-balance.mjs. Required permissions are only read access to the RPC endpoint; the script contains no private key. Expected check: the command finishes without a wallet prompt and logs a raw balance plus decimals. The raw value is in the token's smallest unit; use decimals for display. Exact JavaScript types for uint256 can vary by web3.js version and ABI handling, so check typeof rawBalance before doing arithmetic.
Do not use .send() for this read. On a testnet only, you can observe that token.methods.balanceOf(WALLET_ADDRESS).send({ from: ACCOUNT }) is not a safe read: some providers may reject it, while others may accept it as a no-op transaction that still consumes gas. Never run that experiment on mainnet.
Limits that change the decision
- The RPC node is trusted for reads.
.call()does not independently verify output. A compromised or misconfigured node can return fabricated state. Compare two independent RPC endpoints for sensitive values. - ABI mismatches fail silently or incorrectly. If the ABI does not match the deployed contract, decoding can fail or return wrong values. web3.js does not verify the ABI against on-chain bytecode.
- Writes are not rollback-able. A submitted
.send()transaction cannot be undone. Check the receipt status and events, and expect fees even for failed state changes on many networks. - Version drift is real. Provider setup and package entry points differ between web3.js v1.x and v4.x. Confirm the installed major version and compare the Contract API with the matching documentation.
Actionable check before shipping
- Run
npm list web3and record the major version. - Audit every contract interaction: if the ABI function is
vieworpure, it must use.call(). - For writes, require an explicit user action and a funded signer; never trigger
.send()from a page-load read path. - Verify reads against a second RPC provider and verify writes by receipt status plus expected events.
The split is stable, but the trust boundary is not: .call() tells you what a node says, not necessarily what the chain says.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.