ManicMinter Setup
This is a tutorial on creating a minter contract and a token contract using the ink! smart contract framework. In this tutorial, you will learn how to develop two contracts, use cross contract call and test it with ink! e2e framework.
The minter contract will handle the minting of new fungible tokens, while the token contract will adhere to the PSP22 standard. Our chosen name for the fungible token smart contract is "Oxygen," and the minter contract will be called "ManicMinter."
Once the contracts are created, the ManicMinter contract will become the owner of the Oxygen contract. Only the ManicMinter contract will have the ability to mint Oxygen tokens, and users will acquire these tokens by paying native tokens to the ManicMinter contract at a price determined by its owner.
Let's help Willy to mint some Oxygen tokens through the ManicMinter contract!
Prerequisites
Please refer to the previous section for the list of prerequisites.
ManicMinter and Oxygen Smart Contracts
Initial Setup
In a new project folder, execute the following:
$ cargo contract new manicminter
$ cargo contract new oxygen
Create the root Cargo.toml
file with the workspace content:
[workspace]
members = [
"oxygen",
"manicminter",
]
Oxygen Contract Setup
Let's create a new ink! smart contract for fungible tokens using Brushfam library for PSP22. In the oxygen/
folder, add the following to the Cargo.toml
file:
[package]
name = "oxygen"
version = "1.0.0"
edition = "2021"
authors = ["The best developer ever"]
[dependencies]
ink = { version = "4.1.0", default-features = false }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }
# Include brush as a dependency and enable default implementation for PSP22 via brush feature
openbrush = { tag = "3.1.0", git = "https://github.com/727-Ventures/openbrush-contracts", default-features = false, features = ["psp22", "ownable"] }
[lib]
path = "lib.rs"
crate-type = [
"rlib",
]
[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",
"openbrush/std",
]
ink-as-dependency = []
In the same oxygen/
folder, add the following to the lib.rs
file:
#![cfg_attr(not(feature = "std"), no_std)]
#![feature(min_specialization)]
pub use self::oxygen::OxygenRef;
#[openbrush::contract]
pub mod oxygen {
use openbrush::contracts::ownable::*;
use openbrush::contracts::psp22::extensions::mintable::*;
use openbrush::traits::Storage;
#[ink(storage)]
#[derive(Default, Storage)]
pub struct Oxygen {
#[storage_field]
psp22: psp22::Data,
#[storage_field]
ownable: ownable::Data,
}
impl PSP22 for Oxygen {}
impl Ownable for Oxygen {}
impl PSP22Mintable for Oxygen {}
impl Oxygen {
#[ink(constructor)]
pub fn new(initial_supply: Balance) -> Self {
let mut instance = Self::default();
instance
._mint_to(instance.env().caller(), initial_supply)
.expect("Should mint");
instance._init_with_owner(instance.env().caller());
instance
}
}
}
This tutorial uses ink! version 4.1.0. If you are using a different version, please update the Cargo.toml
file accordingly.
ink = { version = "4.1.0", default-features = false }
Use Openbrush version 3.1.0
with ink! version 4.1.0 and add features "psp22" and "ownable".
openbrush = { tag = "3.1.0", git = "https://github.com/727-Ventures/openbrush-contracts", default-features = false, features = ["psp22", "ownable"] }