Learning SmartX: How to Develop a DApp with Python SDK?
At 2018-11-04 By Yue Zhao

Test a smart contract on Ontology private net

1. Install the Solo-Chain

Step1 - Install the Solo-Chain as Solo-Chain documentation instructs. Here is release address.

Step2 - Run the Solo-Chain.


2. Create a python project

Step1 - Open SmartX and select the python language and blank template. Copy the code in OEP4Sample.py to editor.

3. Compile and deploy

Step1 - Clicking the "Compile" button to compile the smart contract. ABI and AVM will be generated and Opcode will be displayed at the bottom.

Step2 - Deploy the contract

Input basic information and click the "Deploy" button.


The Chrome browser will open Cyano wallet automatically and a confirmation of deployment is required .

Note: You can click setting icon in the upper right corner to open setting and then select the Private-Net. Your account needs to have enough balance to execute the deployment.


After the success of deployment, a contract hash will be generated.

contract hash

4. Test a smart contract on private net

Step1 - Add an account

Input your account private key (hex string) and click the "OK" button.


add account

Step2 - Select the function you want to invoke and run


The log result for successful invocation

log result

Develop a DApp with Python SDK

1. Install punica

pip install punica

We use tutorial-token as an example. Now we install tutorialtoken-box

mkdir tutorialtoken
cd tutorialtoken
punica unbox tutorialtoken

2. Compile ,deploy and invoke

Note: Before compilation, you can modify the code if you want to. The contract ope4_token.py locates under /tutorialtoken/contracts.

2.1 Compile

punica compile

The result:

Compile oep4_token.py
compiled, Thank you

2.2 Deploy

punica deploy

The result:

Using network 'testNet'.
Deploy failed...
Contract has been deployed...
Contract address is 0xd7b6a47966770c1545bf74c16426b26c0a238b16...

Note: The reason why the result occurs "Deploy failed..." is that the contract has already been deployed.

2.3 Invoke

punica invoke
Using network 'testNet'.
Running invocation: oep4_token_abi.json
Unlock default payer account...
Invoking  init
Invoke successful
Invoke result: 0x00
Invoking  name
Invoke successful
Invoke result: 0x4458546f6b656e
Invoking  symbol
Invoke successful
Invoke result: 0x4458
Invoking  decimals
Invoke successful
Invoke result: 0x0a
Invoking  totalSupply
Invoke successful
Invoke result: 0x0000e8890423c78a00
Invoking  balanceOf
Invoke successful
Invoke result: 0x
Invoking  transfer
Unlock signers account...
Invoke failed, Please input gasLimit >= 20000 and gasPrice >= 500
Invoking  transferMulti
Unlock signers account...
Invoke failed, [NeoVmService] vm execute state fault!
Invoking  allowance
Unlock signers account...
Invoke failed, Please input gasLimit >= 20000 and gasPrice >= 500
Invoking  transferFrom
Unlock signers account...
Invoke failed, Please input gasLimit >= 20000 and gasPrice >= 500
Invoking  approve
Invoke successful
Invoke result: 0x00