I'm having trouble understanding the syntax of the following line of Solidity used to construct an ERC20 token using the OpenZepplin library:
constructor(uint256 cap) ERC20("DevToken", "DVT") ERC20Capped(cap){ }
I'm looking for clarification of the following points:
If someone is able to go through word by word and explain the entire line that would be even more helpful.
I find the documentation for solidity very hard to understand, as an aside, does anyone have any recommendations for resources that will help me better understand the syntax of the language?
- constructor does not have any names.
constructor
of the contract is only called when you deploy the contract
Your base contract is inheriting from two other contracts:
ERC20("DevToken", "DVT") ERC20Capped(cap)
when a contract inherits from another contract, it gains access to the inherited contract's functions, variables, and modifiers. During deployment, the bytecode of the base contract includes the bytecode of the inherited contracts. This creates a single bytecode file that represents the complete functionality of the deploying contract and its inherited contracts. since inherited contracts have constructor
function, when you deploy your contract, you are initializing those constructors, as well.
- Why does the ERC20Capped portion take a 'cap' variable instead of actual data like the ERC20 portion does?
you should check inherited contracts and they will tell you what parameters are passed to their constructors