Non-fungible Token

A non-fungible token(NFT) is a special type of cryptographic token which represents something unique; non-fungible token are thus not mutually interchangeable by their individual specification. This is in contrast to cryptocurrencies like Zcash, and many network or utility tokens that are fungible in nature.


General Workflow

_images/NFT.jpg

First, a non-fungible token must be created. It can be created by any wallet, but it have to be authorize by undergo a KYC process for further use.

Authorization might get rejected

Creating Instances

Create non fungible token required approval from authorities

NonFungibleToken . create ( nonFungibleTokenProperties, signerOrProvider )   => Promise<NonFungibleToken>

Creates a new instance reference from signerOrProvider and send non fungible token creation transaction to network and returns a Promise that resolves to a NonFungibleToken instance.

The valid non-fungible token properties are:

  • name : string (name of the token)
  • symbol : string (symbol for the token)
  • fee : int (application fee)
  • properties : string (properties of the token)
  • metadata : string (remarks)

Note

name and symbol must be unique,
metadata can be change after the token is created, but properties can’t
Create Non-fungible Token
let provider = new mxw.Wallet(0x00000000000000000000000000000000000000000000000070726f7669646572);
let nonFungibleTokenProperties: NonFungibleTokenProperties;
nonFungibleTokenProperties = {
    name: "MY " + "symbol",
    symbol: "symbol",
    fee: {
        to: "address",
        value: bigNumberify("1")
    },
    metadata: ["Wallet able to manage their own metadata"],
    properties:["Decentralised identifier"]
};

var nonFungibleToken = new NonFungibleToken("symbol", provider);
nonFungibleToken.create(nonFungibleTokenProperties, provider).then((token) => {
    console.log(JSON.stringify(token));
});
NonFungibleToken . fromSymbol ( symbol, signerOrProvider )   => Promise<NonFungibleToken>
Query non-fungible token by symbol from network and returns a Promise that resolves to a NonFungibleToken instance.
Check on token state
    mxw.nonFungibleToken.NonFungibleToken.fromSymbol("symbol","issuer address").then((token)=>{
        console.log(JSON.stringify(token));
    });

Prototype

prototype . state   => NFTokenState

(Read Only)
The valid token state are:
  • flagsuint (number)
  • namestring (the unique token name)
  • symbolstring (the unique token symbol)
  • ownersting (address of owner of the token)
  • newOwnerstring (address of receiver of token)
  • metadatastring (metadata / remarks of token)
  • mintLimitBigNumber (maximum mint limit of token)
  • transferLimitBigNumber (maximum limit of the token can be transfer)
  • endorserListstring[] list of endorser
  • totalSupplyBigNumber (total item had been minted by the token)

Note

All token must be authorities, before it can use to mint item or transfer ownership. All token state must be assigned.

authorities token
    let provider = new mxw.Wallet(0x00000000000000000000000000000000000000000000000070726f7669646572);
    let issuer = new mxw.Wallet(0x0000000000000000000000000000000000000000000000000000697373756572);
    let middleware = new mxw.Wallet(0x000000000000000000000000000000000000000000006d6964646c6577617265);

    let tokenState = {
    tokenFees: [
                { action: NonFungibleTokenActions.transfer, feeName: "default" },
                { action: NonFungibleTokenActions.transferOwnership, feeName: "default" },
                { action: NonFungibleTokenActions.acceptOwnership, feeName: "default" }
                ],
    endorserList: [],
    mintLimit: 1,
    transferLimit: 1,
    burnable: false,
    pub: false
    };

    token.NonFungibleToken.approveNonFungibleToken("symbol",provider, tokenState).then((transaction) => {
        token.NonFungibleToken.signNonFungibleTokenStatusTransaction(transaction, issuer).then((transaction) => {
            token.NonFungibleToken.sendNonFungibleTokenStatusTransaction(transaction, middleware).then((receipt) => {
                console.log("approve"+receipt);
            });
        });
    });
prototype . transferOwnership ( AddressOrName )   => Promise<TransactionReceipt>
Sends the transfer non-fungible token to another person and returns a Promise that resolves to a Transaction Receipt.
transfer item ownership
    let provider = new mxw.Wallet(0x00000000000000000000000000000000000000000000000070726f7669646572);
    let privateKey = "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
    let wallet = new mxw.Wallet(privateKey, provider);

    var nonFungibleToken = new NonFungibleToken(symbol, provider);
    nonFungibleToken.transfer(wallet.address).then((receipt) => {
        console.log(JSON.stringify(receipt));
    })
prototype . mint ( AddressOrName, NonFungibleTokenItem)   => Promise<TransactionReceipt>

Sends the mint non-fungible token transaction to the network and returns a Promise that resolves to a Transaction Receipt.

The AddressOrName can be set to recipient alias or wallet address.

mint a non-fungible token item
    let issuer : mxw.Wallet;
    let item = {
        symbol: "symbol",
        itemID: "itemId",
        properties: "prop1",
        metadata: "str1"
    } ;

    var minterNFT = new NonFungibleToken(symbol, issuer);

    minterNFT.mint(issuer.address, item).then((receipt) => {
        console.log(JSON.stringify(receipt));
    });

Note

symbol of the minted item must be the same as the token symbol

prototype . updateMetadata(string metadata)   => Promise<TransactionReceipt>
Update the metadata of non-fungible token item to the network and returns a Promise
update metadata of a non-fungible token
let provider = new mxw.Wallet(0x00000000000000000000000000000000000000000000000070726f7669646572);
let nonFungibleTokenProperties: NonFungibleTokenProperties;
nonFungibleTokenProperties = {
    name: "MY " + symbol,
    symbol: symbol,
    fee: {
        to: nodeProvider.nonFungibleToken.feeCollector,
        value: bigNumberify("1")
    },
    metadata: ["Wallet able to manage their own metadata"],
    properties:["Decentralised identifier"]
};

let nftInstance = new NonFungibleTokenItem(nonFungibleTokenProperties,provider);

//overwrite the token metadata with string "overwrite"
nftInstance.updateMetadata("overwite").then((receipt) => {
        console.log(JSON.stringify(receipt));
});

//adding new info into the token metadata
let nftItemStatus = nftInstance.getState();
nftInstance.updateMetadata(nftItemStatus.metadata + "overwite").then((receipt) => {
        console.log(JSON.stringify(receipt));
});

Additional Action

Freeze and unfreeze item

freeze item
    let provider = new mxw.Wallet(0x00000000000000000000000000000000000000000000000070726f7669646572);
    let issuer = new mxw.Wallet(0x0000000000000000000000000000000000000000000000000000697373756572);
    let middleware = new mxw.Wallet(0x000000000000000000000000000000000000000000006d6964646c6577617265);

    token.NonFungibleToken.freezeNonFungibleTokenItem("symbol","itemID",provider).then((transaction) => {
        token.NonFungibleToken.signNonFungibleTokenItemStatusTransaction(transaction, issuer).then((transaction) => {
            token.NonFungibleToken.sendNonFungibleTokenItemStatusTransaction(transaction, middleware).then((receipt) => {
                console.log(JSON.stringify(receipt));
            });
        });
    });
unfreeze item
    let provider = new mxw.Wallet(0x00000000000000000000000000000000000000000000000070726f7669646572);
    let issuer = new mxw.Wallet(0x0000000000000000000000000000000000000000000000000000697373756572);
    let middleware = new mxw.Wallet(0x000000000000000000000000000000000000000000006d6964646c6577617265);

    token.NonFungibleToken.unfreezeNonFungibleTokenItem("symbol","itemID",provider).then((transaction) => {
        token.NonFungibleToken.signNonFungibleTokenItemStatusTransaction(transaction, issuer).then((transaction) => {
            token.NonFungibleToken.sendNonFungibleTokenItemStatusTransaction(transaction, middleware).then((receipt) => {
                console.log(JSON.stringify(receipt));
            });
        });
    });

Item

Creating an item instance, three components must be included(symbol, itemId and address of).

prototype. getState()   => NFTokenState

Returns to the state of Non-fungible Token Item status

(Read Only)
The valid token state are:
  • symbol – symbol of the non-fungible token item
  • itemID – ID of the non-fungible token item
  • properties – properties of the non- fungible token item
  • metadata – metadata of the non-fungible token item
Get item status
    nftInstance.getState().then((result)=>{
        console.log(JSON.stringify(result));
    });
NonFungibleTokenItem . fromSymbol ( symbol,itemID, signerOrProvider )   => Promise<NonFungibleToken>
Query non-fungible token by symbol from network and returns a Promise that resolves to a NonFungibleToken instance.
Check on item state
    mxw.nonFungibleToken.NonFungibleToken.fromSymbol("symbol","itemID","issuer address").then((token)=>{
        console.log(JSON.stringify(token))
    });
Get the state of token that minted this item
    mxw.nonFungibleToken.NonFungibleToken.fromSymbol("symbol","itemID","issuer address").then((token)=>{
        console.log(JSON.stringify(token))
        var mintedNFTItem = nftItem;
        console.log(mintedNFTItem.parent.state);
    });
prototype . burn ()   => Promise<TransactionReceipt>

Sends the burn non-fungible token transaction to the network and returns a Promise that resolves to a Transaction Receipt. To burn item, the token burn flag must be true.

The value is the number of non-fungible token (as a BigNumber) that to be burned. Be aware of the number of decimals applied for the token.

burn a non-fungible token item
    let nftInstance = new NonFungibleTokenItem(symbol, itemID, address);
    nftInstance.burn().then((receipt) => {
            console.log(receipt);
    });
prototype . endorse( )   => Promise<TransactionReceipt>
Perform endorsement by endorser
endorse a non-fungible token item
let nftInstance = new NonFungibleTokenItem("symbol", "itemID", "address");
nftInstance.endorse().then((receipt) => {
        console.log(receipt);
});
prototype . updateItemMetadata(metadata)   => Promise<TransactionReceipt>
Update the metadata of non-fungible token item to the network and returns a Promise
update metadata of a non-fungible token item
let nftInstance = new NonFungibleTokenItem("symbol", "itemID", "address");

//overwrite the item metadata with string "overwrite"
nftInstance.updateItemMetadata("overwite").then((receipt) => {
        console.log(receipt);
});

//adding new info into the item metadata
let nftItemStatus = nftInstance.getState(0);
nftInstance.updateItemMetadata(nftItemStatus.metadata + "overwite").then((receipt) => {
        console.log(receipt);
});