Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Deploy a Solidity contract providing constructor parameters.
from web3 import Web3
from solcx import compile_source
w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:8545'))
source = 'contract Greeter { string public greeting; constructor(string memory _g) { greeting = _g; } }'
compiled = compile_source(source)
contract_interface = compiled['<stdin>:Greeter']
Greeter = w3.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin'])
tx_hash = Greeter.constructor('Hello Web3').transact({'from': w3.eth.accounts[0]})
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print('Deployed at:', tx_receipt.contractAddress)Web3.py is a Python library for interacting with the Ethereum blockchain. It allows developers to deploy, interact with, and query smart contracts, manage accounts, and handle blockchain transactions programmatically.
Origin & Creator
Web3.py was created by the Ethereum Foundation community in 2016 to provide a Pythonic interface to the Ethereum blockchain.
Industrial Note
Web3.py is preferred in Python-based projects, automated scripts, backend integrations, DeFi bots, and data analytics pipelines interacting with Ethereum.