README
¶
Adder Library Examples
This directory contains example applications demonstrating how to use Adder as a library to build custom Cardano blockchain indexers.
Adder communicates with a Cardano Node using the ChainSync protocol to observe and process blockchain events in real-time.
Prerequisites
Cardano Node Access
To run these examples, you'll need access to a fully synced Cardano node. You have several options:
- Local Node: Run your own Cardano node and connect via Unix socket
- Remote Node: Connect to a remote node via TCP/IP
- Public Infrastructure: Use publicly available Cardano nodes (some examples are pre-configured with IOG nodes)
Environment Variables
The examples use the following environment variables for configuration:
CARDANO_NODE_SOCKET_PATH: Path to the Cardano node Unix socket (e.g.,/path/to/node.socket)CARDANO_NODE_MAGIC: Network magic number that identifies the Cardano network
Network Magic Values
| Network | Magic Number |
|---|---|
| Mainnet | 764824073 |
| Preview | 2 |
| Preprod | 1 |
Examples
1. adder-publisher
Difficulty: Beginner
The simplest Adder example. Connects to a Cardano node and logs all blockchain events.
What you'll learn:
- Basic Adder pipeline setup
- Connecting to a Cardano node
- Handling blockchain events
- ChainSync status monitoring
Use case: Understanding the Adder event model and testing your node connection.
cd adder-publisher
go run main.go
2. poolid-filter
Difficulty: Beginner
Demonstrates filtering events by stake pool ID to monitor specific pools.
What you'll learn:
- Adding filters to the pipeline
- Pool-specific event filtering
- Monitoring delegations and block production
Use case: Building pool monitoring tools, delegation trackers, or pool performance dashboards.
cd poolid-filter
go run main.go
3. event-address-filter
Difficulty: Intermediate
Shows how to combine multiple filters to monitor specific addresses and native assets.
What you'll learn:
- Using multiple filters in a pipeline
- Event type filtering
- Address-based filtering
- Asset fingerprint filtering
Use case: Wallet monitors, payment notifications, token analytics, NFT tracking.
cd event-address-filter
go run main.go
Running the Examples
Each example can be run independently. Navigate to the example directory and use Go to run it:
cd <example-directory>
go run main.go
Customizing Network Configuration
To use a different network or node:
export CARDANO_NODE_SOCKET_PATH=/path/to/your/node.socket
export CARDANO_NODE_MAGIC=764824073
cd adder-publisher
go run main.go
Building Binaries
To build an executable binary:
cd <example-directory>
go build -o my-indexer main.go
./my-indexer
Common Patterns
Pipeline Structure
All examples follow a similar pattern:
- Configuration: Parse environment variables
- Create Pipeline: Initialize a new Adder pipeline
- Configure Input: Set up ChainSync connection
- Add Filters (optional): Filter events by type, address, pool, etc.
- Configure Output: Define how to handle events
- Start Pipeline: Begin processing events
- Error Handling: Monitor for pipeline errors
Event Handlers
Each example includes a handleEvent function where you can implement custom logic:
func handleEvent(evt event.Event) error {
// Your custom logic here
// e.g., save to database, send notifications, etc.
return nil
}
Status Updates
Monitor sync progress with updateStatus:
func updateStatus(status input_chainsync.ChainSyncStatus) {
// Log or display sync status
}
Building Your Own Indexer
Start with the adder-publisher example and gradually add features:
- Start Simple: Get events flowing with the basic publisher
- Add Filters: Use filters to focus on relevant events
- Implement Logic: Add your custom event handling
- Add Storage: Integrate a database for persistence
- Add Outputs: Use multiple outputs (logging, webhooks, etc.)
Troubleshooting
Connection Issues
- Verify
CARDANO_NODE_SOCKET_PATHpoints to the correct socket - Ensure the Cardano node is running and fully synced
- Check that
CARDANO_NODE_MAGICmatches your network
Sync Performance
- Start with
WithIntersectTip(true)to sync from the current tip - For historical data, use
WithBulkMode(true)for faster processing - Consider using filters early to reduce event volume
Memory Usage
- Use specific filters to reduce event volume
- Implement batching in your event handler
- Consider using bulk mode for historical syncing
Additional Resources
Contributing
Found an issue or want to add a new example? Contributions are welcome!
- Fork the repository
- Create your feature branch
- Add or modify examples
- Update documentation
- Submit a pull request
License
These examples are licensed under the Apache License 2.0. See the LICENSE file for details.