SDK
The VSC SDK is a library that abstract away various functionalities that are useful in the context of writing a VSC smart contract.
Go Contract SDK
Section titled “Go Contract SDK”The Go contract SDK implements the necessary runtime and SDK functions for the VSC smart contract environment.
Example Usage
Section titled “Example Usage”package main
import ( "contract-template/sdk")
//go:wasmexport entrypointfunc Entrypoint(a *string) *string { msg := "Entrypoint logged" sdk.Log(a) sdk.Log(&msg) return a}SDK Methods
Section titled “SDK Methods”The below methods are within the sdk namespace. All parameters and return types are *string.
Log a string to the node console for debugging purposes.
//go:wasmexport entrypointfunc Entrypoint(a *string) *string { // ... sdk.Log(a) // ...}SetObject
Section titled “SetObject”Set the value of a key in the contract database.
//go:wasmexport setStringfunc SetString(a *string) *string { // ... key := "myString" sdk.SetObject(&key, a) // ...}GetObject
Section titled “GetObject”Retrieve the value of a key from the contract database.
//go:wasmexport getStringfunc GetString(a *string) *string { // ... key := "myString" value := sdk.GetObject(&key) // ...}DelObject
Section titled “DelObject”Delete the value of a key in the contract database.
//go:wasmexport clearStringfunc ClearString(a *string) *string { // ... key := "myString" sdk.DelObject(&key) // ...}Make a system call.
//go:wasmexport systemCallfunc SystemCall(a *string) *string { // ... method := "Method name here" payload := "Payload here" ret := sdk.Call(&method, &payload) // ...}GetEnv
Section titled “GetEnv”Retrieve the current runtime environment variables. List of variable names are listed below.
//go:wasmexport dumpEnvfunc DumpEnv(a *string) *string { // ... varContractId := "contract_id" contract_id := sdk.GetEnv(&varContractId) // ...}Sha256
Section titled “Sha256”Calculate the SHA256 hash of a hex-encoded string.
//go:wasmexport sha256func Sha256(a *string) *string { // ... input := "abcd" sha256hash := sdk.Sha256(&input) // ...}Ripemd160
Section titled “Ripemd160”Calculate the RIPEMD160 hash of a hex-encoded string.
//go:wasmexport ripemd160func Ripemd160(a *string) *string { // ... input := "abcd" ripemd160hash := sdk.Ripemd160(&input) // ...}GetBalance
Section titled “GetBalance”Retrieve the balance of any VSC account or contract.
//go:wasmexport getBalancefunc GetBalance(a *string) *string { // ... acc := "hive:vaultec.vsc" asset := "hive" // valid assets: hive, hive_consensus, hbd, hbd_savings bal := sdk.GetBalance(&acc, &asset) // in terms of mHIVE/mHBD // ...}Transfer assets from caller account to the contract up to the limit specified in intents. The transaction must be signed using active authority for Hive accounts.
//go:wasmexport drawBalancefunc DrawBalance(a *string) *string { // ... amt := "1000" // in terms of mHIVE/mHBD asset := "hive" // valid assets: hive, hbd, hbd_savings sdk.Draw(&amt, &asset) // ...}Transfer
Section titled “Transfer”Transfer assets from the contract to another account.
//go:wasmexport transferBalancefunc TransferBalance(a *string) *string { // ... toacc := "hive:vaultec.vsc" amt := "1000" // in terms of mHIVE/mHBD asset := "hive" // valid assets: hive, hbd, hbd_savings sdk.Transfer(&toacc, &amt, &asset) // ...}Withdraw
Section titled “Withdraw”Unmap assets from the contract to a specified Hive account.
//go:wasmexport unmapBalancefunc UnmapBalance(a *string) *string { // ... toacc := "hive:vaultec.vsc" amt := "1000" // in terms of mHIVE/mHBD asset := "hive" // valid assets: hive, hbd, hbd_savings sdk.Withdraw(&toacc, &amt, &asset) // ...}Environment Methods
Section titled “Environment Methods”The below methods are within the env namespace.
Abort contract execution and revert transaction.
import "contract-template/env"
//go:wasmexport abortMefunc AbortMe(a *string) *string { // ... err := "some error here" fname := "abort.go" env.Abort(&err, &fname, 1, 1) // ...}Env Vars
Section titled “Env Vars”contract_id: ID of the current contractmsg.sender: Address of the transaction sender. If there are multiple, the first account specified inrequired_authsorrequired_posting_authsis returned.msg.required_auths: Therequired_authsfield of the transaction.msg.required_posting_auths: Therequired_posting_authsfield of the transaction.anchor.id: ID of the transactionanchor.block: L1 block ID in which the transaction is included in. For offchain transactions, this refers to the L1 block ID of the VSC block in which the transaction was included in.anchor.height: L1 block number in which the transaction is included in. For offchain transactions, this refers to the L1 block number of the VSC block in which the transaction was included in.anchor.timestamp: Timestamp of when the transaction was included in (i.e.2025-07-26T14:10:42).anchor.tx_index: Transaction position in blockanchor.op_index: Operation position in transaction