The One Question bounty closes Thursday 10 December.

Join in
We Them Media logo We Them Media Support us

Exploring Smart Contract Interaction || Cohort X

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

Banwela Onchogo recaps a week of smart contracts at Web3 Bridge, focusing on interacting with deployed contracts. They describe using interfaces and a signer with Ethers to call an ERC-20 contract, and explain how a staking contract checks a token balance held in another contract.

Not by We Them Media Channel: Web3Bridge. Published Monday 29 April 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:07 A: Hi everyone, I'm Banwela Onchogo, and during the course of this week at Web3 Bridge, we learned about writing smart contracts. We learned about lots of smart contracts, from multisig wallet to SafeEthers to different smart contracts. But what I'll be talking about today is about interacting with this smart contract.

0:35 B: On-chain interaction is basically interacting with the already deployed smart contracts. So it's just a way of user experience. So what we did basically was interacting with an already deployed smart contract, which was our ERC-20. So we interacted with the transfer function, the balanceOf function, and the transferFrom function.

1:02 A: For contract interactions, right, for you to interact with a contract that has been deployed on-chain, right, it is done using an interface of that contract, right? And when you have the interface of that contract, you need the contract address of that contract and also an interface to implement what we have on that contract, on the contract deployed, then you can now manipulate your way and also interact with the contract in your script folder from your contracts folder, right?

1:36 C: Smart contracts, they live independently of their own self, having their own state variables and their own functions. So I will use, um, an analogy of a state Taking DApp to make you understand how smart contracts interact with each other.

1:51 D: Interactions are one of the use cases why we have interfaces in our smart contracts.

1:57 E: Now, how is interaction being made possible? Now, Solidity made use of interface. Now, interfaces basically is being used for 2 key things: for implementation and interaction. Now, when we deploy a smart contract, on the block explorer like Sepolia. Now we want to interact with that contract that we have deployed.

2:21 D: So this week we deployed the contract, you know, on-chain, and now from our code base we run some interactions that reflected on the block explorer. It was, you know, somehow intriguing, but here, here is what happened. You know, for us to actually sign some transactions, you know, on-chain It requires a signer. Now we utilized the Ethers library, a JS library, and then picked the signer and making available our private key. With these 2, you know, elements, we were able to interact with a contract on-chain running transactions that truly reflected on the block explorer.

3:01 C: So take for example, you go to a particular platform and you want to stake. maybe you want to stake using your Ether. Let's say you want to use your Ether to stake, or maybe those of you that use Optimism, you want to use your DAI to stake. Now this is what happens. The staking contract will communicate to the contract of the DAI to know what is your balance in the DAI token. Maybe you say you want to stake like 20 DAI. So first of all, it takes your address, communicates with the DAI contract, and then knows how many DAI does this guy has in his balance. If you have up to 5 or maybe up to 20 as the amounts that you stipulated, what's going to happen is that it's going to allow you to stake. But you don't have up to that, it's not going to allow you to stake. So this is a very simple analogy of how smart contracts interact with each other.

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.