|
| 1 | +--- |
| 2 | +title: Create a token |
| 3 | +sidebar: |
| 4 | + order: 12 |
| 5 | +--- |
| 6 | + |
| 7 | +import { Aside } from '@astrojs/starlight/components' |
| 8 | + |
| 9 | +This tutorial describes the process of creating a basic fungible token on VSC. |
| 10 | + |
| 11 | +<Aside type="note" title="Prior Reading"> |
| 12 | +This guide assumes that you have read the smart contract development guide [here](/how-to/smart-contract-development). |
| 13 | +</Aside> |
| 14 | + |
| 15 | +## Setup |
| 16 | + |
| 17 | +Clone the Go contract template: |
| 18 | + |
| 19 | +```sh |
| 20 | +git clone https://github.com/vsc-eco/go-contract-template your-token |
| 21 | +cd your-token |
| 22 | +``` |
| 23 | + |
| 24 | +## Write Your Token Contract |
| 25 | + |
| 26 | +<Aside type="caution"> |
| 27 | +The specification for defining VSC token contracts are not final. |
| 28 | +</Aside> |
| 29 | + |
| 30 | +An example token contract has been included in [`examples/token/main.go`](https://github.com/vsc-eco/go-contract-template/blob/main/examples/token/main.go) file. You may copy this file into `contract/main.go` to use as a starting point. |
| 31 | + |
| 32 | +```sh |
| 33 | +cp examples/token/main.go contract |
| 34 | +``` |
| 35 | + |
| 36 | +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: |
| 37 | + |
| 38 | +```go title="main.go" |
| 39 | +const MaxSupply = 1000000 |
| 40 | +const Precision = 3 |
| 41 | +const Symbol = "TOKEN" |
| 42 | +const Creator = "hive:vaultec.vsc" |
| 43 | +``` |
| 44 | + |
| 45 | +<Aside type="note"> |
| 46 | +The `Creator` address will be the initial owner of your token contract. You will need to have access to this account to initialize your token and mint new tokens. |
| 47 | +</Aside> |
| 48 | + |
| 49 | +## Deploy Token |
| 50 | + |
| 51 | +Compile your token contract: |
| 52 | + |
| 53 | +```sh |
| 54 | +tinygo build -gc=custom -scheduler=none -panic=trap -no-debug -target=wasm-unknown -o build/main.wasm contract/main.go |
| 55 | +wasm-tools strip -o build/main-striped.wasm build/main.wasm |
| 56 | +``` |
| 57 | + |
| 58 | +Then deploy the contract: |
| 59 | + |
| 60 | +```sh |
| 61 | +# If not done already, init config and fill in deployer active key |
| 62 | +vsc-contract-deploy -init |
| 63 | + |
| 64 | +# Deploy token |
| 65 | +vsc-contract-deploy -wasmPath build/main-striped.wasm -name "your token name" |
| 66 | +``` |
| 67 | + |
| 68 | +## Initialize Token |
| 69 | + |
| 70 | +Call the `init` function from your token contract owner address as specified in the `Creator` constant. The contract call payload does not matter here. |
| 71 | + |
| 72 | +## Mint Tokens |
| 73 | + |
| 74 | +Call the `mint` function where payload is the amount to mint. The tokens minted will be sent to your address. |
| 75 | + |
| 76 | +## Burn Tokens |
| 77 | + |
| 78 | +Call the `burn` function where payload is the amount to burn. The tokens will be burnt from the caller address. |
| 79 | + |
| 80 | +## Transfer Tokens |
| 81 | + |
| 82 | +Call the `transfer` function where payload is a comma-separated string of destination address and amount. |
| 83 | + |
| 84 | +For example, to transfer 10 coins to `did:pkh:eip155:1:0xtoaddresshere`, the payload shall be `did:pkh:eip155:1:0xtoaddresshere,10`. |
0 commit comments