Deploying the Smart Contract

Now we have a compiled smart contract, a private network of the blockchain running, and neo-python fully set up with a wallet with lots of NEO and GAS. The next step is deploying the smart contract with neo-python.

For this example I’ve copied the compiled smart contract (ico_template.avm file) into the neo-python directory, which makes it easier to deploy deploy it into the blockchain:

neo> import contract ico_template.avm 0710 05 True False

contract properties: 1

Please fill out the following contract details:

[Contract Name] > nex ico template

[Contract Version] > 1

[Contract Author] > nex

[Contract Email] > nex

[Contract Description] > nex

Creating smart contract....

Name: nex ico template

Version: 1

Author: nex

Email: nex

Description: nex

Needs Storage: True

Needs Dynamic Invoke: False

{

"returntype": "05",

...

}



-------------------------------------------------------------------------------------------------------------------------------------

Test deploy invoke successful

Total operations executed: 11

Results ['IOp Interface: <neo.Core.State.ContractState.ContractState object at 0x107981128> ']

Deploy Invoke TX gas cost: 490.0

Deploy Invoke TX Fee: 0.0

------------------------------------------------------------------------------------------------------------------------------------- Enter your password to continue and deploy this contract

[password]> coz

[I 171218 12:59:31 Transaction:380] Verifying transaction: b'<transaction-hash>'

The command we used was “import contract ico_template.avm 0710 05 True False”, which means to import the file ico_template.avm with the parameter types 0710 (string and array) and return type byte-array. The parameters “True False” at the end mean “Need storage” (yes) and “Support dynamic invoke” (no). See also the neo docs about SC parameter types.

At this point, the contract is being deployed. Wait for a few blocks until it shows up on the blockchain:

neo> tx <transaction-hash>

Replace <transaction-hash> with the actual hash at the end of the previous step. Once the transaction is found, you can search for the smart contract to get more information. In this example we search for “nex” because we used that in the smart contract deployment step:

neo> contract search nex

Found 1 results for nex

self contract properties: 1

{

"email": "nex",

"properties": {

"dynamic_invoke": false,

"storage": true

},

"code_version": "nex",

"name": "nex",

"description": "nex",

"author": "nex",

"code": {

"returntype": 5,

...

"hash": "70b3f7098a9a3f2361a1f0c312e9842ec4ca6dc6",

"parameters": "0710"

},

"version": 0

}

In this case, the ICO smart contract has the hash 70b3f7098a9a3f2361a1f0c312e9842ec4ca6dc6, which we will need to use for all the method invocations.