The One Question bounty closes Thursday 10 December.

Join in
We Them Media logo We Them Media Support us

Exploring Smart Contracts || Cohort X Shares Insight

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

Students recap week 5 of Web3 Bridge, the start of smart contract writing, from a simple get and set contract to ERC-20 and ERC-721 tokens and three savings contracts. They explain token standards, unit testing, interfaces, multisig wallets and libraries, and mention best practice such as avoiding reentrancy.

Not by We Them Media Channel: Web3Bridge. Published Sunday 28 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:08 A: Hello viewers, thank you for constantly watching our videos weekly. We are excited to bring you another insightful and educating video.

0:21 B: So week 5 has been amazing. This was the beginning of our smart contract week, and having learned the basics of Solidity, we dove right into writing smart contracts. You know, we learned about the development tools that we use, Remix and Hardhat majorly. And we started off easy with a simple setter-getter, you know, contract that just sets data to the blockchain and retrieves that data. And then we went into the more serious stuff like the ERC-20 standard, the ERC-721 standard, and then Went as far as writing 3 versions of a savings contract. One to save Ether, another to save an ERC-20 token, and another to save both Ether and ERC-20 token. The mentor, Kaswini, also took his time to teach us about best practices. Best practices like avoiding reentrancy and also sanity checks. We also went neck deep into testing using Mocha and Hardhat. Smart contracts are executable They are self-executable programs. They run on the blockchain.

1:25 C: They are executed when predefined conditions are met. They can be used independently, and sometimes they are- and most times they are implemented with dApps.

1:37 A: So the major reason why people use smart contracts is because they are immutable. Another major reason why people use smart contracts is because it is distributed.

1:45 B: SafeEther contract allows users to deposit Ether And withdraw Ether.

1:50 D: And Ether is the native currency of the Ethereum blockchain. How does this SaveEther contract work? We made use of mapping, which helps us to keep track of users that save in the contract.

2:06 B: In the SaveEther contract, there are 4 major functions. There's a deposit function, there's a withdraw function, there's a check balance function, and there's a check contract balance function.

2:15 E: The event management smart contracts whereby we used- it was NFT-gated, meaning that the attendees needed to have an ERC-721 NFT to be able to attend your event.

2:28 F: There's a contract called SimpleStorage which has a state variable called _data, and the _data is a type of number. So we use unsigned integer to assign a number. for a state variable. And we also have a function called setData where anybody can actually update the state of that data. And then we also have, um, another function called getData where you can actually get or retrieve the data from that state variable.

2:59 C: Token standards are basically, um, agreed-upon rules that guide development, design, and implementation, and also the Use of these tokens, right? The ERC-20 and the ERC-721, these are the most common token standards we use when we write smart contracts. ERC-20 stands for Ethereum Request for Comments number 20. ERC-20 is just a token standard that follows a technical guide on how tokens should be built on the Ethereum blockchain.

3:32 G: ERC-20 tokens are digital assets that adhere to set of rules. So these rules ensure that they are interoperable, they are compatible, they are fungible, and they are transferable.

3:45 C: For a token to be considered on the Ethereum blockchain, it has to implement some certain functions and events for it to be considered ERC-20 compliant. The events that must be included include the transfer events and the approval events.

4:02 A: ERC-20 tokens have some functions that have to be there. This includes balance of Approve, transfer, among others. And you can also have some optional ones like symbol, name, all those stuff.

4:13 E: ERC-721 token is a token that follows ERC-721 token standard.

4:19 A: And it's used for NFTs. You've seen them like CryptoPunks and every other NFT people create. So this can be physical assets presented in the blockchain or just digital assets that are made in the blockchain.

4:33 H: What makes NFTs like unique of all the digital assets is because your- the ID of the NFT is being like mapped to the address of the owner. So for every NFT, the only unique thing is the ID. So you can't see the same NFT with, with the same ID. You can't see one NFT with the same ID.

4:53 C: They have different IDs, which makes them more secure, and it increases like operability because you can use it It's a non-fungible token, like it's a digital asset, so you can use it for anything. It's cross-platform, provided you are using it on an Ethereum blockchain.

5:09 I: The only difference between the both of them is that the ERC-721 token has, um, an owner-of function, which means every token has a specific owner, but the ERC-20 can be owned by anyone and can have the same value at any time.

5:26 J: So any testing It's a software testing method where you test your functions in units.

5:35 K: Testing is the act of checking your code unit by unit to be sure they are working properly.

5:40 L: We have different frameworks in testing. We have the Chai, we have the Mocha, we also have the Foundry. And other languages, we have the PyTest and JUnit generally. There are different 2 types of unit tests. We have the TDD, which is the test-driven development, and the BDD, which is the behavioral-driven development.

5:57 J: Unit testing is good because it helps you to save money. You don't push things that are not working to production hoping that they will work.

6:07 B: So it's essential we test our code before pushing it to production because it's very expensive to test your code when it's already on the blockchain.

6:15 M: Interfaces. And this interface is a way to define the behavior of a contract without actually implementing it. We have 2 uses for these interfaces. One is for implementation and secondly for interaction. And in implementation, all the functions are being used, but in interaction, we interact with already deployed contracts on-chain.

6:36 N: A multisig wallet is a kind of wallet that involves 2 or more private keys to authorize the transactions.

6:44 O: Multisignature is more secure than a single- multisignature is more secure than a single signature transaction.

6:50 N: Some of the benefits of this multisig wallet is being used in financial institutions, crowdfunding, and so many more.

7:00 P: Libraries are a special type of smart contract that contains reusable code.

7:05 Q: Solidity libraries foster code reusability and they allow developers to, you know, add and implement methods for specific data types. So similar to classes and objects in object-oriented programming. So these methods can be accessed using the dot notation.

7:26 P: But what are the benefits of a library? The first one is the fact that a library is reusable. The second one is the fact that it is economical. The third one is the fact that a library are good add-ons to have in our code. Here are some of the limitations of a library. The first is a library does not have storage. A library cannot accept ethers, neither can it have a payable function. Also, libraries cannot be inherited nor inherit other smart contracts. And lastly, a library cannot be destroyed. It is indestructible.

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.