Skip to main content
The Contract classes generated by squid-evm-typegen wrap eth_call state queries. They need a JSON-RPC endpoint to talk to: the Portal data source does not use one and the handler context provides no built-in chain access, so construct a client explicitly with RpcClient from @subsquid/rpc-client:
We recommend using a private endpoint from e.g. BlastAPI or the SQD Cloud’s RPC addon, and setting it via an environment variable. You can define the RPC_ETH_HTTP in three ways:
  • for local runs, simply update the local .env file;
  • for squids deployed to Cloud define it as a secret on your Cloud account;
  • if you are using the RPC addon, leave it to the Cloud to define it for you.

Contract class

The EVM contract state is accessed using the Contract class generated by squid-evm-typegen. Its constructor takes
  1. a chain access object - anything of the shape {_chain: {client}}, where client has a call(method, params) method; an RpcClient instance fits;
  2. a block reference - any object with a height field; the state is queried at that block height;
  3. the contract address.
For example, assume that we index an ERC721 contract. Typescript ABI module generated with squid-evm-typegen will contain the following class:
Now suppose we want to query our contract from the batch handler. Create a Contract with the RPC client and the current block, then query the contract state at that block:

Batch state queries

The MakerDAO Multicall contract was designed to batch multiple state queries into a single contract call. In the context of indexing, it normally significantly improves the indexing speed since JSON RPC calls are typically the bottleneck. Multicall contracts are deployed in many EVM chains, see the contract repo for addresses. You can use any of them with a multicall Typescript module that is generated when running squid-evm-typegen with --multicall option. The module exports a Multicall class with this method:
The arguments are as follows:
  • func: the contract function to be called
  • calls: an array of tuples [contractAddress: string, args]. Each specified contract will be called with the specified arguments.
  • pageSize is an optional maximum number of calls per JSON-RPC request. Large page sizes may cause timeouts.
The generated class also accepts one shared contract address plus an array of argument objects, or an array of [function, address, arguments] tuples for mixed calls. aggregate() has the same overloads but throws when a call fails. Multicall is constructed exactly like the other generated Contract classes - with a chain access object, a block reference and the address of a deployed Multicall contract. A typical usage is as follows:
src/main.ts