Python in Blockchain
PyCon.LT 2018
Jaro Šatkevič - @chompomonim
About Me
Agenda
- What is Blockchain (main building blocks)
- Which blockchains actually works.
- Intro into Bitcoin and Ethereum.
- What are main problem domains to solve in blockchain world.
- Ideas where python is good choice.
- Actual projects made in pythons (where to join) and list of libraries/tools for those who wanna start own project.
Which of them actually works?
Which of them actually works?
Rest are mostly experiments or tokens
- EOS - ERC20 token
- Cardano - still in early beta
- IOTA - early beta
- Tron - ERC20 token
- ...
What is blockchain?
Consensus
Cryptography is a king
Is Python good for Blockchain?
Isn't C++, Go, Rust or Java mostly used for blockchain creation?
Yes and No
Main parts of Bitcoin
Full node
Mining
Wallet
Bitcoin core
Full node
Ledger of transactions
Mining
creation of blocks with tx
Wallet
view balances, create & sign tx
UTXO > balance
Python libs and tools
Usage example
> from cryptos import *
> c = Bitcoin(testnet=True)
> priv = sha256('a big long brainwallet password')
> priv
'89d8d898b95addf569b458fbbd25620e9c9b19c9f730d5d60102abbabcb72678'
> pub = c.privtopub(priv)
> pub
'041f763d81010db8ba3026fef4ac3dc1ad7ccc2543148041c61a
29e883ee4499dc724ab2737afd66e4aacdc0e4f48550cd783c1a73
edb3dbd0750e1bd0cb03764f'
> addr = c.pubtoaddr(pub)
> addr
'mwJUQbdhamwemrsR17oy7z9upFh4JtNxm1'
Lightning network
In one minute
It knows only what it was told about
Online
Service
User
Service
Python libs and tools
Smart contract
beneficiary: public(address)
auction_start: public(timestamp)
auction_end: public(timestamp)
highest_bidder: public(address)
highest_bid: public(wei_value)
ended: public(bool)
@public
def __init__(_beneficiary: address, _bidding_time: timedelta):
self.beneficiary = _beneficiary
self.auction_start = block.timestamp
self.auction_end = self.auction_start + _bidding_time
@public
@payable
def bid():
assert block.timestamp < self.auction_end
assert msg.value > self.highest_bid
if not self.highest_bid == 0:
send(self.highest_bidder,self.highest_bid)
self.highest_bidder = msg.sender
self.highest_bid = msg.value
@public
def end_auction():
assert block.timestamp >= self.auction_end
self.ended = True
send(self.beneficiary, self.highest_bid)
Oracle
import json
import web3
from web3 import Web3, TestRPCProvider
from solc import compile_source
from web3.contract import ConciseContract
w3 = Web3(TestRPCProvider())
contract = w3.eth.contract(abi=abi)
contract_address = '0x85aC27E4124863492DB18EAFBb358102Cad8fc96'
contract_instance = w3.eth.contract(
abi=abi,
address=contract_address,
ContractFactoryClass=ConciseContract)
contract_instance.bid(transact={'from': w3.eth.accounts[0], 'value': 10000})
print('Highest bid: {}'.format(contract_instance.highest_bid()))
Blockchain ecosystem needs you
- Full nodes
- Mining software
- Wallets of all kind
- Blockchain explorers
- Blockchain monitoring
- Payment processors
- Exchanges
- Smart-contracts
- Oracles
- Lightning network
- Side chains
- Splitting coins
- Deployment scripts
- ...
Let's discuss
Jaro Šatkevič - @chompomonim - me@jarocoin.com
Python in Blockchain
By Jaro
Python in Blockchain
- 3,136