A simple ERC-20 like token contract implemented in ink! for Substrate blockchains.
- Token Minting: Contract owner can mint new tokens
- Token Transfers: Users can transfer tokens to other accounts
- Balance Checking: Query token balances for any account
- Total Supply: Track the total supply of tokens
- Events: Emits events for token transfers and mints
- Rust (latest stable version)
- cargo-contract - For building ink! contracts
To build the smart contract, run:
cargo contract buildThis will create a target/ink directory containing the compiled WebAssembly (.wasm) file and metadata (.json) file.
To run the tests:
cargo test- Build the contract with
cargo contract build - Deploy the contract to a Substrate node using the generated
.wasmand.jsonfiles
/// Creates a new token contract with the caller as the owner
#[ink(constructor)]
pub fn new() -> Self;/// Mint new tokens (only callable by owner)
#[ink(message)]
pub fn mint(&mut self, to: AccountId, amount: Balance) -> Result<(), Error>;
/// Get the balance of an account
#[ink(message)]
pub fn balance_of(&self, account: AccountId) -> Balance;
/// Transfer tokens to another account
#[ink(message)]
pub fn transfer(&mut self, to: AccountId, amount: Balance) -> Result<(), Error>;
/// Get the total supply of tokens
#[ink(message)]
pub fn total_supply(&self) -> Balance;/// Emitted when tokens are transferred
#[ink(event)]
pub struct Transfer {
from: Option<AccountId>,
to: Option<AccountId>,
value: Balance,
}
/// Emitted when new tokens are minted
#[ink(event)]
pub struct Mint {
to: AccountId,
value: Balance,
}pub enum Error {
/// Insufficient balance for the transfer
InsufficientBalance,
/// Caller is not the contract owner
NotOwner,
}This project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.