Skip to content

subsquid-labs/squid-megaeth-example

Repository files navigation

WETH transfers on MegaETH

This squid captures all Transfer(address,address,uint256) events emitted by the WETH token system contract. It keeps up with network updates in real time using only the SQD Portal data.

Dependencies: NodeJS v20 or newer, Docker.

Quickstart

git clone https://github.com/subsquid-labs/squid-megaeth-example
cd squid-megaeth-example
npm ci
npm run build
docker compose up -d
node -r dotenv/config lib/main.js

then in a separate terminal navigate to the squid-megaeth-example folder and run

npx squid-graphql-server

A GraphiQL playground will be available at localhost:4350/graphql.

Development

The example is mostly compatible with the current docs. Highlights:

Direct RPC calls

The only feature that's left out of this example is direct RPC calls using the native Squid SDK tooling. You can add it back in if you need it.

  1. Install the native RPC client

    npm install @subsquid/rpc-client @subsquid/util-internal
  2. Create the RPC client object and add it to the enriched batch context

    +import {assertNotNull} from '@subsquid/util-internal'
    +import {RpcClient} from '@subsquid/rpc-client'
    +const rpcClient = new RpcClient({
    +  url: assertNotNull(
    +    process.env.RPC_MEGAETH_HTTP,
    +    'This example requires supplying RPC_MEGAETH_HTTP for contract calls'
    +  ),
    +})
       const ctx = {
         ...simpleCtx,
         blocks: simpleCtx.blocks.map(augmentBlock),
         log: logger,
    +    _chain: {
    +      client: rpcClient
    +    },
       }
  3. Add a MegaETH RPC URL to the .env file

    RPC_MEGAETH_HTTP=<your_megaeth_rpc_url>

Now you can use direct RPC calls in your batch handler

const contract = new erc20Abi.Contract(
  ctx,                  // For the RPC client
  ctx.blocks[0].header, // Header.height will be the heigh
                        // at which the contract state is queried
  WETH_CONTRACT_ADDRESS
)
const symbol = await contract.symbol() // 'WETH'

Releases

No releases published

Packages

 
 
 

Contributors