Skip to main content
Version: Current

Examples

Browse a dedicated repository with EVM squid examples. It contains:

and a few others.

Processor configs showcase

The snippets below show how to configure EvmBatchProcessor and use Squid SDK to build a custom indexer for various use-cases. Each snippet comes with a link to a repository with full sources, and can be used as a template.

Bulk-index Binance Chain transactions for a large number of wallets

Full squid here.

src/processor.ts
export const processor = new EvmBatchProcessor()
.setGateway('https://v2.archive.subsquid.io/network/binance-mainnet')
.addTransaction({})
src/main.ts
const wallets: Set<string> = loadWallets()
// wallets.size can be very large (tested at 1.4M)

processor.run(new TypeormDatabase(), async (ctx) => {
for (let block of ctx.blocks) {
for (let txn of block.transactions) {
if (wallets.has(txn.from)) {
// process a txn initiated by the wallet
}
if (txn.to && wallets.has(txn.to)) {
// process a txn directed to the wallet
}
}
}
})
Index all USDC Transfer events on Ethereum with real time updates

Real time data is fetched from a chain node RPC; a Database object with hot blocks support is required to store it (see this page for more details). Full squid here.

export const USDC_CONTRACT_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'

export const processor = new EvmBatchProcessor()
.setGateway('https://v2.archive.subsquid.io/network/ethereum-mainnet')
.setRpcEndpoint('<eth_rpc_endpoint_url>')
.setFinalityConfirmation(75)
.addLog({
range: {from: 6_082_465},
address: [USDC_CONTRACT_ADDRESS],
topic0: [usdcAbi.events.Transfer.topic],
})
.setFields({
log: {
transactionHash: true,
},
})
Index all Transfers to vitalik.eth

All Transfer(address,address,uint256) will be captured, including ERC20 and ERC721 transfers and possibly events with the same signature made with other protocols. Full squid here.

export const VITALIK_ETH_TOPIC = '0x000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa96045'

export const processor = new EvmBatchProcessor()
.setGateway('https://v2.archive.subsquid.io/network/ethereum-mainnet')
.addLog({
topic0: [erc20abi.events.Transfer.topic],
topic2: [VITALIK_ETH_TOPIC],
})
Get all calls to AAVE lending pool and all events they caused

Including events emitted by other contracts. Get ETH value involved in each call.

Full squid here.

export const AAVE_CONTRACT = '0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9'

export const processor = new EvmBatchProcessor()
.setGateway('https://v2.archive.subsquid.io/network/ethereum-mainnet')
.setBlockRange({ from: 11_362_579 })
.addTransaction({
to: [AAVE_CONTRACT],
logs: true,
})
.setFields({
transaction: {
value: true,
sighash: true,
},
log: {
transactionHash: true,
},
})
Index all Mint(address,address,uint256) event logs on Ethereum, extract the gas fees

Full squid here.

export const processor = new EvmBatchProcessor()
.setGateway('https://v2.archive.subsquid.io/network/ethereum-mainnet')
.addLog({
topic0: [usdcAbi.events.Mint.topic],
transaction: true,
})
.setFields({
transaction: {
gasUsed: true,
}
})
Index all Pancakeswap trading pairs and Swap logs

Full squid here.

export const FACTORY_ADDRESSES = [
'0xbcfccbde45ce874adcb698cc183debcf17952812',
'0xca143ce32fe78f1f7019d7d551a6402fc5350c73',
]

const PAIR_CREATED_TOPIC = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9'
const SWAP_TOPIC = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822'

export const processor = new EvmBatchProcessor()
.setGateway('https://v2.archive.subsquid.io/network/binance-mainnet')
.setBlockRange({ from: 586_851 })
.addLog({
address: FACTORY_ADDRESSES,
topic0: [PAIR_CREATED_TOPIC],
})
.addLog({
topic0: [SWAP_TOPIC],
})
.setFields({
log: {
transactionHash: true,
},
})
Index all call traces and historical state changes of the BAYC NFT contract

Call traces will expose any internal calls to BAYC by other contracts. Full squid here.

const BAYC_ADDRESS = '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d'

export const processor = new EvmBatchProcessor()
.setGateway('https://v2.archive.subsquid.io/network/ethereum-mainnet')
.setBlockRange({ from: 12_287_507 })
.addTrace({
type: ['call'],
callTo: [BAYC_ADDRESS],
transaction: true,
})
.addStateDiff({
address: [BAYC_ADDRESS],
transaction: true,
})
.setFields({
trace: {
callTo: true,
callFrom: true,
callSighash: true,
},
})
Scrape all NFT contract deployments on Ethereum, index Transfers

All contract creations are scraped; they will be checked for ERC721 compliance in the batch handler. All ERC721 Transfer events are scraped so that they can be filtered and binned by the contract in the batch handler. Full squid here.

export const processor = new EvmBatchProcessor()
.setGateway('https://v2.archive.subsquid.io/network/ethereum-mainnet')
.addTrace({
type: ['create'],
transaction: true,
})
.addLog({
topic0: [erc721.events.Transfer.topic],
})
.setFields({
trace: {
createResultCode: true, // for checking ERC721 compliance
createResultAddress: true,
},
})