1. Home
  2. /
  3. Web3py
  4. /
  5. Web3.py Deploy Simple Contract

Web3.py Deploy Simple Contract - Web3py Typing CST Test

Loading…

Web3.py Deploy Simple Contract — Web3py Code

Deploy a simple Solidity contract using Web3.py.

from web3 import Web3
from solcx import compile_source

w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:8545'))

source_code = 'contract Simple { uint public x; function set(uint val) public { x = val; } }'
compiled = compile_source(source_code)
contract_interface = compiled['<stdin>:Simple']
Simple = w3.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin'])
tx_hash = Simple.constructor().transact({'from': w3.eth.accounts[0]})
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print('Contract deployed at:', tx_receipt.contractAddress)

Web3py Language Guide

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.

Primary Use Cases

  • ▸Deploying and interacting with smart contracts
  • ▸Reading blockchain data and logs
  • ▸Automating DeFi and trading operations
  • ▸NFT minting and marketplaces
  • ▸Backend blockchain integrations in Python

Notable Features

  • ▸Python-native interface to Ethereum nodes
  • ▸Supports multiple Ethereum networks
  • ▸Smart contract ABI interaction
  • ▸Event listening and filtering
  • ▸Transaction creation, signing, and sending

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.

More Web3py Typing Exercises

Python Web3.py Simple Smart Contract InteractionWeb3.py Check Ether BalanceWeb3.py Listen to Contract EventsWeb3.py Send Ether TransactionWeb3.py Interact with ERC20 TokenWeb3.py Estimate GasWeb3.py Check Transaction ReceiptWeb3.py Call Contract View FunctionWeb3.py Deploy Contract with Constructor Args

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher