vikiival / mimick

Indexer for ink! based NFTs
GNU General Public License v3.0
1 stars 3 forks source link

Get Initial data for Contract #5

Open vikiival opened 1 year ago

vikiival commented 1 year ago

Example

import {SubstrateBatchProcessor} from "@subsquid/substrate-processor"
import {TypeormDatabase} from "@subsquid/typeorm-store"
import * as erc20 from "./erc20"

const CONTRACT_ADDRESS = '0x5207202c27b646ceeb294ce516d4334edafbd771f869215cb070ba51dd7e2c72'

const processor = new SubstrateBatchProcessor()
    .setDataSource({
        archive: "https://shibuya.archive.subsquid.io/graphql"
    })
    .addEvent(
        'Contracts.Instantiated',
        {
            range: {from: 1000000, to: 1000000}, // block number where your contract was deployed
            data: {call: {args: true}},
        }
    )

processor.run(new TypeormDatabase(), async ctx => {
    for (let block of ctx.blocks) {
        for (let item of block.items) {
            if (item.kind == 'event' && item.name == 'Contracts.Instantiated' && item.event.args.contract == CONTRACT_ADDRESS) {
                erc20.decodeConstructor(item.event.call.args.data)
            }
        }
    }
})
vikiival commented 1 year ago

Idea: Just save item.event.call.args.data as jsonb when someone will register the contract we will use that