Skip to main content
In order to make on-chain calls, one must set up a JSON-RPC endpoint using setRpcEndpoint(). We recommend using a private endpoint from e.g. BlastAPI or the SQD Cloud’s RPC addon, and set 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. It takes a handler context and a contract address as constructor arguments. The state is always accessed at the context block height unless explicitly defined in the constructor.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. To create a Contract pass the context object and the current Block to its constructor, 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.A typical usage is as follows:
src/main.ts