본문으로 건너뛰기

문빔 EVM 지원

SubQuery Team약 1 분

문빔 EVM 지원

문빔과 문리버 EVM을 위한 커스텀 데이터 소스 프로세서를 제공합니다. 단일 서브쿼리 프로젝트 내 문빔 네트워크 상의 EVM과 서브스트레이트 활동을 필터링하고 인덱싱하는 단순한 방법을 제시합니다.

지원되는 네트워크:

네트워크 이름웹소켓 엔드포인트딕셔너리 엔드포인트
문빔wss://moonbeam.api.onfinality.io/public-wshttps://api.subquery.network/sq/subquery/moonbeam-dictionary
문리버`wss://moonriver.api.onfinality.io/public-ws
Contextrequest`https://api.subquery.network/sq/subquery/moonriver-dictionary
문베이스 알파`wss://moonbeam-alpha.api.onfinality.io/public-ws
Contextrequest`https://api.subquery.network/sq/subquery/moonbase-alpha-dictionary

기본 Moonriver EVM 프로젝트open in new window와 더불어 이벤트 및 콜 핸들러를 참조하세요. 또한 본 프로젝트는 서브쿼리 익스플로러open in new window를 통해 실시간 호스팅됩니다.

시작하기

  1. 디펜던시 커스텀 데이터 소스를 추가하세요yarn add @subql/contract-processors
  2. 아래에 나와있는 것처럼 커스텀 데이터소스를 추가하세요
  3. 여러분의 코드에 커스텀 데이터 소스용 핸들러를 추가하세요

데이터 소스 사양

필드타입요구사항설명
processor.file'./node_modules/@subql/contract-processors/dist/moonbeam.js'데이터 프로세서 코드에 대한 파일 참조
processor.optionsProcessorOptions아니오Options specific to the Moonbeam Processor
assets{ [key: String]: { file: String }}아니오An object of external asset files

프로세서 옵션

필드타입요구사항설명
abiString아니오ABI는 프로세서가 인자 파싱을 위해 사용. 반드시 assets의 키여야 합니다
어드레스String 또는 null아니오이벤트 또는 콜이 만들어진 거래 주소. 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.

필드타입요구사항설명
kind'substrate/MoonbeamCall'Specifies that this is an Call type handler
filterCall Filter아니오Filter the data source to execute

Call Filters

필드타입예시설명
functionString0x095ea7b3, approve(address to,uint256 value)Either Function Signatureopen in new window strings or the function sighash to filter the function called on the contract
fromString0x6bd193ee6d2104f14f94e2ca6efefae561a4334bAn Ethereum address that sent the transaction

핸들러

일반 핸들러와는 달리 변수로 SubstrateExtrinsic를 받지 않으며, 이더 TransactionResponseopen in new window 타입 기반의 MoonbeamCall를 받게 됩니다.

TransactionResponse 타입과의 차이:

  • waitconfirmations 특성을 갖지 않습니다.
  • 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.

필드타입요구사항설명
kind'substrate/MoonbeamEvent'Specifies that this is an Event type handler
filterEvent Filter아니오Filter the data source to execute

이벤트 필터

필드타입예시설명
topicsString arrayTransfer(address indexed from,address indexed to,uint256 value)The topics filter follows the Ethereum JSON-PRC log filters, more documentation can be found hereopen in new window.

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

핸들러

일반 핸들러와는 달리 변수로 SubstrateEvent를 받지 않으며, 이더 Logopen in new window 타입 기반의 MoonbeamEvent를 받게 됩니다.

Log 타입과의 차이:

  • abi 필드가 제공되고 인자가 성공적으로 파싱된 경우, args가 포함됩니다.

데이터 소스 예제

본 예제는 project.yaml 매니페스트 파일에서 추출하였습니다.

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"

알려진 제약사항

  • 현재 핸들러 내부에서 EVM 스테이트의 쿼리는 지원하지 않습니다.
  • 콜 핸들러를 통해 거래 명세서를 받을 수 없습니다.
  • 현재 blockHash 특성은 미정의 항목으로 정의되어 있으며, 대신해서 blockNumber 특성 사용이 가능합니다.