Moonbeam EVM Support

2021-11-24 About 3 min

# Moonbeam EVM Support

We provide a custom data source processor for Moonbeam's and Moonriver's EVM. This offers a simple way to filter and index both EVM and Substrate activity on Moonbeam's networks within a single SubQuery project.

Supported networks:

Network Name Websocket Endpoint Dictionary Endpoint
Moonbeam Coming soon Coming soon
Moonriver wss://moonriver.api.onfinality.io/public-ws https://api.subquery.network/sq/subquery/moonriver-dictionary
Moonbase Alpha wss://moonbeam-alpha.api.onfinality.io/public-ws https://api.subquery.network/sq/subquery/moonbase-alpha-dictionary

You can also refer to the basic Moonriver EVM example project (opens new window) with an event and call handler. This project is also hosted live in the SubQuery Explorer here (opens new window).

# Getting started

  1. Add the custom data source as a dependency yarn add @subql/contract-processors
  2. Add a custom data source as described below
  3. Add handlers for the custom data source to your code

# Data Source Spec

Field Type Required Description
processor.file './node_modules/@subql/contract-processors/dist/moonbeam.js' Yes File reference to the data processor code
processor.options ProcessorOptions No Options specific to the Moonbeam Processor
assets { [key: String]: { file: String }} No An object of external asset files

# Processor Options

Field Type Required Description
abi String No The ABI that is used by the processor to parse arguments. MUST be a key of assets
address String or null No A contract address where the event is from or call is made to. null will capture contract creation calls

# MoonbeamCall

Works in the same way as substrate/CallHandler except with a different handler argument and minor filtering changes.

Field Type Required Description
kind 'substrate/MoonbeamCall' Yes Specifies that this is an Call type handler
filter Call Filter No Filter the data source to execute

# Call Filters

Field Type Example(s) Description
function String 0x095ea7b3, approve(address to,uint256 value) Either Function Signature (opens new window) strings or the function sighash to filter the function called on the contract
from String 0x6bd193ee6d2104f14f94e2ca6efefae561a4334b An Ethereum address that sent the transaction

# Handlers

Unlike a normal handler you will not get a SubstrateExtrinsic as the parameter, instead you will get a MoonbeamCall which is based on Ethers TransactionResponse (opens new window) type.

Changes from the TransactionResponse type:

  • It doesn't have wait and confirmations properties
  • A success property is added to know if the transaction was a success
  • args is added if the abi field is provided and the arguments can be successfully parsed

# MoonbeamEvent

Works in the same way as substrate/EventHandler except with a different handler argument and minor filtering changes.

Field Type Required Description
kind 'substrate/MoonbeamEvent' Yes Specifies that this is an Event type handler
filter Event Filter No Filter the data source to execute

# Event Filters

Field Type Example(s) Description
topics String array Transfer(address indexed from,address indexed to,uint256 value) The topics filter follows the Ethereum JSON-PRC log filters, more documentation can be found here (opens new window).

Note on topics: There are a couple of improvements from basic log filters:

# Handlers

Unlike a normal handler you will not get a SubstrateEvent as the parameter, instead you will get a MoonbeamEvent which is based on Ethers Log (opens new window) type.

Changes from the Log type:

  • args is added if the abi field is provided and the arguments can be successfully parsed

# Data Source Example

This is an extract from the project.yaml manifest file.

dataSources:
  - kind: substrate/Moonbeam
    startBlock: 752073
    processor:
      file: './node_modules/@subql/contract-processors/dist/moonbeam.js'
      options:
        # Must be a key of assets
        abi: erc20
        # Contract address (or recipient if transfer) to filter, if `null` should be for contract creation
        address: '0x6bd193ee6d2104f14f94e2ca6efefae561a4334b'
    assets:
      erc20:
        file: './erc20.abi.json'
    mapping:
      file: './dist/index.js'
      handlers:
        - handler: handleMoonriverEvent
          kind: substrate/MoonbeamEvent
          filter:
            topics:
              - Transfer(address indexed from,address indexed to,uint256 value)
        - handler: handleMoonriverCall
          kind: substrate/MoonbeamCall
          filter:
            ## The function can either be the function fragment or signature
            # function: '0x095ea7b3'
            # function: '0x7ff36ab500000000000000000000000000000000000000000000000000000000'
            # function: approve(address,uint256)
            function: approve(address to,uint256 value)
            from: '0x6bd193ee6d2104f14f94e2ca6efefae561a4334b'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

# Known Limitations

  • There is currently no way to query EVM state within a handler
  • There is no way to get the transaction receipts with call handlers
  • blockHash properties are currently left undefined, the blockNumber property can be used instead
Last update: November 24, 2021 02:27