Composable Tokens
Due to the fact that it up to you as a dapp developer to decide how you persist data for a token, you can actually achieve composability between different modules very easily.
Let's extend our application with a second module, an avatars module.
// modules/avatars/module.rell
module;
import equippables; // import our first module
import lib.yours;// modules/avatars/model.rell
entity avatar {
key yours.token; // the avatar itself is a token as well
}
entity equipment {
key avatar, yours.token;
}// modules/avatars/functions.rell
function attach(token: yours.token) {
yours.attach_module(token, rell.meta(avatar).module_name);
create avatar(token);
}
function equip(avatar: avatar, item: yours.token) {
require(equippables.get_equippable(item) != null, "Item must be equippable");
create equipment(avatar, item);
}
function get_avatar(token: yours.token): avatar? {
return avatar @? { token };
}This logic above allows an avatar to equip 1 token of each equippable. But not the same equippable twice.
Now we can mint this token. I want an avatar to be a NFT, which means we will create a new token each time we create an avatar.
Equipping Items
Now that we have both modules set up, we can create operations to equip items:
Last updated
Was this helpful?