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 gorutines, channels and thus the context
package. We recommend using context.Background
as it fits most usage scenarios.
ChainIO
To use ChainIO against the SatLayer testnet, initialize a CosmWasm client pointing at our network with your keys.
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.
Not all nodes are so called "archiver" nodes, which stores and indexes all past transactions. By default, nodes will forget transactions beyond a predefined time in order to save disk space.
Within the official SatLayer testnet nodes, only rpc.satlayer.net
is an archiver. Expect querying of old transactions to fail against a non archiver.
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