MegaYours Docs
  • 🚀MegaYours
    • Extending your on chain data
  • 💾Megadata
    • Solana Integration
  • 🌎Yours Protocol
    • 🤔Getting Started
      • Setting up Your Project
      • Creating Your First Module
      • Creating & Minting Tokens
      • Composable Tokens
      • Making Your Tokens Interoperable
    • 💱Tokens
      • Types
      • Functions
      • Unique Identifier
    • 🧩Modules
      • 🔌Attaching Modules
      • 🌈Relationships
      • 🎭ERC1155
      • 📚Declaration
      • 👾External
    • 📄Metadata
    • 🔗Interoperability
    • 🔄Migration from Originals
      • FT3
      • Interfaces
      • Prototype
  • 👾Import Existing Tokens from any Chain
    • 🛰️Gamma Chain
  • 🔗Links
    • Github: Yours Protocol
Powered by GitBook
On this page
  • Non-Fungible Tokens
  • Semi-Fungible Tokens

Was this helpful?

  1. Yours Protocol
  2. Tokens

Types

Yours Protocol supports both non-fungible and semi-fungible tokens. The difference is simply how many tokens you create under the same project and collection.

Non-Fungible Tokens

Tokens that are non-fungible are unique per token, this means that under each token, there should maxiumum exist 1 token_balance.

function mint_non_fungible_token(name, to_account_id: byte_array) {
  val spec = yours.token_info(
    project = "Cat Dapp",
    collection = "Cats Collection",
    name,
    modules = [rell.meta(mint_non_fungible_token).module_name]
  );

  val token = yours.create_token(spec);
  val account = accounts.account @ { .id == to_account_id };
  yours.mint(token, yours.balance_info(account, 1L));
}

With the function above, each time we mint, it will create a new token under the same collection.

Assuming that we call this function three times.

mint_non_fungible_token("Bengal", x"DEADBEEF");
mint_non_fungible_token("Maine Coon", x"DEADBEEF");
mint_non_fungible_token("Ragdoll", x"DEADBEEF");

The tokens that would get created are the following.

Project
Collection
Token ID
Token Name
Token Balance

Cat Dapp

Cats Collection

0

Bengal

1

Cat Dapp

Cats Collection

1

Maine Coon

1

Cat Dapp

Cats Collection

2

Ragdoll

1

Semi-Fungible Tokens

Semi-Fungible Tokens can be shared among multiple users, and each user can own multiple of them. This means that we will end up with multiple token_balance under the same token.

function register_semi_fungible_token(name) {
  val spec = yours.token_info(
    project = "Cat Dapp",
    collection = "Cats Collection",
    name,
    modules = [rell.meta(mint_non_fungible_token).module_name]
  );

  val token = yours.create_token(spec);
}

function mint_semi_fungible_token(
  collection, 
  token_id, 
  to_account_id: byte_array, 
  amount: big_integer
) {
  val token = yours.get_token("Cat Dapp", collection, token_id);
  val account = accounts.account @ { .id == to_account_id };
  yours.mint(token, yours.balance_info(account, amount));
}

With the functions above, we will mint new balances of the provided token.

register_semi_fungible_token("Bengal");
register_semi_fungible_token("Maine Coon");
register_semi_fungible_token("Ragdoll");

mint_semi_fungible_token("Cats Collection", 0, x"DEADBEEF", 2L);
mint_semi_fungible_token("Cats Collection", 1, x"DEADBEEF", 1L);
mint_semi_fungible_token("Cats Collection", 2, x"DEADBEEF", 4L);

The tokens that would get created are the following.

Project
Collection
Token ID
Token Name
Token Balance

Cat Dapp

Cats Collection

0

Bengal

2

Cat Dapp

Cats Collection

1

Maine Coon

1

Cat Dapp

Cats Collection

2

Ragdoll

4
PreviousTokensNextFunctions

Last updated 6 months ago

Was this helpful?

🌎
💱