metasv / meta-contract

MVC Development Kit including FT / NFT / Wallet modules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Meta-Contract SDK

This sdk helps you to interact with MVC meta contracts

Please read the documentation for more.

How to install

npm install meta-contract --save

How to use(FT)

Init

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,
})

Genesis

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

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

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 Balance

Query token's balance

let { balance, pendingBalance, utxoCount, decimal } = await ft.getBalanceDetail({
  codehash,
  genesis,
  address: Alice.address,
})

How to use(NFT)

Init

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,
})

Genesis

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',
})

Issue

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

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

Sell #1 NFT

let { sellTx, tx } = await nft.sell({
  codehash,
  genesis,
  sellerWif: Alice.wif,
  tokenIndex: '1',
  satoshisPrice: 2000,
})

Cancel Sell

Cancel Sell #1 NFT

let { unlockCheckTx, tx } = await nft.cancelSell({
  codehash,
  genesis,
  tokenIndex: '1',
  sellerWif: Alice.wif,
})

Buy

Buy #1 NFT

let { unlockCheckTx, tx } = await nft.buy({
  codehash,
  genesis,
  tokenIndex: '1',
  buyerWif: Bob.wif,
})

Example

Go to examples

About

MVC Development Kit including FT / NFT / Wallet modules

License:MIT License


Languages

Language:TypeScript 98.3%Language:JavaScript 1.7%