This is an introductory workshop for how to develop Ethereum smart contracts with Python3.
The popular Python library Populus
will be used to test and deploy smart contracts. Smart contracts are generally written in Solidity
which is a programming language specifically developed to run on the Ethereum Virtual Machine.
- Clone this project into a new folder on your machine
- Install all
System Dependencies
, which are stated in this article - Install the
Solidity Compiler
as explained in this article - Create a new
Virtual Environment
with Python 3.5 or later. This article explains how. - Activate your Virtual Environment as described in the article.
- Install all requirements with
pip install -r requirements.txt
- Run
populus compile
. You should the compiled contract in the folder/build
- Run the tests with
py.test tests
.
- Run the local chain with
testrpc --seed 0
- Run Django server with
python manage.py runserver
- In your browser, go to
http://localhost:8000
- Open the
Inspector
in your browser. Here's how to do that in Chrome or Firefox. - Go to
Console
in the Inspector. You should see some info about what's happening.
- Any Smart Contract functionality can be written into
contracts/ICO.sol
- After you wrote your functionality, run
populus compile
- Then add the
abi
value frombuild/contracts.json
to thecontractABI
inwebsite/ico/static/js/index.js
- Add the
bytecode
value frombuild/contracts.json
to thecontractBytecode
, also inwebsite/ico/static/js/index.js
- After you wrote your functionality, run
- Any Frontend functionality can be written into
website/ico/static/js/index.js
- Once you added your functionality, just refresh your website at
localhost:8000
. - I recommend to access the website in the Incognito mode of your browser. This way, your browser won't load the website from cache, but take it from your project.
- Once you added your functionality, just refresh your website at
The goal of the workshop is to get an understanding of how to write and deploy Smart Contracts. Once you have the project up and running, you can try to extend the Smart Contract with either your own functionality, or alternatively, you can pick from one of these challenges:
- Add a maximum amount of coins that buyers can buy
- Think about what message you send when that amount is reached and how you send it.
- Add discounts for buying coins
- Buyers could get a 50% discount for the first 10.000 coins, 40% for the next 10.000 and so on.
- Add a refund function
- Think about who should be able to call this function (probably only the
owner
) - Will all coins be refunded or only a part?
- Advanced: Add a time frame in which a refund can be requested. Buyers are not able to request a refund after that time frame expired.
- Think about who should be able to call this function (probably only the
- Add functionality that can only be executed using the coins
- Like a Voting function, or requesting a funny message
Here are some links to interesting resources about Ethereum and Smart Contracts