0.4.10 • Published 7 months ago

meta-contract v0.4.10

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

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

import { FtManager, API_TARGET } from 'meta-contract'

const ft = new FtManager({
  network: 'testnet',
  apiTarget: API_TARGET.MVC,
  purse: '', //the wif of a mvc address to offer transaction fees
  feeb: 0.5,
  apiHost,
})

Genesis

Define a token with name,symbol,decimal number. You should save the returned values.(genesis、codehash、sensibleId)

let { txHex, txid, tx, genesis, codehash, sensibleId } = await ft.genesis({
  version: 2,
  tokenName: 'COFFEE COIN',
  tokenSymbol: 'CC',
  decimalNum: 3,
  genesisWif: CoffeeShop.wif,
})

Mint

Mint 1000000000000 tokens

let { txid, txHex, tx } = await ft.mint({
  version: 2,
  sensibleId: sensibleId,
  genesisWif: CoffeeShop.wif,
  receiverAddress: CoffeeShop.address,
  tokenAmount: '1000000000000',
  allowIncreaseMints: false, //if true then you can mint again
})

Transfer

Transfer from CoffeShop to Alice and Bob

let { txid } = await ft.transfer({
  codehash: codehash,
  genesis: genesis,
  receivers: [
    {
      address: Alice.address,
      amount: '5000000',
    },
    {
      address: Bob.address,
      amount: '5000000',
    },
  ],
  senderWif: CoffeeShop.wif,
  ftUtxos: ParamFtUtxo[],
  ftChangeAddress: string | mvc.Address,

  utxos: ParamUtxo[],
  changeAddress: string | mvc.Address

})

Query Balance

Query token's balance

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

How to use(NFT)

Init

import { API_NET, API_TARGET, mvc, NftManager } from 'meta-contract'

// Generate new seed , need to memorize this mnemonic or use your own
// let mnemonic = mvc.Mnemonic.fromString(cute siren parrot merit swamp plate federal buddy sing tourist family tragic)
let mnemonic = mvc.Mnemonic.fromRandom()
console.log(mnemonic.toString())
let hdPrivateKey = mnemonic.toHDPrivateKey('', 'testnet').deriveChild("m/44'/0'/0'")
console.log(hdPrivateKey.publicKey.toAddress('testnet').toString())
console.log(mnemonic.toHDPrivateKey('', 'testnet').deriveChild("m/44'/0'/0'").privateKey.toString())
// use this private key to sign txs later
const privKey = mnemonic.toHDPrivateKey('', 'testnet').deriveChild("m/44'/0'/0'").privateKey.toString()
const nftManager = new NftManager({ apiTarget: API_TARGET.MVC, network: API_NET.TEST, purse: privKey })
// todo remove authorize in the future
nftManager.api.authorize({ authorization: 'METASV_KEY' })

Genesis

Define the NFT with totalSupply You should save the returned values.(genesis、codehash、sensibleId)

const result = await nftManager.genesis({ totalSupply: '10', version: 2 })
console.log(result)

Mint

Mint a NFT to CoffeeShop's address metaTxId is created by metaid which stands for NFT State

// todo generate metaId tx before mint
const mintResult = await nftManager.mint({
  version: 2,
  metaTxId: '0000000000000000000000000000000000000000000000000000000000000000',
  sensibleId: result.sensibleID,
  metaOutputIndex: 0,
})
console.log(mintResult)

Transfer

Transfer #1 NFT from CoffeShop to Alice

const result = await nftManager.transfer({
  codehash: '48d6118692b459fabfc2910105f38dda0645fb57',
  genesis: '4920af2eb18493255e662b07d1d80610de7cb2e3',
  receiverAddress: 'mymqKrpZjY31ABhPXfXjfVcUd78L1LCHEv',
  senderWif: privKey,
  tokenIndex: '1',
})
console.log(result)

Sell

Sell #1 NFT

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

Cancel Sell

Cancel Sell #1 NFT

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

  sellerWif: Alice.wif,
})

Buy

Buy #1 NFT

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

Example

Go to examples

0.4.9

7 months ago

0.4.8

7 months ago

0.4.10

7 months ago

0.4.7

7 months ago

0.4.5

9 months ago

0.4.6

9 months ago

0.4.4

1 year ago

0.4.3

1 year ago

0.4.1

1 year ago

0.4.2

1 year ago

0.3.42

1 year ago

0.4.0

1 year ago

0.3.41

2 years ago

0.3.39

2 years ago

0.3.38

2 years ago

0.3.40

2 years ago

0.3.31

2 years ago

0.3.30

2 years ago

0.3.35

2 years ago

0.3.34

2 years ago

0.3.33

2 years ago

0.3.32

2 years ago

0.3.29

2 years ago

0.3.28

2 years ago

0.3.27

2 years ago

0.3.26

2 years ago

0.3.20

2 years ago

0.1.46

2 years ago

0.1.47

2 years ago

0.1.48

2 years ago

0.3.25

2 years ago

0.3.24

2 years ago

0.3.23

2 years ago

0.3.22

2 years ago

0.3.21

2 years ago

0.3.0

2 years ago

0.3.18

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.9

2 years ago

0.3.17

2 years ago

0.3.16

2 years ago

0.3.15

2 years ago

0.3.14

2 years ago

0.3.13

2 years ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.10

2 years ago

0.2.0

2 years ago

0.1.10

3 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.1.14

3 years ago

0.1.15

3 years ago

0.1.41

3 years ago

0.1.42

2 years ago

0.1.43

2 years ago

0.1.44

2 years ago

0.1.45

2 years ago

0.1.40

3 years ago

0.1.0

3 years ago

0.1.2

3 years ago

0.1.38

3 years ago

0.1.8

3 years ago

0.1.39

3 years ago

0.1.7

3 years ago

0.1.9

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.30

3 years ago

0.1.31

3 years ago

0.1.32

3 years ago

0.1.33

3 years ago

0.1.34

3 years ago

0.1.35

3 years ago

0.1.36

3 years ago

0.1.27

3 years ago

0.1.28

3 years ago

0.1.29

3 years ago

0.1.20

3 years ago

0.1.21

3 years ago

0.1.22

3 years ago

0.1.23

3 years ago

0.1.24

3 years ago

0.1.25

3 years ago

0.1.26

3 years ago

0.1.16

3 years ago

0.1.17

3 years ago

0.1.18

3 years ago

0.1.19

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago