NEO Smart Contract Workshop (Part 1)
by Steve for NEO
This workshop assumes intermediate knowledge of the command line.
This portion involves installing and setting up the environment. This is part 1 of the workshop. Part 2 is for command line operations. This portion involves interacting with neo-python command line.
Feel free to email your questions to me.
For errors, typos or suggestions, please do not hesitate to post an issue. Pull requests are very welcome! Thanks!
Task 0 - Install Pre-requisites
Before you start, make sure you have the following:
- Linux/Mac Operating System
- Tested on Ubuntu (v16.04 and newer), Mint v18.3, CentOS v7.5, macOS Sierra
- Python3.6 or later
For Docker, try running the following in terminal:
sudo apt-get install curl sudo curl -sSL https://get.docker.com/ | sh sudo apt-get update && apt-get upgrade sudo service docker start
If you don't have Python 3.6, and have no idea how to install it, run the following commands:
sudo apt-get install software-properties-common python-software-properties sudo add-apt-repository ppa:deadsnakes/ppa sudo apt-get update sudo apt-get upgrade sudo apt-get install python3.6 python3.6-dev python3.6-venv libleveldb-dev libssl-dev g++
For CentOS users, you can refer to this guide on how to install Python 3.6
Task 1 - Getting Started
In this session, we'll be setting up a local private blockchain which allows us to upload and execute smart contracts.
This will be hosted entirely on our own machines!
The process will go in the following order:
- Setting up the Docker Container
- Running NEO Python
1.1 Setting up the Docker Container
Pull the latest image from Docker hub
sudo docker pull cityofzion/neo-privatenet.
Be patient! On the first time round it might take a while to start up.
The Docker image we're pulling is hosted on currently overseas servers. If you're downloading it from a country like China without any special internet tools, it may take hours to load the full image.
Start the container with the command
sudo docker run --rm -d --name neo-privatenet -p 20333-20336:20333-20336/tcp -p 30333-30336:30333-30336/tcp cityofzion/neo-privatenet.
You can open bash within the container with
sudo docker exec -it neo-privatenet /bin/bash.
Stop the container with
sudo docker rm -f neo-privatenet.
1.2 Running NEO Python
If you don't have git, run
sudo apt-get install git
Navigate to a directory of your choice and download the neo-python repository with
git clone https://github.com/CityOfZion/neo-python.git
Go into the neo-python folder with
Create and start a virtual environment so our setup does not interfere with the rest of our machine.
sudo python3 -m venv venv source venv/bin/activate
sudo pip3 install -r requirements.txt sudo pip3 install -e .
Start neo-python with
You should see something like this:
You are now ready to move on to Part 2.