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

Loading player…

Inheritance: Abstract Contracts

BaseMon, Oct 9, 2023, 12:00 AM

Discover the powerful feature of abstract contracts in Solidity inheritance. Abstract contracts allow you to create contracts with unimplemented functions, making them act as templates. When other contracts inherit from the abstract contract, they must implement the functions defined in it. This way, you can enforce certain behavior in the child contracts and ensure they provide specific functionalities. Don't miss this essential concept to enhance your smart contract designs! 📝💡 📚 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

now let's check one more feature of inheritance and this last feature is called abstract contracts okay abstract contracts allow us to create contracts that can contain functions that are not implemented however contracts that are implementing or inheriting this abstract contract they need to implement the functions that are defined in the abstract contract to create an abstract contract we say abstract then contract and let's call it contract d okay and now what we do is let's create a function call who are you there is going to be public virtual okay and then he's gonna return a string memory and that's all notice that this contract doesn't have any implementation okay now let's do the the contract a has to inherit this contract we're gonna say contract d however check that is failing because we are not implementing the method that this contract is defining so we need to implement it in order to get rid of this error so I'm gonna add the implementation here and I'm just gonna say return who are you let's say a person and we need to overwrite okay yeah this can be pure okay and now it's working so we are implementing this contract d and these who are you function okay so now the code works properly all right let's deploy again zero as the initial type and then we can call who are you a person who am I external contract p who am I Contra a we can change the type and now contract B

Automatic transcript — names and jargon may be misspelled.