This sdk helps you to interact with sensible contracts
Please read the documentation for more.
npm install sensible-sdk --save
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,
//apiUrl: "Your sensible url"
});
ft.sensibleApi.authorize({
authorization:
"Your Api Key",
});
Since 2022-11-01, the request of Sensible Query needs to be authenticated If you don't want to use Sensible Query API, you can use your own service, which can be specified through apiurl.
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 { 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,
});
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,
});