Skip to content

Create a token

This tutorial describes the process of creating a basic fungible token on VSC.

Clone the Go contract template:

Terminal window
git clone https://github.com/vsc-eco/go-contract-template your-token
cd your-token

An example token contract has been included in examples/token/main.go file. You may copy this file into contract/main.go to use as a starting point.

Terminal window
cp examples/token/main.go contract

The token contract features mint/burn with supply cap, transfer and change ownership functions. Update the following constants at the top of the file to your desired values:

main.go
const MaxSupply = 1000000
const Precision = 3
const Symbol = "TOKEN"
const Creator = "hive:vaultec.vsc"

Compile your token contract:

Terminal window
tinygo build -gc=custom -scheduler=none -panic=trap -no-debug -target=wasm-unknown -o build/main.wasm contract/main.go
wasm-tools strip -o build/main-striped.wasm build/main.wasm

Then deploy the contract:

Terminal window
# If not done already, init config and fill in deployer active key
vsc-contract-deploy -init
# Deploy token
vsc-contract-deploy -wasmPath build/main-striped.wasm -name "your token name"

Call the init function from your token contract owner address as specified in the Creator constant. The contract call payload does not matter here.

Call the mint function where payload is the amount to mint. The tokens minted will be sent to your address.

Call the burn function where payload is the amount to burn. The tokens will be burnt from the caller address.

Call the transfer function where payload is a comma-separated string of destination address and amount.

For example, to transfer 10 coins to did:pkh:eip155:1:0xtoaddresshere, the payload shall be did:pkh:eip155:1:0xtoaddresshere,10.