In this blog I will cover the basics of writing a C# Smart Contract with the NEO Blockchain.
First of all quick introduction about NEO.
NEO is often referred to, as the Chinese Etherium. NEO and Etherium share alot of basic concepts mainly.
- NEO and etherium are designed to host smart contracts and build DApps is a decentralised manner.
- Both blockchains are fueled by crypto-assets. Ether for Etherium and GAS for NEO.
- Both support proof of stake as a form of mining.
How do we build a smart contract in NEO ?
To build a smart contract we need a programming language. C# has been part of the NEO ecosystem from inception which is optimal if your stack in based on C#. There is no need to learn a new language to write a smart contract as opposed to Etherium.
Setting up the environment
This blog post assumes you have Visual Studio 2017 or higher. First step you will need to install the NeoContrantPlugin. Go to . Tools -> Extenstion and Updates -> Select Online -> Type Neo in search bar and install the plugin.
Next task, we need to setup is the Neo compiler. This compiler will compile the our contract and generate a byte code representation of the contract.. There is no clean setup. Setup requires the following manual steps.
- Clone the project from the git hub repository.
- Publish the project to a folder of choice. Publishing the project from the UI will could result in this error
Can’t find neon.dll for win10-x64.This is due to the fact that you are using a buggy version of Visual Studio. Issue can be fixed by compiling the project through command prompt. Open cmd , locate the path where the project was cloned and deploy the neon project using this command sequence.
d:\xxx\xx\neon>dotnet publish -r win10-x64 -c release
- Setup environmental variable to point to the folder where the compiler was published.
The check that the compiler has been properly installed. Load a cmd prompt and type noen. The following should be the output of the command prompt.
Writing the smart contract
Now that we have our development environment setup correctly. We can create our hello world contract. First thing we need to do is create a new project based on the NeoContact template.
The template will generate class which inherits from SmartContract.
[code]
namespace HelloWorldNeoContract
{
public class Contract1 : SmartContract
{
public static void Main()
{
Storage.Put(Storage.CurrentContext, "Hello", "World");
}
}
}
[/code]
Once you build the project a .avm file will be generated. This is the compiled version of out contract.
Wooooowoo. We have created our first contract.
In the next blob post I will cover the steps of deploying and invoking the smart contract using the Neo blockchain.
Hope this blog was helpful. If you need assistance or consultancy feel free to contact me on [email protected].