Skip to content

BitMari/python-smart-contract-workshop

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Links

If you have any issues or ideas for improvements, please leave your feedback on the GitHub repository and on the NEO Discord.

Steps in the workshop

  1. Setup neo-python and neo-privatenet-docker
  2. First smart contract using print, Runtime.Log and Runtime.Notify: 1-print.py
    • Learn using neo-python's build command with the test argument
    • Test differences between Log and Notify
  3. Basic smart contract using storage: 2-storage.py
    • Storage is one of the key components of most smart contracts
    • Everything is handled as bytes
  4. A domain registration smart contract: 3-domain.py
    • users can query, register, transfer and delete domains
    • important concept: checking of ownership
  5. NEX ICO template: https://github.com/neonexchange/neo-ico-template

Recommended Setup

Linux or Mac is recommended, and you need Python 3.5 at the moment. If you are using Windows, either setup a VM or use the Linux Subsystem (see also here for more infos).

Clone neo-python and setup everything as described in the README. Then create a symlink of this workshop folder to neo-python/sc, which makes it easier to import, build and execute the smart contracts in this workshop.

Typical method signatures

# These two are just examples for playing around and experimenting:
def Main():
def Main(operation):

# This is how most real smart contracts look like:
def Main(operation, args):

See also: parameter & return value types

Often used imports

from boa.blockchain.vm.Neo.Runtime import Log, Notify
from boa.blockchain.vm.Neo.Runtime import GetTrigger, CheckWitness

from boa.blockchain.vm.Neo.TriggerType import Application, Verification
from boa.blockchain.vm.Neo.Storage import GetContext, Get, Put, Delete

from boa.code.builtins import concat

Often used build commands

neo> build sc/1-print.py test 07 05 True False main
neo> build sc/2-storage.py test 07 05 True False main
neo> build sc/3-domain.py test 0710 05 True False query ["test.com"]

Useful code snippets

Timestamps

You can get the last block timestamp from the blockchain with this code.

def now():
    height = GetHeight()
    current_block = GetHeader(height)
    return current_block.Timestamp

Might not work with neo-boa 0.2.2, downgrade to 0.2.1 (see also CityOfZion/neo-boa#35).

Random numbers

See https://medium.com/proof-of-working/coz-first-dapps-competition-dapp-review-3a6b284afaef#414c

About

Workshop for programming smart contracts with Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%