RPC_ETH_HTTP in three ways:
- for local runs, simply update the local
.envfile; - 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:
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 amulticall Typescript module that is generated when running squid-evm-typegen with --multicall option. The module exports a Multicall class with this method:
func: the contract function to be calledcalls: an array of tuples[contractAddress: string, args]. Each specified contract will be called with the specified arguments.pagingan (optional) argument for the maximal number of calls to be batched into a single JSON PRC request. Note that large page sizes may cause timeouts.
src/main.ts
ctx._chain.
It exposes low-level methods for accessing the storage. However, the recommended way to query the storage is with type-safe wrappers generated with squid-substrate-typegen.
Substrate typegen tool exposes storage access wrappers at src/types/storage.ts. The wrappers follow the general naming pattern used by Substrate typegen:
get() query method and, if available, methods for multi-key queries, listing keys, key-value pairs and retrieving the default value.
Note that the generated getters always query historical blockchain state at the height derived from their block argument.
Here is an example of one such wrapper:
src/types/balances/storage.ts
- the default storage value with
getDefault(block) - a single storage value with
get(block, key) - multiple values in a batch call with
getMany(block, keys[]) - all storage keys with
getKeys(block) - all keys with a given prefix with
getKeys(block, keyPrefix)(only if the storage keys are decodable) - paginated keys via
getKeysPaged(pageSize, block)andgetKeysPaged(pageSize, block, keyPrefix) - key-value pairs via
getPairs(block)andgetPairs(block, keyPrefix) - paginated key-value pairs via
getPairsPaged(pageSize, block)andgetPairsPaged(pageSize, block, keyPrefix)
Example
src/main.ts
Contract class provides facades for all state calls that don’t mutate the contract state. The info about the state mutability is taken from the contract metadata.

