5/5
## Storing Contracts By Interface Type We're going to do a little bit of refactoring here, just to show you something cool that you can do. This `i_favorites` interface, we can also store contracts not just by address, but we could store them as type `i_favorites`. So, what we can do is instead of storing this as an address, we can store these as this `i_favorites` type. If we do that, we're actually going to get to save an extra line of code. Down here, when we call `self.list_of_favorite_contracts` at the favorites index, it's not going to give me an address anymore, it's going to give me an `i_favorites`. So, what we can do is we can say, instead of `favorites_address`, we can do `favorites_contract` of type `i_favorites` and then just delete that next line. Additionally, when we do `self.list_of_favorite_contracts.append`, we would have to wrap our `new_favorites_contract` as type `i_favorites`. We don't have to do this. If what we just showed you is actually very confusing, feel free to just move it back to what it was. Which is this one right here. Feel free to just move it back to what it was, and go with that. Whatever is easier for you, this is your learning journey, and you can come back to this later and go, "Okay, what did Patrick mean by that? Let me ask some AIs, etc., etc." This is another way that we can actually store and work with these variables. ```python from interfaces import i_favorites list_of_favorite_contracts: publicDynArray[i_favorites, 100] original_favorite_contract: address @deploy def __init__(original_favorite_contract: address): self.original_favorite_contract = original_favorite_contract @external def create_favorites_contract(): new_favorites_contract: address = create_copy_of(self.original_favorite_contract) self.list_of_favorite_contracts.append(new_favorites_contract) @external def store_from_factory(favorites_index: uint256, new_number: uint256): favorites_contract: i_favorites = self.list_of_favorite_contracts[favorites_index] favorites_contract.store(new_number) ```
We're going to do a little bit of refactoring here, just to show you something cool that you can do.
This i_favorites
interface, we can also store contracts not just by address, but we could store them as type i_favorites
.
So, what we can do is instead of storing this as an address, we can store these as this i_favorites
type.
If we do that, we're actually going to get to save an extra line of code.
Down here, when we call self.list_of_favorite_contracts
at the favorites index, it's not going to give me an address anymore, it's going to give me an i_favorites
.
So, what we can do is we can say, instead of favorites_address
, we can do favorites_contract
of type i_favorites
and then just delete that next line.
Additionally, when we do self.list_of_favorite_contracts.append
, we would have to wrap our new_favorites_contract
as type i_favorites
.
We don't have to do this. If what we just showed you is actually very confusing, feel free to just move it back to what it was. Which is this one right here. Feel free to just move it back to what it was, and go with that. Whatever is easier for you, this is your learning journey, and you can come back to this later and go, "Okay, what did Patrick mean by that? Let me ask some AIs, etc., etc."
This is another way that we can actually store and work with these variables.
A practical guide to storing contracts by interface type - This lesson demonstrates a refactoring technique to store contracts by interface type rather than by address, showcasing its efficiency and practical benefits in Vyper development.
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