---
# System prepended metadata

title: Create a burner wallet in Substrate

---

# Create a burner wallet in Substrate

Here is an example of how to create a burner wallet on a Substrate chain using the Rust programming language and the Substrate development framework:

First, make sure you have the Substrate development environment set up on your machine. You can follow the instructions in the Substrate documentation to get started.

Next, create a new Substrate project using the following command:

```
arduino

substrate-node-new burner-wallet
```
This will create a new Substrate project called "burner-wallet" in a directory with the same name.

Navigate into the new project directory:

```
bash

cd burner-wallet
```

Open the lib.rs file in the pallets/burner-wallet/src directory and add the following code to define the BurnerWallet pallet:

```
rust

// lib.rs

use frame_support::{decl_module, decl_storage, decl_event, ensure, Parameter};
use frame_system::{self as system, ensure_signed};

#[cfg(test)]
mod tests;

pub trait Trait: system::Trait {}

decl_storage! {
    trait Store for Module<T: Trait> as BurnerWallet {
        Wallets: map hasher(blake2_128_concat) T::AccountId => u128;
    }
}

decl_event!(
    pub enum Event<T> where AccountId = <T as system::Trait>::AccountId {
        Created(AccountId),
        Sent(AccountId, AccountId, u128),
    }
);

decl_module! {
    pub struct Module<T: Trait> for enum Call where origin: T::Origin {
        fn deposit_event() = default;

        #[weight = 10_000]
        pub fn create_wallet(origin) -> Result {
            let sender = ensure_signed(origin)?;
            let wallet_id = <system::Module<T>>::random_seed();
            <Wallets<T>>::insert(&wallet_id, 0);
            Self::deposit_event(RawEvent::Created(wallet_id));
            Ok(())
        }

        #[weight = 10_000]
        pub fn send(origin, to: T::AccountId, amount: u128) -> Result {
            let sender = ensure_signed(origin)?;
            let balance = <Wallets<T>>::get(&sender);
            ensure!(balance >= amount, "Not enough balance.");
            <Wallets<T>>::insert(&sender, balance - amount);
            <Wallets<T>>::mutate(&to, |balance| *balance += amount);
            Self::deposit_event(RawEvent::Sent(sender, to, amount));
            Ok(())
        }
    }
}
```

This code defines a BurnerWallet pallet that has two functions: create_wallet and send. The create_wallet function creates a new wallet with a random ID and initializes its balance to 0. The send function transfers funds from the sender's wallet to the recipient's wallet.

To build and run the project, use the following command:

```
arduino

cargo run -- --dev
```

This will build and launch the Substrate node in development mode. You can interact with the BurnerWallet pallet using the Substrate API, for example through the Polkadot JS UI.