web3.js: call() for reads, send() for writes, events for transfers
Use web3.js call() for gas-free reads, send() for state-changing transactions, and contract events to update UIs without polling balances.
27 Mar 2026, 16:24 UTC

Start with the decision, not the syntax
You are building a dashboard that displays token balances and lets users send tokens. A common mistake is using send() to check a balance: it works, but it costs gas, requires a wallet signature, and waits for mining. The reverse mistake is treating call() as a confirmed transaction: it returns immediately and never changes state. This post explains when to use each, how to listen for Transfer events, and what to verify before shipping.
Useful takeaway: use call() for read-only state, send() for user-initiated writes, and event subscriptions to update the UI when a transfer is mined.
Read state with contract.methods().call()
call() executes through the Ethereum eth_call JSON-RPC method. It runs locally on the node, costs no gas, requires no signed transaction, and does not modify contract state. Because it reads the node's current view, the result can include pending or unconfirmed data depending on node configuration, and a chain reorganization can change the displayed value later.
Examples assume a recent major release of web3.js; verify your installed version before copying provider or event code.
import { Web3 } from 'web3';
const web3 = new Web3(window.ethereum); // wallet provider such as MetaMask
const contract = new web3.eth.Contract(abi, '0xYourContractAddress');
try {
const balance = await contract.methods.balanceOf('0xUserAddress').call();
console.log('Balance:', balance);
} catch (error) {
// A reverting contract still throws here
console.error('Read failed:', error.message);
}
Where to run: browser frontend or Node script with a connected Ethereum provider. Permissions: the user must connect their wallet and approve account access before window.ethereum is available. Expected check: the call returns a value immediately with no transaction hash. Risk: do not treat the returned balance as final settlement; confirm against a block explorer after any related transaction is mined.
Change state with contract.methods().send()
send() signs and broadcasts a state-changing transaction. It requires an unlocked account or a signer, consumes gas, and returns a receipt only after the transaction is mined. Never place private keys or seed phrases in frontend code; use a wallet provider for browser apps or a backend signer for server-side automation.
try {
const receipt = await contract.methods.transfer('0xRecipientAddress', amount).send({
from: selectedAccount,
gas: 200000, // prefer estimateGas() plus a buffer for complex contracts
});
console.log('Transaction mined:', receipt.transactionHash);
} catch (error) {
console.error('Transaction failed:', error.message);
}
Where to run: frontend with a wallet provider, or a backend process with a signer. Permissions: the signer must authorize the transaction and pay gas. Expected checks: receipt.status indicates success, and receipt.transactionHash can be tracked on a block explorer. Risks: gas estimation can fail or underestimate; once mined, the state change cannot be undone.
Listen for Transfer events instead of polling
Solidity contracts emit events such as ERC-20 Transfer when balances change. web3.js can subscribe to these logs so the UI updates without repeatedly calling balanceOf.
const subscription = contract.events.Transfer({}, (error, event) => {
if (error) {
console.error('Event subscription error:', error);
return;
}
console.log('Transfer detected:', event.returnValues);
// updateUI(event.returnValues.from, event.returnValues.to, event.returnValues.value);
});
// To stop listening:
// subscription.unsubscribe();
Event subscriptions require an Ethereum node that retains logs and supports filters. Very old events may require an archival node. This approach works well for recent transfers but is not a substitute for reconciling balances against on-chain state.
Version assumptions and provider differences
web3.js major versions differ in provider setup, Promise versus Observable APIs, and event subscription syntax. Code written for 1.x may not run unchanged on 4.x. Before adopting the examples above, run:
npm list web3
and review the changelog for the installed major version. The snippets here assume a recent major release with a wallet provider exposed as window.ethereum.
Practical verification
- Run a local Hardhat or Anvil node.
- Deploy a simple ERC-20 contract to that local node.
- Call
balanceOfwithcall()and confirm it returns without gas. - Send a
transferwithsend()and confirm theTransferevent arrives. - Compare the post-transfer balance from
call()against a block explorer or local node state.
This verifies read/write consistency on a controlled network before you connect to mainnet or a testnet.
Limitations
call()can reflect pending state and may change after a reorg; it is not a confirmation.send()changes state irreversibly; replacement requires the same nonce and is an advanced, risky operation.- Event logs depend on node log retention; archival nodes may be needed for historical data.
- Frontend code must never expose private keys or seed phrases.
Closing
For dashboards and read-heavy views, start with call(). For user-initiated transfers, use send() with a wallet provider and handle receipts. Use Transfer event subscriptions for real-time UI updates, then reconcile balances on-chain. Verify the full flow on a local node before shipping.