Skip to main content

PSP22 Burnable

This example shows how you can reuse the implementation of PSP22 token with PSP22Burnable extension.

How to use this extension

First, you should implement basic version of PSP22.

After you can just add implementation of PSP22Burnable via #[openbrush::implementation(PSP22Burnable)] attribute.

Final code

#![cfg_attr(not(feature = "std"), no_std, no_main)]

#[openbrush::implementation(PSP22, PSP22Burnable)]
pub mod my_psp22_burnable {
use openbrush::traits::Storage;

#[derive(Default, Storage)]
pub struct Contract {
psp22: psp22::Data,

impl Contract {
pub fn new(total_supply: Balance) -> Self {
let mut instance = Self::default();

psp22::Internal::_mint_to(&mut instance, Self::env().caller(), total_supply).expect("Should mint");


pub fn burn_from_many(&mut self, accounts: Vec<(AccountId, Balance)>) -> Result<(), PSP22Error> {
for account in accounts.iter() {
PSP22Burnable::burn(self, account.0, account.1)?;

And that's it! Your PSP22 is now extended by the PSP22Burnable extension and ready to use its functions! You can check an example of the usage of PSP22 Burnable.