Step-by-step guide on issuing your NEP-5 token on NEO’s Private net using Go

LikKee Chong (Richie)
Coinmonks
10 min readSep 14, 2018

--

Gopher and NEO

This is a tutorial on setting up the environment for developing NEO smart contracts and NEO DApps using Go. If you don’t know what NEO, smart contracts and DApps are, you can refer to:
What is NEO, and what is GAS?blockknight
NEO Smart Contract Introduction
What is NEO DApps?

Extra Reading
NEO Smart EconomyNEO DApps
NEO For BeginnersNEO News TodayNEOFANS
Awesome NEO

Introduction

Development Language

One of the advantages of developing on NEO’s Smart Contracts platform is that it supports a wide range of development languages.

NEO recommends C#, though it also supports Python, Java, Go, Ruby, and in the future Kotlin, C/C++, JavaScript, and others.

Despite it supports many languages, you will find that most of the existing projects are done using C#, Python, Java, and less on Go. Thus, I will attempt to document a simple tutorial, with reference to City of Zion’s resources, in hopes of attracting Go developers to give it a go (pun intended)!

For Gophers

Regardless of being a first-time or experienced developer, it is always encouraged to begin your journey with a Private net or Testnet.

Why?

Because deploying an NEP-5 token on the Mainnet will set you back by 490 GAS.

At the time of this writing (15th September 2018), the market price for a GAS token is $5.80, which totals up to $2842 and still a rather hefty bill for any startup.

But when the GAS price was at its all-time high, it was $95.87 per token and with just a Smart Contract deployment, it would have left a $47k dent in your budget!

Hence, it is always encouraged that you begin with your journey with on Private net or Testnet and only deploy on Mainnet once you are ready.

Requirements

For this tutorial, the required development environment is as below:
1. Operating System — Ubuntu Desktop 18.04.1 LTS

2. Git CLI — Git

3. Language — The Go Programming Language

4. Go Dependency Management Tool — Dep

5. Docker — Docker CE & Docker Compose

6. Editor — Visual Studio Code, Extension: Go

Other NEO Resources Used

  1. Go Smart Contract framework — neo-storm
  2. Pre-built neo-privnet-with-gas in Python and neo-scan images — neo-scan-docker

Important notes: Results may vary on NEO compiler and node version

In essence, there are several ways to run a PrivateNet, such as using neo-go or neo-privatenet-docker. However, in this tutorial, we will stick with neo-scan-docker by slipo. The neo-scan-docker is built from neo-python, so it will carry some “Python” components. Furthermore, it comes with neo-scan’s UI that allows you to analyze the Smart Contract deployment transactions.

* The installation method may vary depending on your operating system. Please refer to the links above for more info.

Setting up your environment

First, let’s set up your NEO Privatenet with neo-scan-docker.
1. Check that your Git, Docker and Docker Compose are in place.

2. Clone slipo’s neo-scan-docker and load Docker image with docker-compose. It may take a while to download the images, so be patient for the done status to appear.

3. Add 127.0.0.1 neo-privnet into your hosts file. Note that the location of your hosts file may vary on different operating systems.

4. Loadhttp://localhost:4000/ on your web browser and you should see neo-scan’s web UI by City of Zion.

5. Click on theWallet Addresses and you should see a wallet address with pre-loaded NEO and GAS tokens. We will use it for Smart Contract deployments. You can refer to neo-privatenet for more information.

With that, your NEO Privatenet and neo-scan setup are done!

Next, let’s set up your neo-storm.

1.Input the following go version, dep version, and echo $GOPATHinto your Terminal to make sure Go, Dep, GOPATH are in place.

2. Get neo-storm with go get, retrieve dependencies with dep, and install with make install. *Ignore the warning messages

3. Now thatneo-storm has been successfully installed, you should be able to test it.

4. “Done installing, happy coding!” — let’s give our first Smart Contract a go!

Issuing your NEP-5 token contract

  1. To issue an NEP-5 token on NEO, we will have to adhere to its token standard. *For more advance NEP5(.1), you can refer here — it will allow the token to be listed on NEX.

2. Instead of rewriting a token contract, you can fork/clone my repository at — https://github.com/maplerichie/neo-go-nep5

3. Launch your code editor (I use Visual Studio Code) and add~/Desktop/MyFirstNeoGoContract into your workspace. There is also sample from neo-storm examples folder at https://github.com/CityOfZion/neo-storm/tree/master/examples/token

https://github.com/maplerichie/neo-go-nep5

4. Edit package and play around with the NEP-5 attributes such asdecimals, multiplier, owner Address, Name, Symbol, TotalSupply.

Package: package should change to package MyFirstNeoGoContract as same to the folder name

Decimals: This sets the number of decimals used by the token or how much divisible is the token.
For example:
NEO’s decimal is 0, which makes it a non-divisible token. Thus, it is not possible to transfer or receive NEO in decimals and must only be in whole numbers.
However, decimals are possible only on exchanges because they create their own decimal systems to facilitate trading standards.

Multiplier: This gives the value when with Decimals and TotalSupply are multiplied. The input format is10^decimals
For example:
If decimals = 6, the multiplier valeue should be 10^6, so multiplier = 1000000.

Owner: This is your token issuer’s address. Here we will use the neo-privatenet address AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y

Name: Your NEP-5 token name in String

Symbol: Your NEP-5 token symbol. It is usually 3 characters long but not a must.

TotalSupply: This is your total token supply. Setting a maximum supply may prevent inflation.

5. Change the parameters and make sure to comply with the NEP-5 token standard. Then, proceed to compile the Go Smart Contract usingneo-storm

6. You will see main.avm in the current directory. For now, neo-stormdoes not perform checks on the NEP-5 token standard. In my experience, it will show an error if owner Address is missed out.

7. We can now deploy the NEP-5 to a Privatenet Docker. To do so, we will first need to get the Privatenet Docker ID, then copy the main.avm from host location and paste it onto the Privatenet Docker image, and finally attach to it to the running Docker.

8. On Docker, navigate to neo-python-cli and unlock the wallet with the password coz.

9. Before deploying the contract main.avm, let’s take a look at the wallet balance through neo-scan.

10. It looks ready for deployment! Again, the wallet’s password iscoz.

11. Verify the transaction with the hash provided. Note: The hash will different on your machine.

12. After the transaction has shown up, check the wallet balance again. At Step 9, our GAS balance was 74589.9996 and now, the GAS balance is 74099.9996. As such, 490 GAS has been spent for the contract deployment!

We can also look up the contract deployed.

13. Finally, we can try to invoke the token with contract hash using the wallet’s password coz .

There you go! You have now successfully issued your own NEP-5 token on your NEO Private net!

End of tutorial

It is hoped that this tutorial is simple enough for Gophers to follow and hope that any Go developers will NEO’s Discord to participate in its development together. You should definitely give it a go!!

Reach me at Discord LikKee.Richie#5647 if you really need my help :D

Author

Richie Chong, Malaysia
NEOMY Community Member

Proofreader
Aaron Hong, Malaysia

Get Best Software Deals Directly In Your Inbox

--

--

LikKee Chong (Richie)
Coinmonks

Tech Guy | DevSecOps | Dream Catcher #NoveltyLab #AwesomeMalaysia #NeOntology #Midas #BlackSwan #NEOMY #Welo