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.
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.jsthen in a separate terminal navigate to the squid-megaeth-example folder and run
npx squid-graphql-serverA GraphiQL playground will be available at localhost:4350/graphql.
The example is mostly compatible with the current docs. Highlights:
- Overview (markdown)
- Development guide (markdown) - indexer development walkthrough
- Indexer from scratch (markdown) - read this to gain deeper understanding of the Squid SDK
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.
-
Install the native RPC client
npm install @subsquid/rpc-client @subsquid/util-internal
-
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 + }, } -
Add a MegaETH RPC URL to the
.envfileRPC_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'