Skip to main content
Version: Current

Generating utility modules

The squid-evm-typegen(1) tool generates TypeScript facades for EVM transactions, logs and eth_call queries.

The generated facades are assumed to be used by squids indexing EVM data.

The tool takes a JSON ABIs as an input. Those can be specified in three ways:

  1. as a plain JSON file(s):

    npx squid-evm-typegen src/abi abi/erc20.json

    To include all files in ./abi and add an interface for the Multicall contract, run

    npx squid-evm-typegen ./src/abi ./abi/*.json --multicall
  2. as a contract address (to fetch the ABI from Etherscan API). Once can pass multiple addresses at once.

    npx squid-evm-typegen src/abi 0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413
info

Please check if your contract is a proxy when using this method. If it is, consult this page for guidance.

  1. as an arbitrary URL:

    npx squid-evm-typegen src/abi https://example.com/erc721.json

In all cases typegen will use basename of the ABI as the root name for the generated files. You can change the basename of generated files using the fragment (#) suffix.

squid-evm-typegen src/abi 0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413#my-contract-name

Arguments:

output-diroutput directory for generated definitions
abiA contract address, an URL or a local path to the ABI file. Accepts multiple contracts.

Options:

--multicallgenerate a facade for the MakerDAO multicall contract. May significantly improve the performance of contract state calls by batching RPC requests
--etherscan-api <url>etherscan API to fetch contract ABI by a known address. By default, https://api.etherscan.io/
--cleandelete output directory before the run
-h, --helpdisplay help for command

Usage

The generated utility modules have three intended uses:

  1. Constants: EVM log topic0 values and sighashes for transactions. Example:

    // generated by evm-typegen
    import * as weth from './abi/weth'

    const CONTRACT_ADDRESS = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'.toLowerCase()

    const processor = new EvmBatchProcessor()
    .setGateway('https://v2.archive.subsquid.io/network/ethereum-mainnet')
    .addLog({
    address: [CONTRACT_ADDRESS],
    topic0: [
    weth.events.Deposit.topic,
    weth.events.Withdrawal.topic
    ]
    })
  2. Decoding of EVM logs and transactions

  3. Direct chain state queries, including queries to multicall.