Coding on Neo from Zero — Part 2/3

George_orwell12
The Neo Pulse
Published in
6 min readJun 15, 2020

As a Neo fan with zero coding knowledge, I want to shares my experience of going through the “Developing on Neo” course, in a 3-part blog.

In this next lesson: https://neocourse.mywish.io/lesson/5/, I was finally facing the first coding steps to build a smart contract. In this scenario, I had to create an “NEP-5” token. For reference, NEP-5 is the standard token of Neo, if a project wants to issue a token on Neo, then it would have to comply with the NEP-5 standard.

This post covers the following points:

1. Depending on your operating system you will be required to use different text editors

2. Functions are the vital organs of a smart contract, they all serves a purpose and together they bring the program to life

3. Hash is essential to certify the authenticity and integrity of our file

4. Once the NEP-5 contract is deployed, it can be stored, sent or exchanged for other tokens

First step of this lesson was to open my text editor, in my case I used Terminal because I am using Mac, if you use a PC it will be PowerShell). Then, I had to enter five simple variables to specify the settings of the token:

Afterwards, I wrote the “GetContext” (ctx=GetContext ())function by first importing it from the “neo-boa” library (seems like when developing you need to add more libraries to your system from time to time, because your computer does not have all required “packages of codes” by default):

Next step was to enter the “Main” function in which various parameters and modes shall be inputted, such as “GetTrigger” “TriggerType” and “CheckWitness”. Again, I had to first import other functions from the “neo-boa” library in order to write “Main”:

This is how “Main” looked like:

At this point, I also had to indicate the “Applications” of the token by providing the functions of the smart contract (very roughly, functions make the whole program “act”, by taking some data in, processing it in some way, and producing the output. As I am just learning, I do not have to understand/remember what every function does, but I can see how a number of these functions combined make a program). First functions were “Name” “Decimals” “Symbol” “Total Supply”, and they are relatively easy to make as they take no additional argument values and simply give the values of the contract:

From now on though, more complex functions were needed: “Transfer”, “TransferFrom”, “Approve”, “Allowance”. Below you can see all four of them in yellow and inside them the variables (in orange) required to make the functions work:

For this set, I also had to enter the “balanceOf” operation to provide the value of the tokens, together with the function “do_balance_of” to check the address, in which I specified that its length should be equal to 20 characters (This is specific to neo’ addresses), otherwise the address returns incorrect :

Then, the method for the storage of the smart contract is imported from the “neo-boa” library:

Moreover, I wrote the “events” of the smart contract by using “OnTransfer” and “OnApprove”:

Another set of much more complex functions followed “do_transfer”, “do_transfer_from, “do_approve” and “do_allowance”. I will save you from all the steps to which you can refer in the lesson, but here is an example of how “do_transfer” looked like:

During this process, I also needed to specify this function from the library:

Once all that was done, I was finally able to start deploying this contract on the blockchain. This last step just required me to copy the “Hash”and paste it to the “Owner” parameter (by the way, it is very interesting to learn what hash and hashing is: “A hash function is any function that can be used to map data of arbitrary size to fixed-size values.” — as defined by Wikipedia. Basically how can you make sure files of a huge program or a movie on your and my computer are the same? Hash function can take code of even a very large file, and use a certain algorithm to create a hash of predefined length (say, 20 symbols). And the algorithm is so magical, that if 2 hashes are the same, it means the 2 files are the same!). That said, this operation can be done by opening the “Wallet Team”, entering the wallet command and password “COZ”. Then, you will be able to see the “Hash” and paste it:

Thereafter, I copied the file to the smart contract folder of the neo-local container:

And further entered the “sc build and sc deploy” along with the parameter: “True, False, False” and the data type “0710 05” (these parameters and data type can be adjusted depending on the need of your smart contract):

After entering one last time the password of the wallet the final result is here, the contract is now deployed:

Once this NEP-5 contract is deployed, users can store it in their wallet, send it and exchange for other tokens.

--

--