1/5
## Introduction to web3.py We're going to learn how to deploy a contract to the Ethereum blockchain by using the web3.py library. We're going to start by installing web3.py in our UV environment. ```bash uv add web3 ``` We can check to make sure it's installed by running `uv sync` and checking our `pyproject.toml` file for the web3.py dependency. Next, we'll import web3.py and the Ethereum Tester Provider: ```python from web3 import Web3 from web3.providers.eth_tester import EthereumTesterProvider ``` We'll then initialize a Web3 object by using the Ethereum Tester Provider: ```python w3 = Web3(EthereumTesterProvider()) ``` The Ethereum Tester Provider simulates a local blockchain node, which is useful for development. Now, let's get our bytecode from the Vyper object. We'll use the `compile_code` function and specify the output format as `bytecode`: ```python compilation_details = compile_code(favorites_code, output_formats=['bytecode']) ``` We can print out the `compilation_details` to see the results of compilation, including the byte code. ```python print(compilation_details) ``` Finally, we can create a contract instance by using the bytecode from the `compilation_details` object. ```python favorites_contract = w3.eth.contract(bytecode=compilation_details['bytecode']) ``` We'll explore how to interact with the deployed contract in later lessons.
A comprehensive introduction to Web3.py - Learn how to interact with the Ethereum blockchain using Python. This lesson introduces web3.py, a Python library for interacting with Ethereum, and shows how to create a contract object, deploy a contract, and interact with a contract instance.
Previous lesson
Previous
Next lesson
Next
Give us feedback
0.4.1 of Vyper
Last updated on April 21, 2025
Course Overview
About the course
Python basics
Introduction to Web3.py
Introduction to Titanoboa
Introduction to Moccasin
How to create an ERC-20
How to test Python code and Vyper smart contract
How to deploy Vyper smart contracts on ZKsync using Moccasin
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on April 21, 2025
Duration: 2h 20min
Duration: 1h 51min
Duration: 58min
Duration: 2h 23min
Duration: 53min
Duration: 2h 24min
Duration: 28min
Duration: 1h 54min
Duration: 11min
Course Overview
About the course
Python basics
Introduction to Web3.py
Introduction to Titanoboa
Introduction to Moccasin
How to create an ERC-20
How to test Python code and Vyper smart contract
How to deploy Vyper smart contracts on ZKsync using Moccasin
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on April 21, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar