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::
    self, extensions::IErc20Burnable, Erc20, IErc20,
;

#[entrypoint]
#[storage]
struct Erc20Example
    erc20: Erc20,


#[public]
#[implements(IErc20<Error = erc20::Error>, IErc20Burnable<Error = erc20::Error>)]
impl Erc20Example {}


#[public]
impl IErc20 for Erc20Example
    type Error = erc20::Error;

    fn total_supply(&self) -> U256 {
        self.erc20.total_supply()


    fn balance_of(&self, account: Address) -> U256
        self.erc20.balance_of(account)


    fn transfer(
        &mut self,
        to: Address,
        value: U256,
    ) -> Result<bool, Self::Error>
        self.erc20.transfer(to, value)


    fn allowance(&self, owner: Address, spender: Address) -> U256
        self.erc20.allowance(owner, spender)


    fn approve(
        &mut self,
        spender: Address,
        value: U256,
    ) -> Result<bool, Self::Error>
        self.erc20.approve(spender, value)


    fn transfer_from(
        &mut self,
        from: Address,
        to: Address,
        value: U256,
    ) -> Result<bool, Self::Error>
        self.erc20.transfer_from(from, to, value)

}


#[public]
impl IErc20Burnable for Erc20Example
    type Error = erc20::Error;

    fn burn(&mut self, value: U256) -> Result<(), erc20::Error> {
        // ...
        self.erc20.burn(value)


    fn burn_from(
        &mut self,
        account: Address,
        value: U256,
    ) -> Result<(), erc20::Error>
        // ...
        self.erc20.burn_from(account, value)

}

On this page