The One Question bounty closes Thursday 10 December.

Join in
We Them Media logo We Them Media Support us

Web3bridge Students (Cohort XI) Share What They’ve Learned: Interface, Interaction & Mainnet forking

The picture loads from YouTube. The player loads only when you press Play. Turn on captions in the player if you need them.

Cohort XI students give a weekly update on three topics. They explain interfaces, which declare functions without logic, state variables or constructors and can act as standards. They describe using an interface and a contract address to interact with an already deployed contract, then cover mainnet forking, where they impersonate a real token holder on a local computer to test against live data.

Not by We Them Media Channel: Web3Bridge. Published Wednesday 11 December 2024.

Titles are the owner’s. It plays from their channel.

Transcript

This transcript may contain errors. This video belongs to Web3Bridge. Letters mark each change of speaker.

These are the speakers’ own words. We have not checked their claims.

0:00 A: This video is proudly brought to you by VirtueBridge with LIX, our official sponsors for Cohort 11.

0:08 B: Hi everyone, I'm Sunday Solomon. Welcome to yet another weekly update. Um, today we'll be talking about interfaces. Interfaces are very similar to abstract contracts where you, just like abstract contracts, can be inherited. Interfaces can also be inherited. Your interface can be inside of a contract and outside of a contract still, but mostly for modularization and to best reduce gas fee- gas fees, we make them outside the contract. So basically inside of another file. Your interfaces can, can be inherited. They can also be imported. So your interfaces, when creating an interface, is just like a contract is also declared where you have your keyword contract and then the contract name and the rest of the code logic that goes into the contract. The same way your interface work, except that for interfaces you have no constructors. For interfaces, you also have no state variables. And then interfaces, you don't have the logic inside of the interface. So what the interface does is it extends- it's like an extension of the actual logic. So what it does is it gives you, um, the parameters needed to run the function instead of its original or instead of its parent representation. So your, your interfaces basically can also act like a standard, just like we have the IRC-20, IRC-721. They also act like a guideline for, say, for interaction. So if you enter- if you have to interact with that interface, you have to follow that interface structure. Mind you, they can still be overwritten. Interfaces can be overwritten where you declare the, the actual interface, and then instead of the interface, you now declare how you want The parameters or the function to be used and returned so they can be overwritten.

2:19 C: Interactions are a way to interact remotely with an already deployed contract. So let's say you have a contract that is already deployed that you would like to interact with or communicate with. What you do is to get the contract address of the already deployed contracts and have that handy and then get the interface as well. Now, when I say the interface, I mean the functions that are readily available inside of the contract. Now you get the functions that you need and you declare them as an interface. Now that interface is going to be able to provide those functions that you need to call from the already deployed contract. Now, when you have that and you have your interface and you have your contract from your code, you can call the functions that are inside of that contract and interact with the deployed contract on-chain. Now, this is useful for when you do not want to- you want to communicate with that contract from your code, or you do not want to communicate from the front end that is available. Another use case is because our tutor gave us a scenario that happened. Say there's this scenario where someone provided liquidity to a pool but isn't able to pull it out, pull it out. Then the way he went about that was getting the interface and then interacting with it from his code and calling the function that is in that contract. And that's a very handy tool for people who want to interact with remotely with already deployed contracts.

4:05 D: So mainnet forkings, it allows us to simulate real-world scenarios because, of course, while we are developing our smart contract, we can use testnet to test our apps and see how they work. But still, we need to simulate some- there are some transactions that some applications that deal with, for instance, DeFi or DEX, So these things, we need to simulate real-world scenarios. So we need to do what we call mainnet forking so that we can simulate how this thing will be working. We work with real-world datasets and states. Mainnet forking is all about interacting with an already deployed contract on-chain. That is basically, you are trying to interact with that smart contract on your local machine. which is your laptop.

4:55 E: When you are doing this, you are not changing the data of the already deployed contract. You are just impersonating that contract on your local machine. And we made use of the Uniswap V2 router, the address, to do this mainnet forking. You can impersonate different contracts on your local machine.

5:16 D: First of all, why do you want to do mainnet forking? Mainnet forking helps as a smart contract developer, it helps you to, you know, test a function that is already deployed in another contract. Maybe you are trying to work on a contract and you want to interact with that contract, but that contract has already been deployed on-chain. So how do you do that? You do that using the mainnet working. And for you to do that, Hardhat provides that package, a helper which you use to impersonate a user, a real user, In the sense like the user already has that token. So in that way, because for you now to interact with it on your local machine, you have to act as if you are a real owner of that coin on that contract.

More from this hub

Something wrong, or a video you want off this page? Write to wethem.xyz@gmail.com and it is fixed or taken down within 48 hours.