Skip to content

Commit 7f5f822

Browse files
techcoderxmiloridenour
authored andcommitted
devnet setup guide
1 parent 9338053 commit 7f5f822

3 files changed

Lines changed: 132 additions & 60 deletions

File tree

src/content/docs/How To/How to use vsc api outline.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/content/docs/How To/create a token.mdx

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,79 +6,70 @@ sidebar:
66

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

9-
This tutorial describes the process of creating a basic fungible token on VSC.
9+
This tutorial describes the process of creating a basic fungible token on Magi.
1010

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

1515
## Setup
1616

17-
Clone the Go contract template:
17+
Clone the Magi token contract template:
1818

1919
```sh
20-
git clone https://github.com/vsc-eco/go-contract-template your-token
20+
git clone https://github.com/vsc-eco/magi_token_contract your-token
2121
cd your-token
2222
```
2323

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-
4924
## Deploy Token
5025

5126
Compile your token contract:
5227

5328
```sh
54-
tinygo build -gc=custom -scheduler=none -panic=trap -no-debug -target=wasm-unknown -o build/main.wasm contract/main.go
29+
tinygo build -gc=custom -scheduler=none -panic=trap -no-debug -target=wasm-unknown -o build/main.wasm ./contract
5530
wasm-tools strip -o build/main-striped.wasm build/main.wasm
5631
```
5732

5833
Then deploy the contract:
5934

6035
```sh
6136
# If not done already, init config and fill in deployer active key
62-
vsc-contract-deploy -init
37+
contract-deployer -init
6338

6439
# Deploy token
65-
vsc-contract-deploy -wasmPath build/main-striped.wasm -name "your token name"
40+
contract-deployer -wasmPath build/main-striped.wasm -name "your token name"
6641
```
6742

6843
## Initialize Token
6944

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.
45+
Call the `init` function from your token contract owner address (contract deployer if not specified) with the following payload:
46+
47+
```json
48+
{"name":"Token Name","symbol":"TKN","decimals":3,"maxSupply":1000000000}
49+
```
7150

7251
## Mint Tokens
7352

74-
Call the `mint` function where payload is the amount to mint. The tokens minted will be sent to your address.
53+
Call the `mint` function from the token owner address with the below payload. The tokens minted will be sent to your address.
54+
55+
```json
56+
{"amount":1000}
57+
```
7558

7659
## Burn Tokens
7760

78-
Call the `burn` function where payload is the amount to burn. The tokens will be burnt from the caller address.
61+
Call the `burn` function with the below payload. The tokens will be burnt from the caller address.
62+
63+
```json
64+
{"amount":500}
65+
```
7966

8067
## Transfer Tokens
8168

82-
Call the `transfer` function where payload is a comma-separated string of destination address and amount.
69+
Call the `transfer` function with the below payload specifying the destination address and amount.
70+
71+
```json
72+
{"to":"hive:recipient","amount":100}
73+
```
8374

84-
For example, to transfer 10 coins to `did:pkh:eip155:1:0xtoaddresshere`, the payload shall be `did:pkh:eip155:1:0xtoaddresshere,10`.
75+
For more details on Magi token standards, please refer to the [README](https://github.com/vsc-eco/magi_token-contract/blob/main/readme.md).
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
title: Setup a development testnet
3+
sidebar:
4+
order: 20
5+
---
6+
7+
import { Aside, FileTree } from '@astrojs/starlight/components'
8+
9+
This is a guide on setting up a local development testnet (aka devnet) for testing protocol changes or contracts in a live environment. Devnets are short lived in nature and can be reset easily.
10+
11+
## Hive testnet
12+
13+
This is just a standard [haf_api_node](https://gitlab.syncad.com/hive/haf_api_node) deployment with the exception of using the HAF testnet image.
14+
15+
1. Clone the `haf_api_node` repository and make a copy of `.env` file.
16+
17+
```sh
18+
git clone https://gitlab.syncad.com/hive/haf_api_node
19+
cd haf_api_node
20+
cp .env.example .env
21+
```
22+
23+
2. Locate and modify the following in the `.env` file:
24+
25+
```sh
26+
# required profiles
27+
COMPOSE_PROFILES="core,hafah,servers"
28+
29+
# use the prebuilt testnet HAF image
30+
HAF_IMAGE=registry.gitlab.syncad.com/hive/haf/testnet
31+
32+
# swagger hostname (replace YOUR_HOSTNAME)
33+
PUBLIC_HOSTNAME="YOUR_HOSTNAME"
34+
35+
# caddy sites (read description in the .env file for info)
36+
CADDY_SITES="http://"
37+
```
38+
39+
Optionally update `ZPOOL`, `TOP_LEVEL_DATASET` and `ZPOOL_MOUNT_POINT` to your desired directory.
40+
41+
3. Create the folders.
42+
43+
```sh
44+
sudo ./create_directories.sh
45+
```
46+
47+
4. Copy the `config.ini` and `pgtune.conf` files from [here](https://github.com/techcoderx/hiverpc-resources/tree/main/testnet) into the dataset folder and `haf_postgresql_conf.d` folder respectively.
48+
49+
<Aside type="note">
50+
These files include the default settings and key required to get block production working.
51+
</Aside>
52+
53+
Using the default values for example:
54+
55+
<FileTree>
56+
- haf-pool
57+
- haf-datadir
58+
- config.ini
59+
- haf_postgresql_conf.d
60+
- pgtune.conf
61+
</FileTree>
62+
63+
5. Start the Hive testnet.
64+
65+
```sh
66+
docker compose up -d
67+
```
68+
69+
To reset the Hive testnet, delete the HAF data directory and repeat from step 3 to 5 above.
70+
71+
## Magi testnet
72+
73+
1. Clone and compile Magi node executables.
74+
75+
```sh
76+
git clone https://github.com/vsc-eco/go-vsc-node
77+
cd go-vsc-node
78+
go mod download
79+
make
80+
```
81+
82+
2. Run the devnet setup script. Run `-help` to view more options.
83+
84+
```sh
85+
./build/devnet-setup -db-url 'mongodb://db:27017' -data-dir ./data/devnet -hive-urls 'http://haftestnodeip:80' -nodes 5 -p2p-host /dns4/magi-\? -drop-db
86+
```
87+
88+
<Aside type="tip">
89+
Use the `?` placeholder in `-p2p-host` to refer to the nth instance, particularly useful for running them in a Docker compose.
90+
</Aside>
91+
92+
3. Start all devnet nodes.
93+
94+
```sh
95+
# Outside docker: run this for every node
96+
./build/magid -network devnet -data-dir ./data/devnet/data-1
97+
```
98+
99+
4. Broadcast the genesis election using one of the instances (shut down the instance's magid first).
100+
101+
```sh
102+
./build/genesis-elector -network devnet -data-dir ./data/devnet/data-5
103+
```
104+
105+
To reset the Magi testnet, reset the Hive testnet first then repeat step 2 to 4.

0 commit comments

Comments
 (0)