SensibleFT
The SensibleFT object makes it easy to interact with Sensible Fungible Token contracts on the BitcoinSV blockchain.
new
new SensibleFT(options)
Parameters
options-Object:signers-string: signerssignerSelecteds-number[]: (Optional) the indexs of the signers which is decided to verifyfeeb-number: (Optional) the fee rate. default is 0.5network- API_NET: (Optional) mainnet/testnet default is mainnetpurse-string: (Optional) the private key to offer transacions fee. If not provided, bsv utoxs must be provided in genesis/issue/transfer.apiTarget- API_TARGET: (Optional) SENSIBLE/METASV, default is SENSIBLE.dustLimitFactor-number: (Optional) specify the output dust rate, default is 0.25 .If the value is equal to 0, the final dust will be at least 1.dustAmount-number: (Optional) specify the output dust.
Returns
Object: The SensibleFT object
Example
const SensibleFT = sensible.SensibleFT;
const { signers, signerSelecteds } = await SensibleFT.selectSigners();
const ft = new SensibleFT({
network: "mainnet", //mainnet or testnet
purse: "", //the wif of a bsv address to offer transaction fees
feeb: 0.5,
signers,
signerSelecteds,
})
= Properties =
sensibleApi
For sensibleApi see the SensibleApi reference documentation.
= Methods =
genesis
ft.genesis(options)
Creates a TokenGenesis Transaction for a new token.
Parameters
options-Object:tokenName-string: token name, limited to 20 bytestokenSymbol-string: the token symbol, limited to 10 bytesdecimalNum-number: the decimal number, range 0-255utxos- ParamUtxo[]: (Optional) specify bsv utxoschangeAddress-string|bsv.Address: (Optional) specify bsv changeAddressopreturnData-string[]|string|Buffer: (Optional) append an opReturn outputgenesisWif-string: the private key of the token genesisernoBroadcast-boolean: (Optional) whether not to broadcast the transaction, the default is false
Returns
Promise returns Object: The transaction object:
tx-bsv.Transaction: the transaction object.(With input data)txHex-string: raw hex of the transaction.txid-string: id of the transaction.genesis-string: genesis of the new token.codehash-string: codehash of the new token.sensibleId-string: sensibleId of the new token.
You should save the returned values.(genesis、codehash、sensibleId) Issuing the token need those values.
Example
const ft = new sensible.SensibleFT({});
const CoffeeShop = {
wif: "L1Ljq1wKir7oJsTzHRq437JdDkmY9v8exFwm2jzytq7EdzunS71Q",
address:"1FVyetCQrPdjNaG962bqYA5EL6q1JxNET3"
};
// use purse to offer the bsv fee
let { txid, genesis, codehash, sensibleId } = await ft.genesis({
genesisWif: CoffeeShop.wif,
tokenName: "COFFEE COIN",
tokenSymbol: "CC",
decimalNum: 3,
});
// or specify bsv utxos (wif must be provided)
let bsvUtxos = ft.sensibleApi.getUnspents(CoffeeShop.address);
bsvUtxos.forEach(v=>{
v.wif = CoffeeShop.wif;
})
let { txid, genesis, codehash, sensibleId } = await ft.genesis({
genesisWif: CoffeeShop.wif,
tokenName: "COFFEE COIN",
tokenSymbol: "CC",
decimalNum: 3,
utxos:bsvUtxos
});
issue
ft.issue(options)
Issue tokens.
Parameters
options-Object:genesis-string: the genesis of token.codehash-string: the codehash of token.sensibleId-string: the sensibleId of token.genesisWif-string: the private key of the token genesiserreceiverAddress-string: the token receiver addresstokenAmount-string: the token amount to issueallowIncreaseIssues-boolean: (Optional) if allow to increase issues. default is trueutxos- ParamUtxo[]: (Optional) specify bsv utxoschangeAddress-string: (Optional) specify bsv changeAddressopreturnData-string[]|string|Buffer: (Optional) append an opReturn outputnoBroadcast-boolean: (Optional) whether not to broadcast the transaction, the default is false
Returns
Object: The transaction object:
tx-bsv.Transaction: the transaction object.(With input data)txHex-string: raw hex of the transaction.txid-string: id of the transaction.
Example
const ft = new sensible.SensibleFT(...)
const {genesis,codehash,sensibleId} = ft.genesis(...);
const CoffeeShop = {
wif: "L1Ljq1wKir7oJsTzHRq437JdDkmY9v8exFwm2jzytq7EdzunS71Q",
address:"1FVyetCQrPdjNaG962bqYA5EL6q1JxNET3"
};
// use purse to offer the bsv fee
let { txid } = await ft.issue({
genesis: genesis,
codehash: codehash,
sensibleId: sensibleId,
genesisWif: CoffeeShop.wif,
receiverAddress: CoffeeShop.address,
tokenAmount: "1000000000000",
allowIncreaseIssues: false,
});
// or specify bsv utxos (wif must be provided)
let bsvUtxos = ft.sensibleApi.getUnspents(CoffeeShop.address);
bsvUtxos.forEach(v=>{
v.wif = CoffeeShop.wif;
})
let { txid } = await ft.issue({
genesis: genesis,
codehash: codehash,
sensibleId: sensibleId,
genesisWif: CoffeeShop.wif,
receiverAddress: CoffeeShop.address,
tokenAmount: "1000000000000",
allowIncreaseIssues: false,
utxos:bsvUtxos
});
transfer
ft.transfer(options)
Transfer tokens.
Parameters
options-Object:genesis-string: the genesis of token.codehash-string: the codehash of token.receivers- TokenReceiver[]: token receiverssenderWif-string: the private key of the token senderftUtxos- ParamFtUtxo[]: (Optional) specify token utxosftChangeAddress-string|bsv.Address: (Optional) specify ft changeAddressutxos- ParamUtxo[]: (Optional) specify bsv utxos which should be no more than 3changeAddress-string|bsv.Address: (Optional) specify bsv changeAddressmiddleChangeAddress-string|bsv.Address: (Optional) the middle bsv changeAddressmiddlePrivateKey-string|bsv.PrivateKey: (Optional) the private key of the middle changeAddressisMerge-boolean: (Optional) do not use this param. Please use function Merge.opreturnData-string[]|string|Buffer: (Optional) append an opReturn outputnoBroadcast-boolean: (Optional) whether not to broadcast the transaction, the default is false
The number of bsv utxo inputs must not be greater than 3, or the transaction will failed.
The best practice is to determine the number of utxos in the address and merge them in advance.
Returns
Object: The transaction object:
tx-bsv.Transaction: the transaction object.txHex-string: raw hex of the transaction.txid-string: id of the transaction.routeCheckTx-bsv.Transaction: the amount-check transaction object.routeCheckTxHex-string: raw hex of the amount-check transaction.
Example
const ft = new sensible.SensibleFT(...)
const {genesis,codehash,sensibleId} = ft.genesis(...);
const CoffeeShop = {
wif: "L1Ljq1wKir7oJsTzHRq437JdDkmY9v8exFwm2jzytq7EdzunS71Q",
address:"1FVyetCQrPdjNaG962bqYA5EL6q1JxNET3"
};
// use purse to offer the bsv fee
let { txid } = await ft.transfer({
senderWif: CoffeeShop.wif,
receivers: [
{
address: Alice.address,
amount: "5000000",
},
{
address: Bob.address,
amount: "5000000",
},
],
codehash: codehash,
genesis: genesis,
});
// or specify ft utxos and bsv utxos (wif must be provided)
let bsvUtxos = ft.sensibleApi.getUnspents(CoffeeShop.address);
bsvUtxos.forEach(v=>{
v.wif = CoffeeShop.wif;
})
let ftUtxos = ft.sensibleApi.getFungibleTokenUnspents(codehash,genesis,CoffeeShop.address,100);
ftUtxos.forEach(v=>{
v.wif = CoffeeShop.wif;
})
let { txid } = await ft.transfer({
senderWif: CoffeeShop.wif,
receivers: [
{
address: Alice.address,
amount: "5000000",
},
{
address: Bob.address,
amount: "5000000",
},
],
codehash: codehash,
genesis: genesis,
utxos: bsvUtxos
});
merge
ft.merge(options)
Merge tokens.
Why do I need to merge tokens? At present, the contract supports only 20 utxo transfers at the same time. When the utxo collection is too large, it needs to be merged.
It will take up to 20 utxos as input and merge them into one output and transfer to owner.
Parameters
options-Object:genesis-string: the genesis of token.codehash-string: the codehash of token.ownerWif-string: the private key of the token ownerutxos- ParamUtxo[]: (Optional) specify bsv utxoschangeAddress-string|bsv.Address: (Optional) specify bsv changeAddressopreturnData-string[]|string|Buffer: (Optional) append an opReturn outputnoBroadcast-boolean: (Optional) whether not to broadcast the transaction, the default is false
The number of bsv utxo inputs must not be greater than 3, or the transaction will failed.
The best practice is to determine the number of utxos in the address and merge them in advance.
Returns
Object: The transaction object:
tx-bsv.Transaction: the transaction object.(With input data)txHex-string: raw hex of the transaction.txid-string: id of the transaction.routeCheckTx-bsv.Transaction: the amount-check transaction object.(With input data)routeCheckTxHex-string: raw hex of the amount-check transaction.
Example
const ft = new sensible.SensibleFT({})
const CoffeeShop = {
wif: "L1Ljq1wKir7oJsTzHRq437JdDkmY9v8exFwm2jzytq7EdzunS71Q",
address:"1FVyetCQrPdjNaG962bqYA5EL6q1JxNET3"
};
let { txid } = await ft.merge({
ownerWif: CoffeeShop.wif,
codehash: codehash,
genesis: genesis,
});
unsignGenesis
ft.unsignGenesis(options)
Create an unsigned transaction for genesis
Parameters
options-Object:tokenName-string: token name, limited to 20 bytestokenSymbol-string: the token symbol, limited to 10 bytesdecimalNum-number: the decimal number, range 0-255utxos- ParamUtxo[]: (Optional) specify bsv utxoschangeAddress-string|bsv.Address: (Optional) specify bsv changeAddressopreturnData-string[]|string|Buffer: (Optional) append an opReturn outputgenesisPublicKey-string|bsv.PublicKey: the public key of the token genesiser
Returns
Promise returns Object:
tx-bsv.Transaction: unsigned transaction object.sigHashList- SigHashInfo[]: sighash info list
sigHashList contains all the input that needs to be signed.
The signature method can refer to signSigHashList
Example
const ft = new sensible.SensibleFT(...)
const {...,genesis,codehash,sensibleId} = ft.genesis(...);
const CoffeeShop = {
wif: "L1Ljq1wKir7oJsTzHRq437JdDkmY9v8exFwm2jzytq7EdzunS71Q",
address:"1FVyetCQrPdjNaG962bqYA5EL6q1JxNET3"
};
// use purse to offer the bsv fee
let { tx, sigHashList } = await ft.unsignGenesis({
tokenName: "CoffeeCoin",
tokenSymbol: "CC",
decimalNum: 8,
genesisPublicKey: CoffeeShop.publicKey,
});
//wallet sign the inputs
let sigList = signSigHashList(sigHashList);
//update tx's inputs
ft.sign(tx, sigHashList, sigList);
//broadcast
await ft.sensibleApi.broadcast(tx.serialize(true));
unsignIssue
ft.unsignIssue(options)
Create an unsigned transaction for issue
Parameters
options-Object:genesis-string: the genesis of token.codehash-string: the codehash of token.sensibleId-string: the sensibleId of token.genesisPublicKey-string|bsv.PublicKey: the private key of the token genesiserreceiverAddress-string: the token receiver addresstokenAmount-string: the token amount to issueallowIncreaseIssues-boolean: (Optional) if allow to increase issues. default is trueutxos- ParamUtxo[]: (Optional) specify bsv utxoschangeAddress-string: (Optional) specify bsv changeAddressopreturnData-string[]|string|Buffer: (Optional) append an opReturn output
Returns
Promise returns Object:
tx-bsv.Transaction: the transaction object.sigHashList- SigHashInfo[]: sighash info
sigHashList contains all the input that needs to be signed.
The signature method can refer to signSigHashList
Example
const ft = new sensible.SensibleFT(...)
const {...,genesis,codehash,sensibleId} = ft.genesis(...);
const CoffeeShop = {
wif: "L1Ljq1wKir7oJsTzHRq437JdDkmY9v8exFwm2jzytq7EdzunS71Q",
address:"1FVyetCQrPdjNaG962bqYA5EL6q1JxNET3",
publicKey:"",
};
// use purse to offer the bsv fee
let { txid ,sigHashList} = await ft.unsignIssue({
genesis: genesis,
codehash: codehash,
sensibleId: sensibleId,
genesisPublicKey: CoffeeShop.publicKey,
receiverAddress: CoffeeShop.address,
tokenAmount: "1000000000000",
allowIncreaseIssues: false,
});
let sigList = signSigHashList(sigHashList);
ft.sign(tx, sigHashList, sigList);
await sensibleApi.broadcast(tx.serialize(true));
unsignPreTransfer
ft.unsignPreTransfer(options)
Create unsigned transactions for transfer
The unsigned transfer token needs to be completed in two steps.
Parameters
options-Object: the options used for deployment.genesis-string: the genesis of token.codehash-string: the codehash of token.receivers- TokenReceiver[]: token receivers.[{address:’xxx’,amount:’1000’}]senderPublicKey-string|bsv.PublicKey: the private key of the token sender,can be wif or other formatftUtxos- ParamFtUtxo[]: (Optional) specify token utxosftChangeAddress-string|bsv.Address: (Optional) specify ft changeAddressutxos- ParamUtxo[]: (Optional) specify bsv utxoschangeAddress-string|bsv.Address: (Optional) specify bsv changeAddressmiddleChangeAddress-string|bsv.Address: (Optional) the middle bsv changeAddressmiddlePrivateKey-string|bsv.PrivateKey: (Optional) the private key of the middle changeAddressisMerge-boolean: (Optional) do not use this param. Please use function Merge.opreturnData-string[]|string|Buffer: (Optional) append an opReturn output
The number of bsv utxo inputs must not be greater than 3, or the transaction will failed.
The best practice is to determine the number of utxos in the address and merge them in advance.
Returns
Promise returns Object:
unsignTxRaw-string: raw hex of the transaction.routeCheckTx-bsv.Transaction: the amount-check transaction object.(With input data)routeCheckSigHashList- SigHashInfo[]: sighash info
routeCheckSigHashList contains all the input that needs to be signed.
The signature method can refer to signSigHashList
Notice! UnsignTxRaw is an incomplete transaction and not able to be signed before routeCheckTx is completed.
Example
const ft = new sensible.SensibleFT({})
const CoffeeShop = {
wif: "L1Ljq1wKir7oJsTzHRq437JdDkmY9v8exFwm2jzytq7EdzunS71Q",
address:"1FVyetCQrPdjNaG962bqYA5EL6q1JxNET3"
};
let {
routeCheckTx,
routeCheckSigHashList,
unsignTxRaw,
} = await ft.unsignPreTransfer({
codehash,
genesis,
senderPublicKey: CoffeeShop.publicKey,
receivers: [
{ address: Alice.address.toString(), amount: "100" },
{ address: Alice.address.toString(), amount: "100" },
{ address: Alice.address.toString(), amount: "100" },
{ address: Alice.address.toString(), amount: "100" },
]
});
ft.sign(
routeCheckTx,
routeCheckSigHashList,
signSigHashList(routeCheckSigHashList)
);
await ft.sensibleApi.broadcast(routeCheckTx.serialize(true));
let { tx, sigHashList } = await ft.unsignTransfer(
routeCheckTx,
unsignTxRaw
);
ft.sign(tx, sigHashList, signSigHashList(sigHashList));
await ft.sensibleApi.broadcast(tx.serialize(true));
unsignTransfer
ft.unsignTransfer(options)
This follows the previous unsignPreTransfer.
Parameters
options-Object: the options used for deployment.routeCheckTx-bsv.Transaction: the genesis of token.unsignTxRaw-string: the codehash of token.
Returns
Promise returns Object:
tx-bsv.Transaction: the transaction object.sigHashList- SigHashInfo[]: sighash info
The tx is still unsigned.
Example
See the example in unsignPreTransfer
unsignPreMerge
ft.unsignPreMerge(options)
Create unsigned transactions for merge
The unsigned merge token needs to be completed in two steps.
Parameters
options-Object:genesis-string: the genesis of token.codehash-string: the codehash of token.ownerPublicKey-string: the private key of the token ownerftUtxos- ParamFtUtxo[]: (Optional) specify token utxosftChangeAddress-string(Optional) specify ft changeAddressutxos- ParamUtxo[]: (Optional) specify bsv utxoschangeAddress-string|bsv.Address: (Optional) specify bsv changeAddressopreturnData-string[]|string|Buffer: (Optional) append an opReturn output
The number of bsv utxo inputs must not be greater than 3, or the transaction will failed.
The best practice is to determine the number of utxos in the address and merge them in advance.
Returns
Promise returns Object:
unsignTxRaw-string: raw hex of the transaction.routeCheckTx-bsv.Transaction: the amount-check transaction object.(With input data)routeCheckSigHashList- SigHashInfo[]: sighash info
routeCheckSigHashList contains all the input that needs to be signed.
The signature method can refer to signSigHashList
Example
//get genesis/codehash/sensibleId from genesis.
const {...,genesis,codehash,sensibleId} = ft.genesis(options);
const CoffeeShop = {
wif: "L1Ljq1wKir7oJsTzHRq437JdDkmY9v8exFwm2jzytq7EdzunS71Q",
address:"1FVyetCQrPdjNaG962bqYA5EL6q1JxNET3"
};
let {
routeCheckTx,
routeCheckSigHashList,
unsignTxRaw,
} = await ft.unsignPreMerge({
codehash,
genesis,
ownerPublicKey: CoffeeShop.publicKey,
utxos,
});
ft.sign(
routeCheckTx,
routeCheckSigHashList,
signSigHashList(routeCheckSigHashList)
);
await sensibleApi.broadcast(routeCheckTx.serialize(true));
let { tx, sigHashList } = await ft.unsignMerge(routeCheckTx, unsignTxRaw);
ft.sign(tx, sigHashList, signSigHashList(sigHashList));
await sensibleApi.broadcast(tx.serialize(true));
unsignMerge
ft.unsignMerge(options)
This follows the previous unsignPreMerge.
Parameters
options-Object: the options used for deployment.routeCheckTx-bsv.Transaction: the genesis of token.unsignTxRaw-string: the codehash of token.
Returns
Promise returns Object:
tx-bsv.Transaction: the transaction object.sigHashList- SigHashInfo[]: sighash info
Example
See the example in unsignPreTransfer
getGenesisEstimateFee
ft.getGenesisEstimateFee(options)
Estimate the cost of genesis
The cost mainly depends on the number of bsv utxo inputs.
Parameters
options-Object:opreturnData-string[]|string|Buffer: (Optional) append an opReturn outpututxoMaxCount-number: (Optional) Maximum number of BSV UTXOs supported, the default is 10.
Returns
Promise returns number: The fee amount estimated.
Example
let estimateFee = await ft.getGenesisEstimateFee({
utxoMaxCount: 1,
});
getIssueEstimateFee
ft.getIssueEstimateFee(options)
Estimate the cost of issue
Parameters
options-Object:sensibleId-string: the sensibleId of token.genesisPublicKey-string|bsv.PublicKey: the public key of token genesiser.opreturnData-string[]|string|Buffer: (Optional) append an opReturn outputallowIncreaseIssues-boolean: (Optional) if allow increase issues , the default is true.utxoMaxCount-number: (Optional) Maximum number of BSV UTXOs supported, the default is 10.
Returns
Promise returns number: The fee amount estimated.
Example
const ft = new sensible.SensibleFT(...);
const {...,genesis,codehash,sensibleId} = ft.genesis(options);
const CoffeeShop = {
address:"1FVyetCQrPdjNaG962bqYA5EL6q1JxNET3",
publicKey:"02fe9584308dcab1c934cd82329d099152115cb9acced8e4413380333bbcb7520d",
};
let estimateFee = await ft.getIssueEstimateFee({
sensibleId,
genesisPublicKey: CoffeeShop.publicKey,
allowIncreaseIssues: true,
});
getTransferEstimateFee
ft.getTransferEstimateFee(options)
Estimate the cost of transfer
Parameters
options-Object:genesis-string: the genesis of token.codehash-string: the codehash of token.receivers- TokenReceiver[]: token receivers.[{address:’xxx’,amount:’1000’}]senderWif-string: the private key of the token sender,can be wif or other formatsenderPrivateKey-string|bsv.PrivateKey: the private key of the token sender,can be wif or other formatsenderPublicKey-string|bsv.PublicKey: (Optional) senderWif and senderPublicKey must be providedftUtxos-ParamFtUtxo[]: (Optional) specify token utxosftChangeAddress-string|bsv.Adderss: (Optional) specify ft changeAddressisMerge-boolean: (Optional) do not use this param. Please use function Merge.opreturnData-string[]|string|Buffer: (Optional) append an opReturn outpututxoMaxCount-number: (Optional) Maximum number of BSV UTXOs supported, the default is 3.
The number of bsv utxo inputs must not be greater than 3, or the transaction will failed.
Returns
Promise returns number: The fee amount estimated.
Example
//get genesis/codehash from genesis.
const {...,genesis,codehash} = ft.genesis(options);
const CoffeeShop = {
address:"1FVyetCQrPdjNaG962bqYA5EL6q1JxNET3",
publicKey:"02fe9584308dcab1c934cd82329d099152115cb9acced8e4413380333bbcb7520d",
};
let estimateFee = await ft.getTransferEstimateFee({
codehash,
genesis,
senderPublicKey: CoffeeShop.publicKey,
receivers: [
{ address: Alice.address.toString(), amount: "100" },
{ address: Alice.address.toString(), amount: "100" },
{ address: Alice.address.toString(), amount: "100" },
{ address: Alice.address.toString(), amount: "100" },
],
utxoMaxCount: 3,
});
getMergeEstimateFee
ft.getMergeEstimateFee(options)
Estimate the cost of merge
Parameters
options-Object:genesis-string: the genesis of token.codehash-string: the codehash of token.ownerWif-string: the private key of the token sender,can be wif or other formatownerPublicKey-string|bsv.PublicKey: (Optional) senderWif and senderPublicKey must be providedftUtxos-ParamFtUtxo[]: (Optional) specify token utxosftChangeAddress-string|bsv.Adderss: (Optional) specify ft changeAddressisMerge-String: (Optional) do not use this param. Please use function Merge.opreturnData-Array: (Optional) append an opReturn outpututxoMaxCount-number: (Optional) Maximum number of BSV UTXOs supported, the default is 3.
The number of bsv utxo inputs must not be greater than 3, or the transaction will failed.
Returns
Promise returns number: The fee amount estimated.
Example
const ft = new sensible.SensibleFT({});
let estimateFee = await ft.getMergeEstimateFee({
codehash,
genesis,
ownerWif: CoffeeShop.privateKey.toWIF(),
opreturnData,
});
getTransferEstimateFee2
ft.getTransferEstimateFee2(options)
Estimate the cost of transfer
Parameters
options-Object:bsvInputLen-string: the count of bsv inputstokenInputLen-string: the count of token inputstokenOutputLen-string: the count of token outputsopreturnData-string[]|string|Buffer: (Optional) append an opReturn output
Returns
Promise returns number: The fee amount estimated.
Example
const ft = new sensible.SensibleFT({});
let estimateFee = await ft.getTransferEstimateFee2({
bsvInputLen: 3,
tokenInputLen: 1,
tokenOutputLen: 6,
});
setDustThreshold
ft.setDustThreshold(options)
Set dust. DustAmount has a higher priority than dustLimitFactor.
Notice, too low dust will be rejected by miner.
Parameters
options-Object: The options used for deployment.dustLimitFactor-number: (Optional): specify the output dust rate, default is 0.25 .If the value is equal to 0, the final dust will be at least 1.dustAmount-number: (Optional): specify the output dust
Returns
none
Example
ft.setDustThreshold({
dustLimitFactor: 0.25
)
ft.setDustThreshold({
dustAmount: 1
})
sign
ft.sign(options)
Update the signature of the transaction
Parameters
options-Object:tx-bsv.Transaction: the genesis of token.sigHashList- SigHashInfo[]: the codehash of token.sigList- SigInfo[] : token receivers.[{address:’xxx’,amount:’1000’}]
Returns
none
Example
const ft = new sensible.SensibleFT({});
let { tx, sigHashList } = await ft.unsignGenesis({
tokenName: "CoffeeCoin",
tokenSymbol: "CC",
decimalNum: 8,
genesisPublicKey: CoffeeShop.publicKey,
utxos,
});
let sigList = signSigHashList(sigHashList);
ft.sign(tx, sigHashList, sigList);
await sensibleApi.broadcast(tx.serialize(true));
broadcast
ft.broadcast(txHex)
Broadcast a transaction
Parameters
txHex-string: the raw hex of transaction
Returns
Promise returns string: the txid of transaction
Example
const {...,txHex} = ft.genesis({...,noBroadcast:true});
let txid = await ft.broadcast(txHex);
console.log(txid);
dumpTx
ft.dumpTx(tx)
Dump transaction.
Parameters
tx-bsv.Transaction: the transaction to dump
Returns
none
Example
const {...,tx} = ft.genesis(options);
ft.dumpTx(tx);
> =============================================================================================
Summary
txid: 22ad1c67cb4611eb0cf451861d9c67aae835537468e06abdccac0e71c487019c
Size: 3758
Fee Paid: 0.00001893
Fee Rate: 0.5037 sat/B
Detail: 1 Inputs, 2 Outputs
----------------------------------------------------------------------------------------------
=>0 1MxFhEQ1fMkqaYJEKqRUGiz76ZjNJJ9ncm 9.13627305 BSV
lock-size: 25
unlock-size: 107
via 3d1ce4a600298cd960f713125d88e4cfefbfa116ac640a184fd1130b044b3fb0 [2]
Input total: 9.13627305 BSV
----------------------------------------------------------------------------------------------
=>0 nonstandard 0.00002784 BSV
size: 3555
=>1 1MxFhEQ1fMkqaYJEKqRUGiz76ZjNJJ9ncm 9.13622628 BSV
size: 25
Output total: 9.13625412 BSV
=============================================================================================
getSummary
ft.getSummary(address)
Query the token summary infos of address.
Parameters
address-string: token address.
Returns
Promise returns FungibleTokenSummary[]
Example
const ft = new SensibleFT({});
let summarys = await ft.getSummary("18WoTi5rkjtqrR74pQ2q6gSzshCosjyTTr");
console.log(summarys)
> [
{
codehash: '777e4dd291059c9f7a0fd563f7204576dcceb791',
genesis: '8e9c53e1a38ff28772db99ee34a23bb305062a1a',
sensibleId: '17f47c6861b3a4fec7d337d80d204e6d214836c88e49e9bea398feddddb455ae00000000',
pendingBalance: '0',
balance: '631034354',
symbol: 'OVTS',
decimal: 3
}
]
getFtUtxos
ft.getFtUtxos(options)
Query token utxos.
Parameters
genesis-string: the genesis of token.codehash-string: the codehash of token.address-stringtoken addresscount-number(Optional) the default is 20.
Returns
Promise returns FungibleTokenUnspent[] : utxos of token
Example
getCodehashAndGensisByTx
getCodehashAndGensisByTx(genesisTx,genesisOutputIndex)
Get codehash and genesis from genesis tx.
Parameters
genesisTx-bsv.Transaction: the genesis transaction.genesisOutputIndex-number: (Optional) the outputIndex of the TokenGenesis contract. Default is 0.
Returns
Object:
genesis-string: the genesis of token.codehash-string: the codehash of token.sensibleId-string: the sensibleId of token.
Example
const {tx} = ft.genesis(options);
const {genesis,codehash,sensibleId} = ft.getCodehashAndGensisByTx(tx);
= Static Methods =
selectSigners
SensibleFT.selectSigners(signerConfigs)
select available signers
3/5 signers are required to provide transaction correlation.
The function is decide which 3 signers will be used. (with the fastest response)
Parameters
signerConfigs- SignerConfig[]: (Optional) The signers for the token to instantiate
If the signerConfigs is not provided, the default will be used.
Returns
Object:
signers- SignerConfig[] signerssignerSelecteds-number[]: the selected index of signers.
Example
isSupportedToken
SensibleFT.isSupportedToken(codehash)
The SDK only supports tokens with specified version codehash.
Parameters
codehash-string: the codehash of token.
Returns
boolean: is token supported
Example
let isSupported = sensible.SensibleFT.isSupportedToken("777e4dd291059c9f7a0fd563f7204576dcceb791");
console.log(isSupported);
>true
parseTokenScript
SensibleFT.parseTokenScript(scriptBuf,[network])
a function to parse output script
Parameters
scriptBuf-Buffer: The token script buffernetwork- API_NET: (Optional) network
Returns
Object: The transaction object:
codehash-string: the codehash of tokengenesis-string: the genesis of token.sensibleId-stringthe sensibleId of token.tokenName-string: the token nametokenSymbol-string: the token symbolgenesisFlag-number: is the TokenGenesis contract or not.decimalNum-number: the token decimaltokenAddress-string: the token addresstokenAmount-BN: the token amountgenesisHash-string: the token genesisHashrabinPubKeyHashArrayHash-string: the token rabinPubKeyHashArrayHashsensibleID- SensibleID: the token sensibleIDprotoVersion-number: the proto versionprotoType-number: the proto type
Example
const tx = new bsv.Transaction(rawHex);
const scriptBuf = tx.outputs[0].scriptBuf
let { tokenAmount } = await ft.parseTokenScript(scriptBuf);
console.log(tokenAmount.toString('hex'));