API Reference

This page is used to describe all the additional API which exists as part of the Contract SDK


To use the Env package, you need to import it

import (

It provides the following functions


Used to get the block height which will be the one this transaction be a part of

GetBlockHeight() uint64

It will return the block height in decimal values


Used to get the block timestamp (creation time) which will be the one this transaction be a part of

GetBlockTimestamp() uint64

It will return the block timestamp representing the Unix epoch in nanoseconds


Used to get the virtual chain id this contract is executing under

GetVirtualChainId() uint32

It will return the virtual chain id in decimal values


To use the Safemath package, you need to import it

import (

It gives the ability to work with 32, 64 and 256 bit unsigned integers, in a 'safe' way meaning there is overflow/underflow and illegal operation protection around the arithmetic operation done.

The API is uniform between the different variants and consist of the following functions


Adds two numbers and returns the result, the numbers are validated so that they do not overflow after the addition.

Add(x *big.Int, y *big.Int) *big.Int
Add(x uint32, y uint32) uint32
Add(x uint64, y uint64) uint64


Subtract y from x. The result is validated so if it becomes negative, an error is returned.

Sub(x *big.Int, y *big.Int) *big.Int
Sub(x uint32, y uint32) uint32
Sub(x uint64, y uint64) uint64


Multiplies the values and returns the new number, the result is validated so that it does not overflow.

Mul(x *big.Int, y *big.Int) *big.Int
Mul(x uint32, y uint32) uint32
Mul(x uint64, y uint64) uint64


Performs the integer division of x and y. The remainder is discarded as it should in integer arithmetic and the input (y) is validated to not be zero.

Div(x *big.Int, y *big.Int) *big.Int
Div(x uint32, y uint32) uint32
Div(x uint64, y uint64) uint64


Performs the modulo operation between x and y. The input is validated to be valid (meaning y is not zero to avoid invalid division) - the resulting number will hold the reminder as expected

Mod(x *big.Int, y *big.Int) *big.Int
Mod(x uint32, y uint32) uint32
Mod(x uint64, y uint64) uint64


Only relevant for safeuint256

The function validates that the number is not negative and did not overflow. If validation fails, the code will panic with the appropriate message

Validate(n *big.Int)

It is called automatically on each operation, meaning after using Add or Sub or any operation of the safemath library, there is no need to manually validate.