I am trying to understand the openzeppelin code for writing ICO contract.
In MintedCrowdsale, mint()
function in ERC20Mintable
is called as mentioned below.
ERC20Mintable(address(token())).mint(beneficiary, tokenAmount));
Could you please let me know how this is being called without inheriting it while defining in the contract MintedCrowdsale ?
Also Why address(token())
is used in ERC20Mintable(address(token()))
? I do not see any such type of constructor in ERC20Mintable
. Could you please help me to understand this as well ?
MintedCrowdsale
contract MintedCrowdsale is Crowdsale {
constructor() internal {}
/**
* @dev Overrides delivery by minting tokens upon purchase.
* @param beneficiary Token purchaser
* @param tokenAmount Number of tokens to be minted
*/
function _deliverTokens(
address beneficiary,
uint256 tokenAmount
)
internal
{
// Potentially dangerous assumption about the type of the token.
require(
ERC20Mintable(address(token())).mint(beneficiary, tokenAmount));
}
}
ERC20Mintable
contract ERC20Mintable is ERC20, MinterRole {
/**
* @dev Function to mint tokens
* @param to The address that will receive the minted tokens.
* @param value The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(
address to,
uint256 value
)
public
onlyMinter
returns (bool)
{
_mint(to, value);
return true;
}
}