Set up a new Sim IDX app using the contract-decoder template to decode all events and functions from any smart contract.
contract-decoder
template provides a shortcut to make this happen. Instead of manually defining each event you want to capture, it generates a special listener that automatically handles all events from a given contract ABI.
--template=contract-decoder
flag.
abis/UniswapV3Factory.json
. Since we’re replacing it, the first step is to delete this file.
sim abi codegen
. This command re-scans the abis/
directory and regenerates the bindings, effectively removing the ones for the now-deleted Uniswap ABI.
abis/Moonbirds.json
and paste the ABI into it.sim abi add
to register it with your project and generate the necessary Solidity bindings.
Moonbirds.sol
file in listeners/lib/sim-idx-generated/
. This file contains all the interfaces and helper contracts needed to interact with the Moonbirds contract in your listener.
listeners/src/Main.sol
. This is the core file where you define your indexing logic. We need to make two small changes to trigger on the generated Moonbirds bindings.
The Moonbirds.sol
file generated in the previous step includes a special abstract contract called Moonbirds$EmitAllEvents
. By inheriting from this contract, your listener automatically gains the ability to:
allTriggers()
, to register all event listeners at once.snake_case
for your PostgreSQL table names. For example, an on-chain event named RoleGranted
will have its data stored in a table named role_granted
.
Update listeners/src/Main.sol
with the following code:
Listener
contract inherits the decoding logic, and the Triggers
contract points to the on-chain Moonbirds address, registering all its events for indexing.
sim listeners evaluate
. This command runs a local dry-run to confirm your triggers fire correctly and decode events as expected.
Find a block number on Etherscan where a Moonbirds transaction occurred and use it for the --start-block
flag.
events
array and an empty errors
array.
sim init
, a sample API was created in apis/src/index.ts
. This API is configured to query data from the original Uniswap contract and will fail now that we’ve replaced the ABI. We need to update it to query one of the new tables created for the Moonbirds events.
When you run sim build
, Drizzle schemas for all your new event tables are automatically generated and placed in apis/src/db/schema/Listener.ts
. You can inspect this file to see which tables are available to query.
Let’s update apis/src/index.ts
to fetch the 10 most recent records from the approval_for_all
table, which corresponds to the ApprovalForAll
event.
sim build
to compile your contracts and API code.
contract-decoder
template does not include listener tests that need to be updated, simplifying the development workflow.