Setting Up A TomoChain
Setting Up A TomoChain
Setting Up A TomoChain
Session 2 of 5: Setting Up a
Development Environment
1. Recap
2. General Requirements
3. Building a Development Environment
4. Smart Contract Workflow
5. Installing a Simple Web3 Frontend with Web2Py
6. Building a Blockchain Certification System
Developed by Certified by
This has sufficient computing power for our purposes, costs nothing, and saves your work in the
cloud too. All you need is an internet connection -- this is the fastest way to get started.. We start by
logging in and increasing our swap size since the free server is small (check with free -m):
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab //Optional: make ths persistent
node -v
npm - v
Enter your home directory, create a folder for your project, and enter it
cd ~
truffle init
● https://medium.com/tomochain/how-to-
build-a-dapp-on-tomochain-85532a1192e
7
Finally, get the ABI from /build/contracts/name.json -- be sure just to get the section in and including [ ]
brackets. Any web application you write will need this to interact with your smart contract.
● Web applications can then use that data to ‘do something useful’ for our users.
Web2Py is a simple Python framework that we can use to build simple web applications. More advanced
options include Flask (Python), Node.js, React.js, and Angular.js
● Web3 is available as a library for both JavaScript and Python. The Javascript library is probably more
popular, but the Python language itself is more popular -- we’ll use Python today since it’s easier to
read.
● Both libraries work the same way in any case.
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
sudo apt-get install build-essential autoconf libtool pkg-config python-opengl python-imaging python-pyrex
python-pyside.qtopengl idle-python2.7 qt4-dev-tools qt4-designer libqtgui4 libqtcore4 libqt4-xml libqt4-test libqt4-script
libqt4-network libqt4-dbus python-qt4 python-qt4-gl libgle3 python-dev
wget https://mdipierro.pythonanywhere.com/examples/static/web2py_src.zip
Make sure port 8000 is open to tcp under network-->VPC Network-->Firewall rules
Finally:
Web2Py and many web application frameworks work on the model-controller-view system.
Today we will write a small application that interacts with a smart contract that issues educational
certification on TomoChain. We’ll worry about the smart contract itself tomorrow -- for now let's just worry
about sending and receiving data from the blockchain.
with open('/home/sean/web2py/web2py/applications/Certify/controllers/Certify.json') as f:
abi = json.load(f)
w3 = Web3(HTTPProvider('https://testnet.tomochain.com'))
contract_address = '0x0B2B9FB74aD129f0D296AC72CE43166caA044383'
contract = w3.eth.contract(address = contract_address, abi = abi)
setStudent is a specific function of the smart contract -- we’ll see how that works tomorrow.
result = w3.eth.sendRawTransaction(signed_txn.rawTransaction)
tx_receipt = w3.eth.getTransactionReceipt(result)
count = 0
if tx_receipt is None:
tx_receipt = "Failed"
return(tx_receipt)
def check_certification(address):
tx_receipt = contract.functions.getStudent(address).call()
return(tx_receipt)
@service.run
def tsend(address,Name,gradelist):
address = str(address)
Name = str(Name)
tx_receipt = store_results(address, Name, gradelist)
return tx_receipt
def call():
session.forget()
return service()
@service.run
def tcheck(address):
address = str(address)
tx_receipt = check_certification(address)
return tx_receipt
def call():
session.forget()
return service()
def index():
response.view = 'generic.html' # use a generic view
grid = SQLFORM.smartgrid(db.students, deletable=True, editable=True, user_signature=False, links=links)
return dict(grid=grid)
Pay careful attention to user_signature=False -- this disables all login-based access control to the database.
Probably you won’t want that behavior for a live application :)
● Remember, at the end of the class tomorrow there will be a short quiz!
● Also: We’ll airdrop you some Tomo if you attend our hackathon April 20-21st
Developed by Certified by
Introduction to Blockchain & Tomochain