7.4.1 • Published 2 years ago

@cyio/sensible-sdk v7.4.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Sensible-SDK

npm version

This sdk helps you to interact with sensible contracts

Please read the documentation for more.

How to install

npm install sensible-sdk --save

How to use(FT)

Init

const { SensibleFT } = require("sensible-sdk");

const { signers, signerSelecteds } = await SensibleFT.selectSigners();
const ft = new SensibleFT({
  network: "testnet", //mainnet or testnet
  purse: "", //the wif of a bsv 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 { SensibleNFT } = require("sensible-sdk");
const { signers, signerSelecteds } = await SensibleNFT.selectSigners();
const nft = new SensibleNFT({
  network: "testnet", //mainnet or testnet
  purse: "", //the wif of a bsv 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