ChainIO Module
The BVS SDK consists of several components, with ChainIO being the primary one—and likely the only one you’ll interact with. ChainIO acts as an abstraction layer over the base CosmWasm API used for communicating with a CosmWasm node. It simplifies tasks like data querying, contract execution, and event indexing/sequencing. ChainIO is the main interface for interacting with a BVS contract.
Creating a context
The BVS SDK makes heavy use of Golang's goroutines, channels and thus the context package. We recommend using context.Background as it fits most usage scenarios.
import "context"
ctx := context.Background()ChainIO
To use ChainIO against the SatLayer testnet, initialize a CosmWasm client pointing at our network with your keys.
import "github.com/satlayer/satlayer-api/signer"
client, err := signer.NewCosmosClient(
"sat-bbn-testnet1", // Chain-id. For SatLayer testnet it's sat-bbn-testnet1
"https://rpc.satlayer.net", // URL to an RPC node
".", // Directory that stores the key. Only used if the keyring needs it
"your-key-name-here", // name of the key
"test", // Keyring backend. Valid values includes test, os, kwallet or file
"bbn" // Address prefix of the network
)Querying contract state
The QueryContract method allows you to query contract states (equivalent to the command babylond query wasm contract-state smart <contract-address> <query-data> .
In which the QueryOptions struct is defined as follows.
Executing contract
The ExecuteContract method runs a contract. It works exactly like QueryContract but with options to configure gas, fees and more. It is equivalent to the babylond tx wasm execute command
The ExecuteOptions is defined as follow:
Alternative to ExecuteContract, the SendTranscation function does the same thing but it provides automatic retry and observation. Depending on the use case, the SendTransaction function could be a better option.
Querying node status
The QueryNodeStatus method helps you check if a node is online and healthy.
Query a historical transaction
The QueryTransaction method queries a past transaction and returns the transaction result.
Listening for events
A key function of ChainIO is listening for events generated by a given contract, which is essential for tracking task generations and submissions within a BVS. Setting up an event listener is a bit more complicated but remains straightforward. Let’s assume the cosmosClient from previous examples is still accessible.
Contract API wrappers
ChainIO also provides abstractions of SatLayer core contacts by allowing programmatic execution and query of the core contracts. These are simple, strongly-typed wrappers for ease of use.
Wrappers are available for:
BVS Directory
Delegation Manager
Rewards Coordinator
Slash Manager
State Bank
Strategy Base/TVL Limits/Factory/Manager
To access them, run:
Please refer to the SatLayer Core Contracts section for what each contract does.
Logger
The BVS SDK includes a generic logger that is integrated into components of the SDK.
The following snippet shows how the logger can be used.
Last updated
Was this helpful?