Handle Name Conflicts
When working with multiple ABIs, you may encounter functions or events with the same name, which can cause compilation errors. Sim IDX provides two solutions.1. Multiple Listeners
The recommended approach is to split your logic into separate, dedicated listener contracts for each ABI. This keeps your code clean and modular.2. Prefixed Naming for Shared State
If you need to share state between handlers for conflicting functions within a single contract, you can configuresim.toml
to prefix the generated names.
sim.toml
Example Listener with Shared State
To learn more about the
codegen_naming_convention
property and other sim.toml
configuration options, visit the App Structure page.Stack Too Deep Errors
You may encounter aStack too deep
compilation error if your event contains more than 16 parameters, or if your handler function declares too many local variables. This is due to a fundamental limit in the Solidity EVM.
The solution is to use a pattern called Struct Flattening. You group your event parameters into a struct
and then define your event to take this struct as a single, unnamed parameter. Sim IDX recognizes this specific pattern and will automatically “flatten” the struct’s members into individual columns in your database. This gives you the best of both worlds: code that compiles and a clean, relational database schema.
Implement struct flattening in your listener contract code (in
listeners/src/
), not in the generated files. Files in listeners/lib/sim-idx-generated/
are auto-generated and should never be modified directly, as they will be overwritten when you run sim build
.1
Define a Struct
Create a struct containing all the fields you want in your database table.
This struct can be defined in any Solidity file within
listeners/src/
, but it must be properly imported in any file where you plan to use it for events or handler functions.2
Update Event Definition
Change your event to accept the struct as a single, unnamed parameter. This is the crucial step that enables struct flattening.
3
Populate and Emit the Struct
In your handler, create an instance of the struct, populate its fields, and emit it.