Tutorials
MultiAsset Journey
Part 2

Multi-Asset Journey ( Part 2, Cookbook )

User journey context

Expert chefs Master and his student Alice are traveling the world to develop unique recipes. Their goal is to create a renowned cookbook showcasing their culinary innovations.

Minting NFTs

After starting their travels, Master and Alice decided to separate and they had taken two separate different paths. Master crafted his cookbook in Japan, ancient place rich with tradition and history.

We provide valid IPFS URI throughout all of steps, feel free to use them, they point to a JSON file with the corresponding metadata for the step.

While connected to the Master's account, go under deployed contracts and search for the mint method. Expand it and fill the data.

  • to: Master's address
  • numToMint: 1
  • tokenURI: ipfs://QmWcoQ7MvDRVCBZ2Xii3TtNYThdoibztG1gkutDHyS6KQk/masters-cookbook.json Your input should look like this, then click on the transact button. Minting Master's CookBook

Our Master wallet now contains a new NFT from the cookbook collection. Token Ids are assigned sequentially on the ready to use implementations, so we have a token with ID 1 being the master's cookbook.

Recipes creation - Adding assets to the collection

During his stay Master studied a lot and after getting the inspiration he gave life to 3 raw recipes.

You can use these 3 IPFS URIs for the metadata:

  • ipfs://QmQSoP7iT9C7PdNPvoxhKSvXq3Bkpxnz9AC6N7GCoJDNVt/1-carbonara.json
  • ipfs://QmQSoP7iT9C7PdNPvoxhKSvXq3Bkpxnz9AC6N7GCoJDNVt/2-cesar-salad.json
  • ipfs://QmQSoP7iT9C7PdNPvoxhKSvXq3Bkpxnz9AC6N7GCoJDNVt/3-grilled-salmon.json

While connected to the Master's account, go under deployed contracts and search for the addAssetEntry method. Expand it and for each of the 3 given assets, set it and hit transact.

Your input should look like this: Master adds assets to the collection

The collection now contains 3 assets, but they are not bound to any token yet. Asset Ids are assigned sequentially on the ready to use implementations, so we have assets with IDs 1, 2 and 3.

Recipes creation - Adding assets to a token

Now Master will add the 3 recipes (assets) to his cookbook.

While connected to the Master's account, go under deployed contracts and search for the addAssetToToken method. Expand it and for each of the 3 given assets, set it and hit transact. Remember we have asset ids from 1 to 3 and master's cookbook has token id 1.

Your input should look like this: Master adds assets to his cookbok

In general, Master would need to accept each of those assets, but our implementation has an autoaccept mechanism that will accept the asset if the owner of the token is the same user adding the token. So we can skip the accept step, the token now has 3 assets bound to it.

Managing Contributors

Alice was eager to create her own cookbook, yet she understood that crafting recognizable recipes was a privilege not afforded to everyone—it was an exclusive endeavor. Therefore, she approached Master to request permission to contribute to this significant project, and happily, he agreed.

Our ready to use Pre-Mint implementations, allow for the owner or a contributor to mint tokens, add new assets and add assets to tokens. So we will add Alice as a contributor to the collection. We need to do this as Master account, since only the owner of the collection has permissions to add or remove contributors.

While connected to the Master's account, go under deployed contracts and search for the manageContributor method. Expand it, fill the inputs and hit transact.

  • contributor: Alice's address
  • grantRole: true
  • tokenURI: ipfs://QmWcoQ7MvDRVCBZ2Xii3TtNYThdoibztG1gkutDHyS6KQk/masters-cookbook.json

Your input should look like this: Adding Alice as contributor

Alice Creates her cookbook - Minting a new token and adding assets to it

Now we will interact using Alice's account. She will create her own cookbook and add some recipes to it.

You can use these 2 IPFS URIs for the metadata:

  • ipfs://QmQSoP7iT9C7PdNPvoxhKSvXq3Bkpxnz9AC6N7GCoJDNVt/4-stir-fry.json
  • ipfs://QmQSoP7iT9C7PdNPvoxhKSvXq3Bkpxnz9AC6N7GCoJDNVt/5-chocolate-cake.json

Change to Alices's account in your wallet and repeat the steps we did with Master.

  1. Mint.
  • to: Alices's address
  • numToMint: 1
  • tokenURI: ipfs://QmWcoQ7MvDRVCBZ2Xii3TtNYThdoibztG1gkutDHyS6KQk/alices-cookbook.json Minting Alices's CookBook
  1. Add assets to the collection (they will have ids 4 and 5) Alice adds assets to collection
  2. Add assets to the token (her cookbook, token id 2) Alice adds assets to her cookbook

Collaboration - Accepting assets proposed by others

During his travel, Master created a recipe dedicated to his student and he decided to send it to Alice, to add it to her cookbook. Alice accepted the recipe gifted from her master...

Change to Master's account in your wallet and then:

  1. Add asset entry, metadata URI: ipfs://QmQSoP7iT9C7PdNPvoxhKSvXq3Bkpxnz9AC6N7GCoJDNVt/6-chicken-tikka.json. Master adds new asset
  2. Add the asset to Alice's cookbook (The asset has Id 6, Alice's cookbook has Id 2). Master adds asset to Alice's cookbok
  3. Change to Alice's account and accept it. It is at index 0 since there are no more pending assets. Alice accepts the asset

Alice improves recipe - Asset replacement

Alice felt that the recipe was missing something. After a long search and many attempts she found the right missing ingredient. So Alice fixed the recipe and she replaced the old one with this new, improved one.

The asset is auto accepted since the user (Alice) adding it, owns the token.

Using to Alices's account in your:

  1. Add asset entry, metadata URI: ipfs://QmSMs4nsW5LMKHbE4bqjCDQbwfSs6FKFPzkJWXFYtvuvjh. Alice adds new asset
  2. Add the asset to Alice's cookbook (The new asset has Id 7, the old one has Id 6, Alice's cookbook has Id 2). Alice adds asset to her cookbok, replacing the old one
💡

It's important to note that the earlier asset (with Id 6), is still in the collection, but it is not bound to any token. The owner or a contributor could reuse it into any token in the future.

Master and Alice collaboration - Proposing assets to a token

After this fix, Alice's career took flight and Master, proud of his student, proposed to create 2 recipes as a collaboration to add her cookbook. The last recipe was so delicious that Master added it to his cookbook as well!

You can use these 2 IPFS URIs for the metadata:

  • ipfs://QmQSoP7iT9C7PdNPvoxhKSvXq3Bkpxnz9AC6N7GCoJDNVt/8-buddha-bowl.json
  • ipfs://QmQSoP7iT9C7PdNPvoxhKSvXq3Bkpxnz9AC6N7GCoJDNVt/9-shrimp-scamp-pasta.json

Change to Master's account in your wallet and then:

  1. Add both assets to the collection (they will have Ids 8 and 9).
  2. Add both assets to the token (Alice's cookbook, token Id 2).
  3. Add the LAST asset to Master's cookbook (token Id 1, asset Id 9).
  4. Change to Alice's account and accept them. Initially asset Id 8 will be at index 0, after accepting it now asset Id 9 will also have index 0.

Master retires - Token burning with related assets

When the collaboration ended, Master decided to retire. He was an old man and he was also tired of travelling the world. This final decision resulted in him burning his cookbook. His only wish was to leave a nice memory and a veil of mystery of his cooking prowess.

Fortunately Master's recipes will be available for the next generations, but without the permission of Alice, his loyal student, none will be able to add the recipes into future cookbooks.

Change to Master's account in your wallet search for the burn method. Set token Id to 1 and transact.

We will omit this step so you can see the final result on Singular (opens in a new tab).

The result on both Remix or Hardhat is exactly the same.

User journey summary

In this tutorial we have seen how to interact with the Multi-Asset implementation in order to:

  1. Create a collection with tokens that support this standard
  2. Create and add assets (resources) to a token
  3. Accept a pending asset
  4. Replace an active asset with another one
  5. Manage contributors
  6. Burn a token with all its assets bound

Development notes

  • When you add a new entry to the collection you are creating a new asset (resource) that can be used by adding it to the collection tokens, but this asset is not unique so it can be added to multiple different tokens.
  • In this implementation, the assets cannot be unbound from a token. Once you add the asset with ID 5 to the token with ID 1 there is no way to remove it, so be careful when accepting new assets from unknown origins. On the other hand, an asset can be "deleted" by replacing it with a new one, this will keep the number of active assets the same.

Bugs, doubts and help

For clarifications, bug reporting or help please open a Github issue or write a message here: