Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions src/content/docs/How To/How to build smart contracts outline.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/content/docs/How To/How to use vsc api outline.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: How to use the VSC API (OUTLINE)
sidebar:
order: 12
order: 20
---


Expand Down
84 changes: 84 additions & 0 deletions src/content/docs/How To/create a token.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
title: Create a token
sidebar:
order: 12
---

import { Aside } from '@astrojs/starlight/components'

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

<Aside type="note" title="Prior Reading">
This guide assumes that you have read the smart contract development guide [here](/how-to/smart-contract-development).
</Aside>

## Setup

Clone the Go contract template:

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

## Write Your Token Contract

<Aside type="caution">
The specification for defining VSC token contracts are not final.
</Aside>

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.

```sh
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:

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

<Aside type="note">
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.
</Aside>

## Deploy Token

Compile your token contract:

```sh
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:

```sh
# 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"
```

## 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

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

## Burn Tokens

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

## 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`.
Loading
Loading