ERC-20 Burnable
Extension of ERC-20 that allows token holders to destroy both their own tokens and those that they have an allowance for, in a way that can be recognized off-chain (via event analysis).
Usage
In order to make ERC-20 Burnable
methods “external” so that other contracts can call them, you need to implement them by yourself for your final contract as follows:
use openzeppelin_stylus::{
token::erc20::{
extensions::IErc20Burnable,
Erc20, IErc20,
},
};
sol_storage! {
#[entrypoint]
struct Erc20Example {
#[borrow]
Erc20 erc20;
}
}
#[public]
#[inherit(Erc20)]
impl Erc20Example {
pub fn burn(&mut self, value: U256) -> Result<(), Vec<u8>> {
// ...
self.erc20.burn(value).map_err(|e| e.into())
}
pub fn burn_from(
&mut self,
account: Address,
value: U256,
) -> Result<(), Vec<u8>> {
// ...
self.erc20.burn_from(account, value).map_err(|e| e.into())
}
}