WatPy - Building Smart Contract Applications Python, Solidity, Flask - 2019 - Sep
WatPy - Building Smart Contract Applications Python, Solidity, Flask - 2019 - Sep
● Let’s see if we can get the balance of one of our ethereum accounts:
○ The call from python to Web3.py can be observed from the ganache-cli terminal as well.
Getting Started - Web3.py
● Send some ETH to your new account from your other accounts:
● The response is the transaction hash registered on the blockchain. Here is the output of the transaction
in ganache-cli:
Explaining Smart Contracts
● Self-Executing contracts that exist on a blockchain
○ Think of it like a computer program
● Contracts can store terms between a buyer and a seller directly written into lines of code (soldity)
● The goal is to provide fully self-executing and self-enforcing contracts, improving on our existing
framework.
Explaining Smart Contracts
● Moving Parts in the Next Step:
○ Solidity - the smart contract language that is most commonly used. This is what this
demo/tutorial will be using.
○ Solc - Solc is a binary and commandline interface for the Solidity Compiler (LLLC).
○ LLLC - the Lovely Little Language Compiler. This binary will translate Solidity Contracts into a
Ethereum-Blockchain executable format.
○ Py-Solc - The python wrapper for the the solc binary.
Building a Smart Contract
Learning More About Solidity
There are plenty of online resources for learning more about Solidity. For exploring more, take a
look at some of the provided documentation and sample contract-implementations:
deploycontract.py
Deploying Contracts
deploycontract.py
Using Flask to Build a dApp - Libraries
Flask Requirements
dapp.py
Web3 Requirements
dapp.py
Using Flask to Build a dApp - Input Form
Define an Input Form
dapp.py
Using Flask to Build a dApp - App Routing
Application Routing: 3 Basic Routes
dapp.py
Application Routing - home (/)
dapp.py
HTML Templates - index.html
Basic template for application:
The ’contractaddress’
variable is inserted into
the template with double
curly brackets:
{% block content %}
{% endblock %}
templates/index.html
HTML Templates - home.html
templates/home.html
What it looks like
Application Routing - Register (/register) - GET
dapp.py
HTML Templates - register.html
Import the index.html
template
templates/register.html
What it looks like
Application Routing - Registered (/registered) - POST
dapp.py
HTML Templates - registered.html
templates/registered.html
What it looks like