joshstevens19 / rindexer

A no-code blazing fast EVM indexer tool built in rust.
https://rindexer.xyz
MIT License
283 stars 26 forks source link

All ERC20 transfers to/from a certain address #82

Closed nareto closed 2 months ago

nareto commented 2 months ago

Hi, thanks for the cool project. Can I use this to index all token transfers to/from a certain address, without knowning in advance the tokens that will be transferred and their ABIs?

joshstevens19 commented 2 months ago

Hey yes tokens do follow a standard ABI which you can copy in and then use the filter alongside the indexed parameter to filter on them https://rindexer.xyz/docs/start-building/yaml-config/contracts#indexed_1-indexed_2-indexed_3

Lets say I want to get all the erc20 tokens which were transferred from 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 alongside i also want to get all transfers which were sent to 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 starting from block 18600000 (that address is Vitaliks btw)

The ABI for transfer is:

  {
    "anonymous":false,
    "inputs":[
      {
        "indexed":true,
        "internalType":"address",
        "name":"from",
        "type":"address"
      },
      {
        "indexed":true,
        "internalType":"address",
        "name":"to",
        "type":"address"
      },
      {
        "indexed":false,
        "internalType":"uint256",
        "name":"value",
        "type":"uint256"
      }
    ],
    "name":"Transfer",
    "type":"event"
  },

you can see above from and to are indexed: true

I would then do a YAML like this

name: Indexer
description: My first rindexer project
repository: https://github.com/joshstevens19/rindexer
project_type: no-code
networks:
  - name: ethereum
    chain_id: 1
    rpc: https://mainnet.gateway.tenderly.co
storage:
  postgres:
    enabled: true
contracts:
  - name: FromTransferEvents
    details:
      - network: ethereum
        start_block: 18600000
        filter:
          event_name: Transfer
        indexed_filters:
          - event_name: Transfer
            indexed_1:
              - "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
    abi: ./abis/erc20.abi.json
    include_events:
      - Transfer
  - name: ToTransferEvents
    details:
      - network: ethereum
        start_block: 18600000
        filter:
          event_name: Transfer
        indexed_filters:
          - event_name: Transfer
            indexed_2:
              - "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
    abi: ./abis/erc20.abi.json
    include_events:
      - Transfer

at the moment you can't have more then 1 filter in the same contract YAML so you have to define it twice and this will also generates you 2 tables but all the data will resync for you.. is that what you was looking for?

nareto commented 2 months ago

thanks, yes this looks exactly like what I was asking for. Will try it!