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 { sdk.Log(*a) sdk.Log("Entrypoint logged") 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 { // ... sdk.StateSetObject("myString", *a) // ...}GetObject
Section titled “GetObject”Retrieve the value of a key from the contract database.
//go:wasmexport getStringfunc GetString(a *string) *string { // ... value := sdk.StateGetObject("myString") // ...}DelObject
Section titled “DelObject”Delete the value of a key in the contract database.
//go:wasmexport clearStringfunc ClearString(a *string) *string { // ... sdk.StateDeleteObject("myString") // ...}GetEnv
Section titled “GetEnv”Retrieve the current runtime environment variables. List of variable names are listed below.
//go:wasmexport dumpEnvfunc DumpEnv(a *string) *string { // ... envs := sdk.GetEnv() // ...}GetEnvKey
Section titled “GetEnvKey”Retrieve an environment variable by key. List of variable names are listed below.
//go:wasmexport dumpEnvKeyfunc DumpEnvKey(a *string) *string { // ... contract_id := sdk.GetEnvKey("contract.id") // ...}GetBalance
Section titled “GetBalance”Retrieve the balance of any VSC account or contract.
//go:wasmexport getBalancefunc GetBalance(a *string) *string { // ... bal := sdk.GetBalance("hive:vaultec.vsc", sdk.AssetHive) // result 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 { // ... sdk.HiveDraw(1000, sdk.AssetHive) // Draw 1 HIVE from caller // ...}Transfer
Section titled “Transfer”Transfer assets from the contract to another account.
//go:wasmexport transferBalancefunc TransferBalance(a *string) *string { // ... sdk.HiveTransfer("hive:vaultec.vsc", 1000, sdk.AssetHive) // Transfer 1 HIVE from contract // ...}Withdraw
Section titled “Withdraw”Unmap assets from the contract to a specified Hive account.
//go:wasmexport unmapBalancefunc UnmapBalance(a *string) *string { // ... sdk.HiveWithdraw("hive:vaultec.vsc", 1000, sdk.AssetHive) // Withdraw 1 HIVE from contract // ...}Abort contract execution and revert transaction.
//go:wasmexport abortMefunc AbortMe(a *string) *string { // ... sdk.Abort("something went wrong") // ...}Env Vars
Section titled “Env Vars”contract.id: ID of the current contracttx.id: ID of the transactiontx.index: Transaction position in blocktx.op_index: Operation position in transactionblock.id: 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.block.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.block.timestamp: Timestamp of when the transaction was included in (i.e.2025-07-26T14:10:42).msg.sender: Address of the transaction sender. This must be a user address. 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.caller: The address that is calling the contract. It can be a contract ID or user address.