5/5
## Interacting with Anvil Contract with Titanoboa We will explore how to interact with an Anvil contract with Titanoboa. Let's take a look at our code. We've learned how to deploy this contract and now we will interact with it. To do so we will start with a print statement: ```python print("Storing number...") ``` We will call a function called "store" from our favorites contract. This will set our favorite number to 5. ```python favorites_contract.store(5) ``` Now we will print the ending favorite number. ```python ending_favorite_number = favorites_contract.retrieve() print(f"Ending favorite number is: {ending_favorite_number}") ``` Finally, we will run the code in our terminal: ```bash python deploy_favorites.py ``` We will see the output: - Transaction created - Contract deployed - Starting favorite number is 7 - Storing number... - Ending favorite number is 5 We deployed a new contract and stored a number to it. Now we can see the effects of storing a number and retrieving it through the use of our smart contract and Titanoboa!
We will explore how to interact with an Anvil contract with Titanoboa.
Let's take a look at our code. We've learned how to deploy this contract and now we will interact with it. To do so we will start with a print statement:
We will call a function called "store" from our favorites contract. This will set our favorite number to 5.
Now we will print the ending favorite number.
Finally, we will run the code in our terminal:
We will see the output:
Transaction created
Contract deployed
Starting favorite number is 7
Storing number...
Ending favorite number is 5
We deployed a new contract and stored a number to it. Now we can see the effects of storing a number and retrieving it through the use of our smart contract and Titanoboa!
A practical guide to interacting with an Anvil contract using Titanoboa. The lesson demonstrates how to read and write values to a deployed contract using Python, showcasing the use of the 'boa' library and 'print' statements.
Previous lesson
Previous
Next lesson
Next
Give us feedback
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 August 11, 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 August 11, 2025