unshETH - Dependencies
ERC20Burnable.sol
This is a Solidity file that extends the ERC20 contract with burnable token functionality. It allows token holders to destroy, or 'burn', their tokens, which can be recognized off-chain via event analysis. This file defines two methods: burn
, which destroys tokens from the caller, and burnFrom
, which destroys tokens from a specified account, deducting from the caller's allowance.
ERC20Burnable
The ERC20Burnable contract extends the base ERC20 contract with burnable token functionality. It provides methods to destroy tokens, either from the caller or from a specified account.
burn
function burn(uint256 amount) public virtual
Destroys amount
tokens from the caller. It uses the internal _burn
function of the ERC20 contract.
Parameters
- amount uint256: The amount of tokens to be destroyed.
burnFrom
function burnFrom(address account, uint256 amount) public virtual
Destroys amount
tokens from account
, deducting from the caller's allowance. It first spends the allowance using _spendAllowance
and then burns the tokens using _burn
.
Parameters
- account address: The account from which the tokens will be destroyed.
- amount uint256: The amount of tokens to be destroyed.
Examples
Using the burn method
This example shows how to call the burn method to destroy tokens from the caller's account.
// contract instance
ERC20Burnable token = ERC20Burnable(address);
// amount to burn
uint256 amount = 100;
// burn tokens
token.burn(amount);
Using the burnFrom method
This example shows how to call the burnFrom method to destroy tokens from a specified account.
// contract instance
ERC20Burnable token = ERC20Burnable(address);
// account to burn from
address account = 0x123...
// amount to burn
uint256 amount = 100;
// burn tokens from specified account
token.burnFrom(account, amount);