layout | lang | lang-ref |
---|---|---|
post |
en |
Development_compile |
Objective: Know the process of compile, deploy and invoke the smart contract
Main points:
Compile the smart contract to AVM
Deploy the smart contract use the GUI
Invoke the smart contract and get the result
Let's go back to the visual studio and start to compile this simple project.
Click generate
->generate solutions
(hotkeys: Ctrl + Shift + B) in the Visual Studio menu to start compilation.
When the compilation is done, NEO smart contract file namedNEP5.avm
is generated in the bin/Debug
directory of the project.
SmartContractDemo.abi.json
is a descriptive file of the smart contract, which contains descriptions of the ScriptHash, entry, parameters and return values of the contract. More information about the smart contract ABI can be found in NeoContract ABI.
[!!!!Note]
Given that neon compiles .dll with nep-8 by default, which conflicts with nep-5, thus we need to execute .avm using nep-5 compatible method.
Open Power Shell or command prompt (CMD), enter bin/Debug directory and input the following command (replace nep5.dll with your own project file):
neon SmartContractDemo.dll --compatible
The new
SmartContractDemo.avm
file andSmartContractDemo.abi.json
file will overwrite the old files.
We may use NEO-GUI to deploy the newly generated contract file.
-
Open 0.json wallet file, click
advance
->deploy contracts
. -
Click
load
to select the compiled contract filexxx.avm
in the contract deployment dialog.Copy the contract script hash displayed under the code box for late use in contract invocation.
-
Fill in the params in the information and meta data fields.
For this contract, the argument is written as 0710 and the return value is 05.
Detailed rules can be referred to Smart Contract Parameters and Return Values。
Check the box of
required to create a storage area
/No need to check the options
require dynamic invocation
. -
After all the params are defined, click
deploy
->test
->invoke
.
Now you may invoke the smart contract released just recently.
-
Click
advance
->contract call
->function call
。 -
Paste the contract scripthash copied in the last step to
ScriptHash
and press search button. Relevant contract information will be displayed automatically. -
Click
...
besidearguments
to enter the edit interface. Fill in the argument. In this contract, any arguments is ok because the main method does not use that. -
Click
trial
to test the contract. If no error is spotted, clickinvoke
, which may cost several GAS.
If invoke successfully, the gas will be reduced in the account balance.
Congratulations!, you set up your private network and invoke your first smart contract successfully. Now let's begin to learn the basic of NEO smart contract and get your first one.
If you are not set up the IDE yet , you may first click here.