Table of Contents

EVM node

Note
Examples below are for Ethereum mainnet. For other supported networks, see EVM Networks.

DipDup can connect to any EVM-compatible node via JSON-RPC. It can be used as a "last mile" datasource for EVM indexes (data that is not in Subsquid Network yet) or as a standalone datasource for handlers and hooks.

The example below shows how to connect to Alchemy node for Ethereum mainnet, but you can use any as long as it has all the necessary data (e.g. archive node).

dipdup.yaml
datasources:
  evm_node:
    kind: evm.node
    url: ${NODE_URL:-https://eth-mainnet.g.alchemy.com/v2}/${NODE_API_KEY:-''}
    ws_url: ${NODE_WS_URL:-wss://eth-mainnet.g.alchemy.com/v2}/${NODE_API_KEY:-''}

Then, add it to EVM index definitions:

dipdup.yaml
indexes:
  eth_usdt_events:
    kind: evm.events
    datasources:
      - subsquid
      - etherscan
      - evm_node
    handlers:
      - callback: on_transfer
        contract: eth_usdt
        name: Transfer

web3 client

web3.py is a popular Python library for interacting with Ethereum nodes. Every node datasource has a web3 client instance attached to it. You can use it in handlers and hooks to fetch data from the node and perform other actions.

Warning
Don't initialize web3 clients manually! It will break the connection pooling, lock the event loop, and kill your dog.

To access the client, use web3 property of the datasource. The underlying web3 client is asynchronous, so you should use await keyword to call its methods.

web3: AsyncWeb3 = ctx.get_evm_node_datasource('evm_node').web3
contract = self.web3.eth.contract(...)
symbol = await contract.functions.symbol().call()

Each datasource has its own web3 client instance, so you can use it safely in parallel. web3 clients respect http configuration from the datasource config when making requests.

Help and tips -> Join our Discord
Ideas or suggestions -> Issue Tracker
GraphQL IDE -> Open Playground
Table of Contents