This sdk helps you to interact with MVC meta contracts
Please read the documentation for more.
npm install meta-contract --save
const { FT } = require('meta-contract')
const { signers, signerSelecteds } = await FT.selectSigners()
const ft = new FT({
network: 'testnet', //mainnet or testnet
purse: '', //the wif of a mvc address to offer transaction fees
feeb: 0.5,
signers,
signerSelecteds,
})
Define a token with name,symbol,decimal number. You should save the returned values.(genesis、codehash、sensibleId)
let { txid, genesis, codehash, sensibleId } = await ft.genesis({
genesisWif: CoffeeShop.wif,
tokenName: 'COFFEE COIN',
tokenSymbol: 'CC',
decimalNum: 3,
})
Issue 1000000000000 tokens
let { txid } = await ft.issue({
genesis: genesis,
codehash: codehash,
sensibleId: sensibleId,
genesisWif: CoffeeShop.wif,
receiverAddress: CoffeeShop.address,
tokenAmount: '1000000000000',
allowIncreaseIssues: false, //if true then you can issue again
})
Transfer from CoffeShop to Alice and Bob
let { txid } = await ft.transfer({
senderWif: CoffeeShop.wif,
receivers: [
{
address: Alice.address,
amount: '5000000',
},
{
address: Bob.address,
amount: '5000000',
},
],
codehash: codehash,
genesis: genesis,
})
Query token's balance
let { balance, pendingBalance, utxoCount, decimal } = await ft.getBalanceDetail({
codehash,
genesis,
address: Alice.address,
})
const { NFT } = require('meta-contract')
const { signers, signerSelecteds } = await NFT.selectSigners()
const nft = new NFT({
network: 'testnet', //mainnet or testnet
purse: '', //the wif of a mvc address to offer transaction fees
feeb: 0.5,
signers,
signerSelecteds,
})
Define the NFT with totalSupply You should save the returned values.(genesis、codehash、sensibleId)
let { txid, genesis, codehash, sensibleId } = await nft.genesis({
genesisWif: CoffeeShop.wif,
totalSupply: '3',
})
Mint a NFT to CoffeeShop's address metaTxId is created by metaid which stands for NFT State
let { txid, tokenIndex } = await nft.issue({
genesis,
codehash,
sensibleId,
genesisWif: CoffeeShop.wif,
receiverAddress: CoffeeShop.address,
metaTxId: '8424d5efb0c11f574d7f045959bdc233c17804312c9ca1e196cebdae2b2646ea',
metaOutputIndex: 0,
})
Transfer #1 NFT from CoffeShop to Alice
let { txid } = await nft.transfer({
senderWif: CoffeeShop.wif,
receiverAddress: Alice.address,
codehash: codehash,
genesis: genesis,
tokenIndex: '1',
})
Sell #1 NFT
let { sellTx, tx } = await nft.sell({
codehash,
genesis,
sellerWif: Alice.wif,
tokenIndex: '1',
satoshisPrice: 2000,
})
Cancel Sell #1 NFT
let { unlockCheckTx, tx } = await nft.cancelSell({
codehash,
genesis,
tokenIndex: '1',
sellerWif: Alice.wif,
})
Buy #1 NFT
let { unlockCheckTx, tx } = await nft.buy({
codehash,
genesis,
tokenIndex: '1',
buyerWif: Bob.wif,
})