Fungible Token

Creating Instances

Creating fungible token requires approval from authorities.

FungibleToken . create ( properties, signerOrProvider )   => Promise<FungibleToken>

Creates a new instance reference from signerOrProvider, then sends fungible token creation transaction to the network and returns a Promise that resolves to a FungibleToken instance.

The valid fungible token properties are:

  • name: string name for the token
  • symbol: string symbol for the token
  • decimals: ref:*BigNumber* <bignumber> the number of decimals for balance
  • fixedSupply: bool the supply mechanisms type (true: fixed, false: dynamic)
  • maxSupply: ref:*BigNumber* <bignumber> the maximum supply, set to 0 for unlimited supply (only applicable to dynamic supply type)
  • fee: int application fee
  • owner: the owner of the token (default to wallet creator)
  • metadata: string remarks (optional)

Note

name and symbol should be unique.

create fungible token
let wallet = new mxw.Wallet(0x00000000000000000000000000000000000000000000000070726f7669646572, networkProvider);
let fungibleTokenProperties = {
    name: "MY " + "symbol",
    symbol: "symbol",
    decimals: 18,
    fixedSupply: true,
    maxSupply: bigNumberify("100000000000000000000000000"),
    fee: {
        to: "address",
        value: bigNumberify("1")
    },
    metadata: ["Fungible Token's metadata is able to modify"]
};

token.FungibleToken.create(FungibleTokenProperties, wallet).then((token) => {
    console.log(JSON.stringify(token))
});
FungibleToken . fromSymbol ( symbol, signerOrProvider )   => Promise<FungibleToken>
Queries fungible token by symbol from network and returns a Promise that resolves to a FungibleToken instance.
check token state
    mxw.token.FungibleToken.fromSymbol("symbol", wallet).then((token)=>{
        console.log(JSON.stringify(token));
    });

Prototype

prototype . state   => TokenState

(Read-only)
The valid token states are:
  • type — token type (fungible or non-fungible)
  • name — unique token name
  • symbol — unique token symbol
  • decimals — number of decimals for balance
  • fixedSupply — supply mechanism types (true: fixed, false: dynamic)
  • totalSupply — total current supply for the token
  • maxSupply — maximum supply for the token
  • approved — approval status
  • frozen — frozen status
  • owner — token owner’s address
  • metadata — optional
  • burnable — whether the token balance can be burned, this will be always true for token with dynamic supply
authorize token action
    let provider = new mxw.Wallet(0x00000000000000000000000000000000000000000000000070726f7669646572, networkProvider);
    let issuer = new mxw.Wallet(0x0000000000000000000000000000000000000000000000000000697373756572, networkProvider);
    let middleware = new mxw.Wallet(0x000000000000000000000000000000000000000000006d6964646c6577617265, networkProvider);

    let tokenState = {
    tokenFees: [
                { action: FungibleTokenActions.transfer, feeName: "default" },
                { action: FungibleTokenActions.transferOwnership, feeName: "default" },
                { action: FungibleTokenActions.acceptOwnership, feeName: "default" }
                ],
    burnable: false,
    };

    token.FungibleToken.approveFungibleToken("symbol",provider, tokenState).then((transaction) => {
        token.FungibleToken.signFungibleTokenStatusTransaction(transaction, issuer).then((transaction) => {
            token.FungibleToken.sendFungibleTokenStatusTransaction(transaction, middleware).then((receipt) => {
                console.log("approve"+receipt);
            });
        });
    });
prototype . getBalance ( )   => Promise<BigNumber>
Returns a Promise that resolves to the fungible token balance (as a BigNumber) of the wallet. Be aware of the number of decimals applied to the token. The balance can be converted to a human-readable format by formatUnits, versa parseUnits.
prototype . transferOwnership ( AddressOrName )   => Promise<TransactionReceipt>
Transfer the fungible token ownership from token owner’s wallet to another wallet and returns a Promise that resolves to a Transaction Receipt.
prototype . acceptOwnership ()   => Promise<TransactionReceipt>
Accept the fungible token ownership which transfer from another wallet and returns a Promise that resolves to a Transaction Receipt.
transfer and accept token ownership
    let transfereePrivateKey = "0x0123abcdefabcdef0123456789abcdef0123456789abcdef0123456789abcdef";
    let transfereeWallet = new mxw.Wallet(transfereePrivateKey, networkProvider);
    let transferorPrivateKey = "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
    let transferorWallet = new mxw.Wallet(transferorPrivateKey, networkProvider);

    // transferor transfering token ownership
    token.FungibleToken.fromSymbol(tokenSymbol, transferorWallet).then((token) =>{
        token.transferOwnership(transfereeWallet.address).then((receipt) => {
            console.log(JSON.stringify(receipt));
        })
    })

    // after verified the wallet owner done transfering the token ownership
    // then this action must get approval from authorities

    // transferee accepting token ownership
    token.FungibleToken.fromSymbol(tokenSymbol, transfereeWallet).then((token)=>{
        token.acceptOwnership().then((receipt) => {
            console.log(JSON.stringify(receipt));
        })
    })


    /* tokenSymbol is the symbol from a token, which already been created and approved by authorities */
prototype . transfer ( AddressOrName, value )   => Promise<TransactionReceipt>

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

The AddressOrName can be set to recipient’s alias or wallet address. The value is the number of fungible token (as a BigNumber) that is being transferred to recipient. Be aware of the number of decimals applied to the token.

prototype . mint ( AddressOrName, value )   => Promise<TransactionReceipt>

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

The AddressOrName can be set to recipient’s alias or wallet address. The value is the number of fungible token (as a BigNumber) that is being minedted to recipient. Be aware of the number of decimals applied to the token.

Note

Only fungible token owner is allowed to sign mint transaction.

prototype . burn ( value )   => Promise<TransactionReceipt>

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

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

burn a fungible token
let ftInstance = new FungibleTokenItem(symbol, itemID, wallet);
    ftInstance.burn().then((receipt) => {
            console.log(receipt);
    });
prototype . freeze ( AddressOrName )   => Promise<TransactionReceipt>

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

The AddressOrName can be set to target token holder’s alias or wallet address of which is to be frozen.

Note

Only fungible token middleware is allowed to sign freeze transaction.

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

    mxw.token.FungibleToken.freezeFungibleToken("symbol","itemID", provider).then((transaction) => {
        mxw.token.FungibleToken.signFungibleTokenStatusTransaction(transaction, issuer).then((transaction) => {
            mxw.token.FungibleToken.sendFungibleTokenStatusTransaction(transaction, middleware).then((receipt) => {
                console.log(JSON.stringify(receipt));
            });
        });
    });
prototype . unfreeze ( AddressOrName )   => Promise<TransactionReceipt>

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

The AddressOrName can be set to target token holder’s alias or wallet address of which is to be unfrozen.

Note

Only fungible token middleware is allowed to sign unfreeze transaction.

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

    mxw.token.FungibleToken.unfreezeFungibleToken("symbol","itemID", provider).then((transaction) => {
        mxw.token.FungibleToken.signFungibleTokenStatusTransaction(transaction, issuer).then((transaction) => {
            mxw.token.FungibleToken.sendFungibleTokenStatusTransaction(transaction, middleware).then((receipt) => {
                console.log(JSON.stringify(receipt));
            });
        });
    });