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.
let wallet = new manifold.Wallet(0x00000000000000000000000000000000000000000000000070726f7669646572);
let fungibleTokenProperties = {
name: "MY " + "symbol",
symbol: "symbol",
decimals: 18,
fixedSupply: true,
maxSupply: bigNumberify("100000000000000000000000000"),
fee: {
to: "address",
value: bigNumberify("1")
},
metadata: ["Wallet is able to manage their own metadata"]
};
manifold.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.
manifold.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
- 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 . 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
valueis 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
valueis 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
valueis the number of fungible token (as a BigNumber) to be burned. Be aware of the number of decimals applied to the token.
let ftInstance = new NonFungibleTokenItem(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.
let provider = new manifold.Wallet(0x00000000000000000000000000000000000000000000000070726f7669646572);
let issuer = new manifold.Wallet(0x0000000000000000000000000000000000000000000000000000697373756572);
let middleware = new manifold.Wallet(0x000000000000000000000000000000000000000000006d6964646c6577617265);
manifold.token.FungibleToken.freezeFungibleToken("symbol","itemID", provider).then((transaction) => {
manifold.token.FungibleToken.signFungibleTokenStatusTransaction(transaction, issuer).then((transaction) => {
manifold.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.
let provider = new manifold.Wallet(0x00000000000000000000000000000000000000000000000070726f7669646572);
let issuer = new manifold.Wallet(0x0000000000000000000000000000000000000000000000000000697373756572);
let middleware = new manifold.Wallet(0x000000000000000000000000000000000000000000006d6964646c6577617265);
manifold.token.FungibleToken.unfreezeFungibleToken("symbol","itemID", provider).then((transaction) => {
manifold.token.FungibleToken.signFungibleTokenStatusTransaction(transaction, issuer).then((transaction) => {
manifold.token.FungibleToken.sendFungibleTokenStatusTransaction(transaction, middleware).then((receipt) => {
console.log(JSON.stringify(receipt));
});
});
});