πŸ‘ΊNFT

Non Fungible Tokens

NFT is not stored in the user's wallet, instead, each NFT exists in the NFT contract and is unique.

The role of the NFT contract is to keep accounts, that is, it is responsible for processing the creation, storage and transfer of NFT. This makes NFTs ideal for representing ownership of an asset, such as a piece of digital content or event tickets.

Transferring an NFT​

Transferring an NFT can happen in two scenarios: (1) you ask to transfer an NFT, and (2) an authorized account asks to transfer the NFT.

// code transferring nft_
mam call nft_transfer '
{"receiver_id": "", "token_id": ""}'
accountId --depositYocto 1

Track real-time events (such as money transfers) by implementing the NFT event standard. Events are simple to use because they are just login messages formatted in a standardized way. Since these records are on-chain data, this is public information.

Mint NFTs with the matmo SDKs

Mint NFT

This #SDK provides a directory.

This tutorial covers the simple-nft example.

Clone the matmo-core repository.

How Does it Work?​

Assume you want to attach an NFT to a call on the receiver contract. The workflow is as follows:

  1. You call nft_transfer_call in the NFT-contract passing: the receiver, a message, and the token-id of .

  2. The NFT contract transfers the NFT to the receiver.

  3. The NFT contract calls receiver.nft_on_transfer(sender, token-owner, token-id, msg).

  4. The NFT contract handles errors in the nft_resolve_transfer callback.

  5. The NFT contract returns true if it succeeded.

The following is the access code, buried when casting NFT

// code//
=== Addresses 
=== Alice: 0xeef95e86c160fa10a71675c6075f44f8f2c6125f57b4b589424f1fbee385f754 Bob: 0x4dcd7b180c123fdb989d10f71fba6c978bda268c2e3660c169bdb55f67aab776
=== Initial Coin Balances 
=== Alice: 100000000 Bob: 100000000
=== Creating Collection and Token
 === Alice's collection: {
 "description": "Alice's simple collection", 
"maximum": "18446744073709551615", 
"mutability_config": { "description": false, "maximum":
 false, "uri": false },
 "name": "Alice's", 
"supply": "1", 
"uri": "https://alice.com" } 
Alice's token balance: 1 Alice's 
token data: { "default_properties": { "map": { "data": [] } }, 
"description": "Alice's simple token", 
"largest_property_version": "0",
 "maximum": "18446744073709551615",
 "mutability_config": { "description": false, 
"maximum": false, "properties": false, "royalty": false, "uri": false },
 "name": "Alice's first token",
 "royalty": { "payee_address": "0xeef95e86c160fa10a71675c6075f44f8f2c6125f57b4b589424f1fbee385f754", 
"royalty_points_denominator": "0", "royalty_points_numerator": "0" }, 
"supply": "1", 
"uri": "https://matmos.dev/img/nyan.jpeg" }
=== Transferring the token to Bob 
=== Alice's token balance: 0 Bob's token balance: 1
=== Transferring the token back to Alice using MultiAgent === Alice's token balance: 1 Bob's token balance: 0
const client = new matmosClient(NODE_URL); 
const faucetClient = new FaucetClient(NODE_URL, FAUCET_URL);
//

The sender may first ask the receiver to acknowledge pending transfers off-chain.

This comes in the form of a multi-agent transaction request.

A multi-agent transaction contains multiple signatures, and each signature corresponds to an account on the chain.

The nft_on_transfer method​

From the workflow above it follows that the receiver we want to call needs to implement the nft_on_transfer method. When executed, such method will know:

  • Who is sending the NFT, since it is a parameter

  • Who is the current owner, since it is a parameter

  • Which NFT was transferred, since it is a parameter.

  • If there are any parameters encoded as a message

The nft_on_transfer must return true if the NFT has to be returned to the sender.

Last updated