This example demonstrates how to invoke an arbitrary stored procedure on the TRUF.NETWORK database from the Go SDK using the CallProcedure helper.
- How to initialise a
tnclient.Client - How to load the generic
ActionAPI - How to call a read-only stored procedure that expects custom arguments
- How to inspect the raw
QueryResultthat is returned
For demonstration purposes we call the procedure get_divergence_index_change, which accepts the following positional arguments:
| Position | Name | Type | Description |
|---|---|---|---|
| 1 | from |
INT | Unix timestamp (inclusive) marking the start |
| 2 | to |
INT | Unix timestamp (inclusive) marking the end |
| 3 | frozen_at |
INT? | Optional freeze timestamp |
| 4 | base_time |
INT? | Optional base time for normalisation |
| 5 | time_interval |
INT | Comparison interval in seconds |
Feel free to replace the procedure name and arguments with your own.
- Go 1.20+ installed
- A running TN gateway (local or
https://gateway.mainnet.truf.network) - A funded Ethereum-style private key to sign transactions
-
Replace
"your-private-key"inmain.gowith your actual private key (never commit real keys!). -
Optionally switch the
endpointvalue to your local node (http://localhost:8484). -
In this directory run:
go mod tidy go run . -
You should see something similar to:
Columns: [event_time value] [1717503323 1.2345] [1717589723 1.5678] ...