Create a token
This tutorial describes the process of creating a basic fungible token on VSC.
Clone the Go contract template:
git clone https://github.com/vsc-eco/go-contract-template your-tokencd your-token
Write Your Token Contract
Section titled “Write Your Token Contract”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.
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:
const MaxSupply = 1000000const Precision = 3const Symbol = "TOKEN"const Creator = "hive:vaultec.vsc"
Deploy Token
Section titled “Deploy Token”Compile your token contract:
tinygo build -gc=custom -scheduler=none -panic=trap -no-debug -target=wasm-unknown -o build/main.wasm contract/main.gowasm-tools strip -o build/main-striped.wasm build/main.wasm
Then deploy the contract:
# If not done already, init config and fill in deployer active keyvsc-contract-deploy -init
# Deploy tokenvsc-contract-deploy -wasmPath build/main-striped.wasm -name "your token name"
Initialize Token
Section titled “Initialize Token”Call the init
function from your token contract owner address as specified in the Creator
constant. The contract call payload does not matter here.
Mint Tokens
Section titled “Mint Tokens”Call the mint
function where payload is the amount to mint. The tokens minted will be sent to your address.
Burn Tokens
Section titled “Burn Tokens”Call the burn
function where payload is the amount to burn. The tokens will be burnt from the caller address.
Transfer Tokens
Section titled “Transfer Tokens”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
.