EVM node
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).
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:
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.
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.