Getting Started

Build and deploy your own custom ERC20 token in minutes!

Prerequisites

  • Rust
  • cargo-stylus
  • foundry
  • Wallet with testnet funds
1

Create a New Stylus Project

cargo stylus new my-awesome-token
cd my-awesome-token
2

Add Kairo as a Dependency

Open your Cargo.toml and add Kairo to [dependencies]:

Cargo.toml
[dependencies]
# ... other dependencies
kairo = { git = "https://github.com/Team-Oracle/kairo.git", branch = "main" }
3

Write Your Custom Token Contract

Open src/lib.rs (or src/main.rs) and replace its contents:

src/lib.rs
#![cfg_attr(not(any(feature = "export-abi", test)), no_main)]
extern crate alloc;

// 1. Import Kairo ERC20 components
use kairo::erc20::{Erc20, Erc20Params, Erc20Error};
use stylus_sdk::{alloy_primitives::U256, prelude::*};

// 2. Define token properties
struct MyTokenParams;

impl Erc20Params for MyTokenParams {
    const NAME: &'static str = "My Awesome Token";
    const SYMBOL: &'static str = "MAT";
    const DECIMALS: u8 = 18;
}

// 3. Define storage and inherit ERC20 logic
sol_storage! {
    #[entrypoint]
    struct MyAwesomeToken {
        #[borrow]
        Erc20<MyTokenParams> erc20;
    }
}

// 4. (Optional) Add custom functions (e.g., mint initial supply)
#[public]
#[inherit(Erc20<MyTokenParams>)]
impl MyAwesomeToken
where
    Self: HostAccess,
{
    pub fn init(&mut self) -> Result<(), Erc20Error> {
        let initial_supply = U256::from(1_000_000) * U256::from(10).pow(U256::from(MyTokenParams::DECIMALS));
        self.erc20.mint(self.vm().msg_sender(), initial_supply)
    }
}
4

Deploy to a Testnet

Use cargo stylus to deploy to Sepolia (or another supported testnet):

cargo stylus deploy --no-verify \
  -e <YOUR_SEPOLIA_RPC_URL> \
  --private-key <YOUR_WALLET_PRIVATE_KEY>

Your custom token is now live, inheriting all of Kairo's security and functionality!