Go Library Examples
Este contenido aún no está disponible en español.
Download the complete Go examples bundle or browse the
source files.
The bundle pins Adder commit e6f733d318eb and includes its Apache-2.0 license.
It builds independently of an Adder checkout.
Install Go 1.26.8 or newer, then extract the bundle:
tar -xzf adder-library-examples.tar.gzcd adder-library-examplesgo mod downloadexport CARDANO_NODE_SOCKET_PATH=/path/to/node.socketgo run ./adder-publisherThe three programs require a synchronized mainnet Cardano node with a local
Unix socket. They default to /ipc/node.socket and mainnet magic 764824073.
For preview, set CARDANO_NODE_MAGIC=2 and point CARDANO_NODE_SOCKET_PATH at
a preview node. For preprod, use magic 1 and a preprod node. ChainSync infers
its status epoch history from these known magic values.
For a custom network, add input_chainsync.WithEraHistory to inputOpts in
main.go. Supply an input_chainsync.EraHistory whose ByronEpochLength,
ShelleyStartSlot, ShelleyStartEpoch, and ShelleyEpochLength match that
network’s genesis and era boundaries. The programs parse only the two
CARDANO_NODE_* variables; configure custom era history in source.
For TCP access, replace WithSocketPath with WithAddress in source.
Node-to-Node ChainSync uses bulk synchronization; connect only to nodes you control.
Examples
Section titled “Examples”- Event publisher: receive and log ChainSync events.
- Stake pool filter: watch either of two pool IDs.
- Address and asset filter: combine transaction, address, and asset filters.
- Managed plugins: implement cancellation, restart, failure, and event ownership.
All three programs start at the current tip and enable automatic reconnection.
They handle SIGINT/SIGTERM, observe terminal Failed() separately from
recoverable ErrorChan() diagnostics, and call Stop() before returning after
a successful start. Startup errors return without a Stop() call because
StartContext cleans up a failed start.
The callback logs received event with an event type, and status changes log
chainsync status update.
Validate the source
Section titled “Validate the source”From the extracted bundle root:
go test -race ./...go vet ./...go build ./...Tests use a fake local socket and in-memory plugins; they do not need a live Cardano node. Run the programs separately to observe real ChainSync events.