New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

The OpenZeppelin ERC 20 Implementation

BaseMon, Oct 9, 2023, 12:00 AM

Implement an ERC-20 token using the OpenZeppelin library, which provides secure and well-audited smart contracts. Follow along to easily create your own ERC-20 token and explore implementation examples for a better understanding. Unlock the world of tokenization! 📚 Head to Base Camp for full courses on smart contract development: https://docs.base.org/base-camp/docs/welcome ✅ Subscribe to our channel here: https://www.youtube.com/@BuildonBase ► Build on Base: https://base.org ► Follow us on Twitter: https://twitter.com/buildonbase ► Join our Discord: https://base.org/discord

Transcript

okay and then let's check some implementation examples so open sapling is a library of smart contracts this library is one of the most used smart contract libraries they have a lot of contracts to Simply Implement an open sampling also do audits so all the contracts here have been audited which is very very good as you can see this project is maintained and the better following higher standard so I definitely recommend this Library and let's check an implementation we go to contracts token then erc20 and then we go to the erc20. soil as you can see this is an implementation of the erc20 you will see that these functions name symbol decimals are the same functions that are defined in the standard okay total Supply the balance of transfer allowance approve and transfer from Okay so as you can see this is a smart contract is fully compliant with the erc20 token standard okay so the good thing is that we can take advantage of this smart contract that is fully audited that is working in production and that is fully ready for us to use it's also well documented alright so what we do is in remix we can simply copy the address and here we can say import and we just paste the link you will notice that remix downloaded a lot of files okay and then what we do is if you remember the inheritance we simply say my erc20 token is erc20 okay then let's do a Constructor and what we are gonna do is if you notice them the implementation on open sapling in the Constructor you can pass a name and a symbol okay also notice the underscore and this is very common in some contracts it depends at the end of the day of your style as developer so um actually we are just gonna copy this Constructor and I personally like to use the underscore at the beginning so that's just a a simple preference Okay so at construction we are gonna pass the name the symbol and then we need to initialize the erc20 and to initialize we simply say erc20 and we're gonna pass the name and the symbol that we are receiving and then we will have automatically a erc20 okay so let's test let's go to the deploy and run transactions and then as you can see we can pass a name so I'm gonna pass my erc20 actually you don't need quotes just like that and then a symbol can be a m y 2 let's say so I'm gonna transact and as you can see the transaction was successful and now let's see the token that I deploy contains all the functionality that the standard defines so let's check decimals by default is using 18 decimals you can check that here okay as you can see this is 18 you can actually read the the comments when they say tokens usually decide to use 18 to imitate the relationship between ether and weight because um one one eater is actually one elevated to the 18 way so most of the tokens use that not all of them like the usdc actually uses 8 decimals so it depends your decision but in order to change this Behavior you need to override a function okay now let's check the name my erc20 the symbol and Y2 total Supply is zero because we don't have any tokens out there yet we haven't mint anything and so for that reason if we even check balances here the balance of is gonna be obviously zero

Automatic transcript — names and jargon may be misspelled.