Code Monkey home page Code Monkey logo

python-smart-contract-workshop's Introduction

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 a neo-privatenet Docker container optionally with neoscan
  2. First smart contract, just printing "Hello World": 1-print.py
    • Learn using neo-python's build command with the test argument
    • Test differences between Log and Notify
  3. First smart contract using print, Runtime.Log and Runtime.Notify: 2-print-and-notify.py
    • Learn using neo-python's build command with the test argument
    • Test differences between Log and Notify
  4. Basic smart contract using storage: 3-storage.py
    • Storage is one of the key components of most smart contracts
    • Everything is handled as bytes
    • Learn about debugstorage on/off/reset
  5. Check out Dictionary support and neo.Runtime.Serialize
  6. A domain registration smart contract: 4-domain.py
    • users can query, register, transfer and delete domains
    • important concept: checking of ownership
  7. NEX ICO template: https://github.com/neonexchange/neo-ico-template

Note: Inside neo-python's prompt.py you need to run config sc-events on to see any kind of notifications of the examples!

Recommended Setup

Linux or Mac is recommended, and you need Python 3.6+. 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.

Always work with a private network with this Docker image: https://hub.docker.com/r/cityofzion/neo-privatenet You can also easily run the private network with neoscan - just use this Docker compose file:

$ wget https://raw.githubusercontent.com/slipo/neo-scan-docker/master/docker-compose.yml -O docker-compose-neoscan.yml
$ docker-compose -f docker-compose-neoscan.yml up

See here for more information.

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.interop.Neo.Runtime import Log, Notify
from boa.interop.Neo.Storage import Get, Put, GetContext
from boa.interop.Neo.Runtime import GetTrigger,CheckWitness
from boa.builtins import concat, list, range, take, substr

Often used build commands

neo> build sc/1-print.py test 07 05 True False
neo> build sc/2-print-and-notify.py test 07 05 True False
neo> build sc/3-storage.py test 07 05 True False
neo> build sc/4-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

python-smart-contract-workshop's People

Contributors

metachris avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.