sim init
creates a new Sim IDX app with the folder structure shown above.
The following sections explain each folder’s purpose and contents in detail.
App Folder Structure
sim.toml
Thesim.toml
file is your app’s main configuration file. It contains your app’s name
and a [listeners]
table for configuring code generation.
name
field is used internally by Sim IDX for resource naming and deployment.
codegen_naming_convention
field in the [listeners]
table controls how function and type names are generated from your ABIs. This manages potential name conflicts when you index multiple contracts. It supports two values:
"plain"
(Default): Generates clean names without any prefixes (e.g.,onSwapFunction
). This is the most common setting, especially when you split logic for different ABIs into separate listener contracts."abi_prefix"
: Prefixes generated names with the ABI’s name (e.g.,ABI1$onSwapFunction
). Use this option to prevent compilation errors when a single listener contract must handle functions with the same name from two different ABIs.
sim.toml
file to stream your indexed data to external systems like Kafka. This is done using environment-specific sink configurations:
The [[env.<environment>.sinks]]
table allows you to define multiple sinks for different environments (e.g., dev
, prod
). Each sink configuration specifies how to connect to your external data system and which events should be sent to which topics. For detailed configuration options and setup instructions, see the Kafka Sinks documentation.
abis/
Theabis/
folder contains JSON ABI files of smart contracts you want to index. The sample app includes abis/UniswapV3Factory.json
for the Uniswap V3 Factory contract.
When you add a new ABI with the
sim abi add
CLI command, it automatically generates Solidity bindings in listeners/lib/sim-idx-generated/
.apis/
Theapis/
folder is a complete Node.js project that provides TypeScript API endpoints running on the Cloudflare Workers Edge runtime.
The src/index.ts
file defines your HTTP routes, while src/db/schema/Listener.ts
is produced by sim build
and exposes your listener-generated tables through Drizzle ORM for type-safe queries.
listeners/
Thelisteners/
folder is a Foundry project that contains everything related to on-chain indexing. The Triggers
contract must be defined in src/Main.sol
, but handler logic can be implemented in one or more listener contracts, which can have any name and be defined across multiple .sol
files in the src/
directory. Unit tests live under the test/
directory. Foundry will discover any file ending in .t.sol
, so you can add as many unit-test files as you need (e.g., Main.t.sol
, SwapHandlers.t.sol
, etc.).
During sim build
, the framework inserts core helpers into lib/sim-idx-sol/
and writes ABI-specific bindings into lib/sim-idx-generated/
. These generated files should not be edited directly.
Development Workflow
Here’s how these folders work together:- Add Contract ABI →
abis/YourContract.json
- Generate Bindings →
sim abi add
creates Solidity bindings - Extend Listener → Implement handlers in
listeners/src/
- Test Logic → Write tests in
listeners/test/
(e.g., any*.t.sol
files) - Build APIs → Use generated schema in
apis/src/
to query your data - Deploy → Push your changes to a branch (or
main
) and follow the steps in the deployment guide to promote them to a live environment