Skip to content

Discord

Discord is one of the most popular chat platforms, and is great to build bots and notifications when things happen on chain.

Setup a bot on discord

  1. go to https://discordapp.com/developers/applications/
  2. If you already have a bot created, click it in the list. If you don’t have any discord bots, click the “New Application” button.
  3. Give Your Bot a Name (you can then after add a description and icon for it)
  4. Your next step is to go over the menu on the left side of the screen and click “Bot”. It’s the icon that looks like a little puzzle piece.
  5. Click the “Add Bot” button and press "Yes, do it!"
  6. You see a section called “Token” you need to generate your bot token and save it somewhere safe for later.
  7. In order to add your bot to your Discord Server, you’ll need to navigate back to the “OAuth2” tab.
  8. Once there, scroll down to the “Oauth2 URL Generator” section. In the “Scopes” section, you’ll want to select the “bot” checkbox.
  9. You’ll notice that a URL appeared as soon as you clicked “bot” — this will be your URL for adding your bot to a server.
  10. Scroll down some more to the “Bot Permissions” section. This is where you choose what permissions to give your bot, and what it can and can’t do.
  11. You want to do tick "Send messages" as rindexer does not read any messages from the server.
  12. After you’ve selected your permissions, scroll up a little bit and look at the URL that was generated and copy and go to that url in your browser.
  13. Here you’ll want to select the server you’re adding your bot to and press “Continue”
  14. It then confirm permissions make sure you have ticked "Send Messages" and press "Authorize"
  15. You are now done you will need the bot token to setup the discord bot with rindexer

Configure rindexer

discord property accepts an array allowing you to split up the channels any way you wish.

Example

name: RocketPoolETHIndexer
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
contracts:
- name: RocketPoolETH
  details:
  - network: ethereum
    address: "0xae78736cd615f374d3085123a210448e74fc6393"
    start_block: "18600000"
    end_block: "18600181"
  abi: "./abis/RocketTokenRETH.abi.json"
  include_events:
  - Transfer
  chat: 
    discord: 
      - bot_token: ${DISCORD_BOT_TOKEN}
        channel_id: 123456789012345678
        networks: 
          - ethereum
        messages:
          - event_name: Transfer
            # conditions are optional
            conditions: 
              - "from": "0x0338ce5020c447f7e668dc2ef778025ce3982662||0x0338ce5020c447f7e668dc2ef778025ce398266u"
              - "value": ">=10||<=2000000000000000000"
            template_inline: "*New RETH Transfer Event*
 
                              from: {{from}}
 
                              to: {{to}}
 
                              amount: {{format_value(value, 18)}}
 
                              RETH contract: {{transaction_information.address}}
 
                              [etherscan](https://etherscan.io/tx/{{transaction_information.transaction_hash}})
                              "

bot_token

This is your discord bot token which you generate using @BotFather.

...
contracts:
- name: RocketPoolETH
  details:
  - network: ethereum
    address: "0xae78736cd615f374d3085123a210448e74fc6393"
    start_block: "18600000"
    end_block: "18600181"
  abi: "./abis/RocketTokenRETH.abi.json"
  include_events:
  - Transfer
  chat: 
    discord: 
      - bot_token: ${DISCORD_BOT_TOKEN}

channel_id

You have add your bot to channel to use it, so this is the channel ID you wish the bot to send messages to.

...
contracts:
- name: RocketPoolETH
  details:
  - network: ethereum
    address: "0xae78736cd615f374d3085123a210448e74fc6393"
    start_block: "18600000"
    end_block: "18600181"
  abi: "./abis/RocketTokenRETH.abi.json"
  include_events:
  - Transfer
  chat: 
    discord: 
      - bot_token: ${DISCORD_BOT_TOKEN}
        channel_id: -4223616270

networks

This is an array of networks you want to send messages to this discord channel.

rindexer.yaml
...
contracts:
- name: RocketPoolETH
  details:
  - network: ethereum
    address: "0xae78736cd615f374d3085123a210448e74fc6393"
    start_block: "18600000"
    end_block: "18600181"
  abi: "./abis/RocketTokenRETH.abi.json"
  include_events:
  - Transfer
  chat: 
    discord: 
      - bot_token: ${DISCORD_BOT_TOKEN}
        channel_id: 123456789012345678
        networks: 
          - ethereum

messages

This is an array of messages you want to send to this discord channel. It is an array as you can define many different messages to send to this channel with different conditions.

event_name

This is the name of the event you want to send a message for, must match the ABI event name.

rindexer.yaml
...
contracts:
- name: RocketPoolETH
  details:
  - network: ethereum
    address: "0xae78736cd615f374d3085123a210448e74fc6393"
    start_block: "18600000"
    end_block: "18600181"
  abi: "./abis/RocketTokenRETH.abi.json"
  include_events:
  - Transfer
  chat: 
    discord: 
      - bot_token: ${DISCORD_BOT_TOKEN}
        channel_id: 123456789012345678
        networks:
          - ethereum
        messages:
          - event_name: Transfer

conditions

This accepts an array of conditions you want to apply to the event data before sending a message to this discord channel.

You may want to filter on the message based on the event data, if the event data has not got an index on the on the solidity event you can not filter it over the logs. The conditions filter is here to help you with this, based on your ABI you can filter on the event data.

rindexer has enabled a special syntax which allows you to define on your ABI fields what you want to filter on.

  1. > - higher then (for numbers only)
  2. < - lower then (for numbers only)
  3. = - equals
  4. >= - higher then or equals (for numbers only)
  5. <= - lower then or equals (for numbers only)
  6. || - or
  7. && - and

So lets look at an example lets say i only want to get transfer events which are higher then 2000000000000000000 RETH wei

rindexer.yaml
...
contracts:
- name: RocketPoolETH
  details:
  - network: ethereum
    address: "0xae78736cd615f374d3085123a210448e74fc6393"
    start_block: "18600000"
    end_block: "18600181"
  abi: "./abis/RocketTokenRETH.abi.json"
  include_events:
  - Transfer
  chat: 
    discord: 
      - bot_token: ${DISCORD_BOT_TOKEN}
        channel_id: 123456789012345678
        networks:
          - ethereum
        messages:
          - event_name: Transfer
            conditions: 
              - "value": ">=2000000000000000000"

We use the ABI input name value to filter on the value field, you can find these names in the ABI file.

{
    "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 use the || or && to combine conditions.

rindexer.yaml
...
contracts:
- name: RocketPoolETH
  details:
  - network: ethereum
    address: "0xae78736cd615f374d3085123a210448e74fc6393"
    start_block: "18600000"
    end_block: "18600181"
  abi: "./abis/RocketTokenRETH.abi.json"
  include_events:
  - Transfer
  chat: 
    discord: 
      - bot_token: ${DISCORD_BOT_TOKEN}
        channel_id: 123456789012345678
        networks:
          - ethereum
        messages:
          - event_name: Transfer
            conditions: 
              - "value": ">=2000000000000000000 && value <=4000000000000000000"

You can use the = to filter on other aspects like the from or to address.

rindexer.yaml
...
contracts:
- name: RocketPoolETH
  details:
  - network: ethereum
    address: "0xae78736cd615f374d3085123a210448e74fc6393"
    start_block: "18600000"
    end_block: "18600181"
  abi: "./abis/RocketTokenRETH.abi.json"
  include_events:
  - Transfer
  chat: 
    discord: 
      - bot_token: ${DISCORD_BOT_TOKEN}
        channel_id: 123456789012345678
        networks:
          - ethereum
        messages:
          - event_name: Transfer
              conditions: 
                - "from": "0x0338ce5020c447f7e668dc2ef778025ce3982662 || 0x0338ce5020c447f7e668dc2ef778025ce398266u"
                - "value": ">=2000000000000000000 || value <=4000000000000000000"

If you have a tuple and you want to get that value you just use the object notation.

For example lets say we want to only get the events for profileId from the quoteParams tuple which equals 1:

{
     "anonymous": false,
     "inputs": [
       {
         "components": [
           {
             "internalType": "uint256",
             "name": "profileId", 
             "type": "uint256"
           },
           ...
         ],
         "indexed": false,
         "internalType": "struct Types.QuoteParams",
         "name": "quoteParams", 
         "type": "tuple"
       },
       ...
     ],
     "name": "QuoteCreated", 
     "type": "event"
}
rindexer.yaml
...
contracts:
- name: RocketPoolETH
  details:
  - network: ethereum
    address: "0xae78736cd615f374d3085123a210448e74fc6393"
    start_block: "18600000"
    end_block: "18600181"
  abi: "./abis/RocketTokenRETH.abi.json"
  include_events:
  - Transfer
  chat: 
    discord: 
      - bot_token: ${DISCORD_BOT_TOKEN}
        channel_id: 123456789012345678
        networks:
          - ethereum
        messages:
          - event_name: Transfer
            conditions: 
              - "quoteParams.profileId": "=1"

template_inline

You can then write your own template inline, this is the template you want to send to the channel. You have to use the ABI input names in object notation for example if i wanted to put value in the template i just have to write {{value}} in the template and it will be replaced with the value of the event itself.

The template supports:

  • bold text = *bold text*
  • italic text = _italic text_
  • inline url = [inline URL](YOUR_URL)
  • inline fixed-width code = `inline fixed-width code`
  • pre-formatted fixed-width code block = ```pre-formatted fixed-width code block```
  • pre-formatted fixed-width known code block = ```rust pre-formatted fixed-width known code block```
  • breaks = just line break in the template

transaction_information

You also can use the transaction_information object to get common information about the transaction, this is the transaction information for the event.

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct TxInformation {
    pub network: String,
    // This will convert to a hex string in the template
    pub address: Address,
    // This will convert to a hex string in the template
    pub block_hash: H256,
    // This will convert to a string decimal in the template
    pub block_number: U64,
    // This will convert to a hex string in the template
    pub transaction_hash: H256,
    // This will convert to a string decimal in the template
    pub log_index: U256,
    // This will convert to a string decimal in the template
    pub transaction_index: U64,
}

format_value

You can use the format_value function to format the value of the event to a decimal value with the specified decimals.

Lets put it all together:

rindexer.yaml
...
contracts:
- name: RocketPoolETH
  details:
  - network: ethereum
    address: "0xae78736cd615f374d3085123a210448e74fc6393"
    start_block: "18600000"
    end_block: "18600181"
  abi: "./abis/RocketTokenRETH.abi.json"
  include_events:
  - Transfer
  chat: 
    discord: 
      - bot_token: ${DISCORD_BOT_TOKEN}
        channel_id: 123456789012345678
        networks:
          - ethereum
        messages:
          - event_name: Transfer
            template_inline: "*New RETH Transfer Event*
 
                              from: {{from}}
 
                              to: {{to}}
 
                              amount: {{format_value(value, 18)}}
 
                              RETH contract: {{transaction_information.address}}
 
                              [etherscan](https://etherscan.io/tx/{{transaction_information.transaction_hash}})
                              "