Custom Trait
Next, we will expand the contract with more utility methods to have more control over the NFT creation, minting, payments and all that most of the NFT projects will need.
To start with we will move mint()
from contract lib.rs
to a custom trait PayableMint
.
Folder Structure for Custom Trait
Before starting to add code we need to prepare the scene for the external trait. Create new logics
folder with following empty files:
.
├── Cargo.toml
├── contracts
│ └── shiden34
│ ├── Cargo.toml
│ └── lib.rs
└── logics
├── Cargo.toml
├── impls
│ ├── mod.rs
│ └── payable_mint
│ ├── mod.rs
│ └── payable_mint.rs
├── lib.rs
└── traits
├── mod.rs
└── payable_mint.rs
Module Linking
With the extended structure we need to link all new modules. Let's start from logics
folder.
The crate's lib.rs
needs to point to impls
and trait
folders and since it is top module for this crate it needs a few macros:
#![cfg_attr(not(feature = "std"), no_std)]
pub mod impls;
pub mod traits;
The crate's Cargo.toml
will import all ink! and Openbrush crates and it will be used by the contract's Cargo.toml
to import all methods. We will name this package payable_mint_pkg
.
[package]
name = "payable_mint_pkg"
version = "3.1.0"
authors = ["Astar builder"]
edition = "2021"
[dependencies]
ink = { version = "4.2.1", default-features = false }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true }
openbrush = { tag = "v4.0.0-beta", git = "https://github.com/Brushfam/openbrush-contracts", default-features = false, features = ["psp34", "ownable"] }
[lib]
path = "lib.rs"
crate-type = ["rlib"]
[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info",
"openbrush/std",
]
Add same mod.rs
file in folders: traits, impls, and impls/payable_mint.
pub mod payable_mint;
As a last step add link to payable_mint
in contract's Cargo.toml
.
payable_mint_pkg = { path = "../../logics", default-features = false }
[features]
default = ["std"]
std = [
// ...
"payable_mint_pkg/std",
]