Integrate using Go
The recommended way to integrate a service with Go is to use the official Cosmos SDK.
go get github.com/cosmos/cosmos-sdk
To get started, you should install the cosmwasm-schema
module.
It contains Go types generated from the CosmWasm contract schemas.
These types allow you to interact with SatLayer contracts in a type-safe manner.
go get github.com/satlayer/satlayer-bvs/modules/cosmwasm-schema
We also provide a cosmwasm-api
module that contains the client context and helper Query
and Execute
functions.
This module is a thin wrapper around the Cosmos SDK and provides a convenient way to interact with CosmWasm contracts.
You don’t need to use this module if you prefer to use the Cosmos SDK directly.
go get github.com/satlayer/satlayer-bvs/modules/cosmwasm-api
Interacting with contracts
For convenience, we provide a NewClientCtx
function that sets up a client context
with a given RPC endpoint and chain ID.
import (
cosmwasmapi "github.com/satlayer/satlayer-bvs/cosmwasm-api"
);
RpcEndpoint := "https://babylon-rpc.polkachu.com"
ChainID := "bbn-1"
clientCtx := cosmwasmapi.NewClientCtx(RpcEndpoint, ChainID)
To perform a query, you can use the Query
function provided by the cosmwasm-api
package.
import (
cosmwasmapi "github.com/satlayer/satlayer-bvs/cosmwasm-api";
"github.com/satlayer/satlayer-bvs/cosmwasm-schema/registry"
)
func PerformQuery() {
queryMsg := registry.QueryMsg{
Status: ®istry.Status{
Operator: "bbnoperator",
Service: "bbnservice",
},
}
clientCtx := cosmwasmapi.NewClientCtx("https://babylon-rpc.polkachu.com", "bbn-1")
response, err := cosmwasmapi.Query[registry.StatusResponse](
clientCtx,
context.Background(),
"bbn...",
queryMsg,
)
}
To perform a execute transaction, you can use the Execute
function provided by the cosmwasm-api
package.
import (
cosmwasmapi "github.com/satlayer/satlayer-bvs/cosmwasm-api";
"github.com/satlayer/satlayer-bvs/cosmwasm-schema/registry"
)
func PerformExecute() {
clientCtx := cosmwasmapi.NewClientCtx("https://babylon-rpc.polkachu.com", "bbn-1").
WithKeyring(clientKeyring).
WithFromAddress(executorAddr).
WithFromName("executor")
executeMsg := registry.ExecuteMsg{
RegisterOperatorToService: ®istry.RegisterOperatorToService{
Operator: "bbnoperator",
},
}
executeOptions := cosmwasmapi.DefaultBroadcastOptions().
WithContractAddr(s.pauser.Address).
WithExecuteMsg(executeMsg).
WithGasPrice("0.002ubbn")
response, err := cosmwasmapi.Execute(
clientCtx,
context.Background(),
owner.String(),
executeOptions,
)
}
For more detailed information on the full lifecycle of a BVS: