BlockChain


Web3.py

Library to interact with Ethereum blockchain:

Create new instance of web3.py

Note: You need to have a RPC_URL to connect to the blockchain

from web3 import Web3

w3_instance = Web3(Web3.HTTPProvider("<RPC_URL>")
assert w3_instance.is_connected()

Get storage at address (usefull to get private variables):

Note: You need to have a web3 instance (see previous snippet)

Get block information:

Get contract instance:

Get public variables or view/pure functions:

Note: You need to have a contract instance (see previous snippet)

Call transact function (my_awesome_function):

Transact function need to be called with a private key and a caller address

You can also call payable function you just need to add the value, and gas in the tx_data:

Note: Gas and gasPrice need to be calculated before.

Last updated