Creating & Minting Tokens
Not every dapp needs minting support - you might want to only interact with existing tokens. However, if you want to create new assets, you'll need to understand token creation and minting in Yours Protocol.
Token Creation
To create a new token, you'll need to define its specifications and attach any modules you want it to support.
To do this, first let's import ft4 to the module
module;
import lib.yours;
namespace ft4 { // <-- Add FT4
import lib.ft4.accounts;
import lib.ft4.auth;
}
Then the create token operation
// modules/equippables/operations.rell
operation create_equippable(
collection: text,
name: text,
slots: list<text>
) {
// Authenticate the caller
ft4.auth.authenticate();
// Create token specification
val spec = yours.token_info(
project = yours.project_info("Example Dapp", chain_context.blockchain_rid),
collection,
type = yours.token_type.yours,
name,
modules = [rell.meta(equippable).module_name]
);
// Create the token
val token = yours.create_token(spec);
// Attach our equippable module
attach(token, slots);
}
Note, in this example we did not check the authentication of the account.
Minting Tokens
After creating a token definition, you can mint instances of it to specific accounts:
// modules/equippables/operations.rell
operation mint_equippable(
token: yours.token,
to_account_id: byte_array,
amount: integer = 1
) {
// Authenticate the minting request
val account = ft4.auth.authenticate();
// Get the recipient account
val recipient = ft4.accounts.account @ { .id == to_account_id };
// Mint the token
yours.mint(token, yours.balance_info(recipient, amount));
}
Understanding Token Types
In Yours Protocol, the distinction between fungible and non-fungible tokens is determined by how you use them:
Non-Fungible: Create unique tokens by minting only one instance
Semi-Fungible: Create multiple instances of the same token
For example, a unique piece of art would be minted with amount=1, while a game item might have multiple copies.
Best Practices
When creating tokens:
Always authenticate operations
Validate input parameters
Consider which modules to attach
Plan your token distribution strategy
Last updated
Was this helpful?