How to write smart contracts in C# on ubuntu
To develop smart contracts in C# on ubuntu, basically you need to do the following:
-
Create a library project, write code, and add the smart contract library.
-
Execute
neo-compiler/neon
to generate the compiler. -
Run
neon
to generate the .avm file.
Create a smart contract project
-
In the dotnet command line, create a library project:
mkdir NeoContractDemo cd ./NeoContractDemo/ dotnet new classlib rm ./Class1.cs vim NeoContractDemo.cs
-
In NeoContractDemo.cs, enter the following code and then press
ESC
+wq!
.using Neo.SmartContract.Framework; using Neo.SmartContract.Framework.Services.Neo; public class NeoContractDemo: SmartContract { public static bool Main() { return true; } }
-
Add the smart contract reference:
dotnet add package Neo.SmartContract.Framework --version 2.5.4
-
Compile the smart contract project:
dotnet publish -o ../testlib
Generate the compiler
cd ..
git clone https://github.com/neo-project/neo-compiler.git
cd ./neo-compiler/neon
dotnet publish -o ../../testlib
Generate the .avm file
cd ../../testlib
dotnet neon.dll NeoContractDemo.dll
mkdir ../output
cp NeoContractDemo.avm ../output/NeoContractDemo.avm
For complete scripts, refer to https://raw.githubusercontent.com/hunjixin/NeoContractBuildScriptOnUbuntu/master/SmartContract.sh