SLPJS
SLPJS is a JavaScript Library for validating and building Simple Ledger Protocol (SLP) token transactions. GENESIS, MINT, and SEND token functions are supported. See change log for updates.
Table of Contents
Installation
NOTE: Using SLPJS requires bitbox-sdk and bitcore-lib-cash to also be installed.
For node.js
npm install slpjs bitbox-sdk bitcore-lib-cash
For browser (only works for versions <= 0.26.0)
<script src='https://unpkg.com/slpjs@0.26.0'></script>
NOTE: The latest version of slpjs package will be refactored to fix this problem.
Transaction Examples
The following code snippet examples can be copy/pasted directly into the node.js CLI. See the examples directory for example files written in TypeScript than can be run using tsc & node <filename>
.
Wallets utilizing this library will want to write their own methods in place of the methods found in TransactionHelpers
and BitboxNetwork
classes.
NOTES:
- The BigNumber.js library is used to avoid precision issues with numbers having more than 15 significant digits.
- For the fastest validation performance all of the following transaction examples show how to use SLPJS using default SLP validation via
rest.bitcoin.com
. See the Local Validation section for instructions on how to validate SLP locally with your own full node. - All SLPJS methods require token quantities to be expressed in the smallest possible unit of account for the token (i.e., token satoshis). This requires the token's precision to be used to calculate the quantity. For example, token having a decimal precision of 9 sending an amount of 1.01 tokens would need to first calculate the sending amount using
1.01 x 10^9 => 1010000000
.
Get Balances
Get all balances for a given example. See also the TypeScript example.
// Install BITBOX-SDK v8.1+ for blockchain access// For more information visit: https://www.npmjs.com/package/bitbox-sdkconst BITBOXSDK = const slpjs = ; // FOR MAINNET UNCOMMENTlet addr = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu";const BITBOX = restURL: 'https://rest.bitcoin.com/v2/' ; // FOR TESTNET UNCOMMENT// let addr = "slptest:qpwyc9jnwckntlpuslg7ncmhe2n423304ueqcyw80l";// const BITBOX = new BITBOXSDK.BITBOX({ restURL: 'https://trest.bitcoin.com/v2/' }); const bitboxNetwork = BITBOX; let balances; { balances = await bitboxNetwork; console;}; // RETURNS ALL BALANCES & UTXOs: // { satoshis_available_bch: 190889,// satoshis_locked_in_slp_baton: 546,// satoshis_locked_in_slp_token: 1092,// satoshis_in_invalid_token_dag: 0,// satoshis_in_invalid_baton_dag: 0,// slpTokenBalances: {// '1cda254d0a995c713b7955298ed246822bee487458cd9747a91d9e81d9d28125': BigNumber { s: 1, e: 3, c: [ 1000 ] },// '047918c612e94cce03876f1ad2bd6c9da43b586026811d9b0d02c3c3e910f972': BigNumber { s: 1, e: 2, c: [ 100 ] } // },// nftParentChildBalances: {// 'parentId1': {// 'childId1': BigNumber// 'childId2': BigNumber// }// 'parentId2': {// 'childId1': BigNumber// 'childId2': BigNumber// }// }// slpTokenUtxos: [ ... ],// slpBatonUtxos: [ ... ],// invalidTokenUtxos: [ ... ],// invalidBatonUtxos: [ ... ],// nonSlpUtxos: [ ... ]// unknownTokenTypeUtxos: [ ... ]// }
GENESIS - Create a new token
GENESIS is the most simple type of SLP transaction since no special inputs are required. The following example shows how to create a fungible token. Also see the TypeScript examples for:
// Install BITBOX-SDK v8.1+ for blockchain access// For more information visit: https://www.npmjs.com/package/bitbox-sdkconst BITBOXSDK = const BigNumber = ;const slpjs = ; // FOR MAINNET UNCOMMENTconst BITBOX = restURL: 'https://rest.bitcoin.com/v2/' ;const fundingAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // <-- must be simpleledger formatconst fundingWif = "L3gngkDg1HW5P9v5GdWWiCi3DWwvw5XnzjSPwNwVPN5DSck3AaiF"; // <-- compressed WIF formatconst tokenReceiverAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // <-- must be simpleledger formatconst bchChangeReceiverAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // <-- cashAddr or slpAddr format// For unlimited issuance provide a "batonReceiverAddress"const batonReceiverAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // FOR TESTNET UNCOMMENT// const BITBOX = new BITBOXSDK.BITBOX({ restURL: 'https://trest.bitcoin.com/v2/' });// const fundingAddress = "slptest:qpwyc9jnwckntlpuslg7ncmhe2n423304ueqcyw80l";// const fundingWif = "cVjzvdHGfQDtBEq7oddDRcpzpYuvNtPbWdi8tKQLcZae65G4zGgy";// const tokenReceiverAddress = "slptest:qpwyc9jnwckntlpuslg7ncmhe2n423304ueqcyw80l";// const bchChangeReceiverAddress = "slptest:qpwyc9jnwckntlpuslg7ncmhe2n423304ueqcyw80l";// // For unlimited issuance provide a "batonReceiverAddress"// const batonReceiverAddress = "slptest:qpwyc9jnwckntlpuslg7ncmhe2n423304ueqcyw80l"; const bitboxNetwork = BITBOX; // 1) Get all balances at the funding address.let balances; { balances = await bitboxNetwork; console; console;}; // WAIT FOR NETWORK RESPONSE... // 2) Select decimal precision for this new tokenlet decimals = 2;let name = "Awesome SLPJS README Token";let ticker = "SLPJS";let documentUri = "info@simpleledger.io";let documentHash = nulllet initialTokenQty = 1000000 // 3) Calculate the token quantity with decimal precision includedinitialTokenQty = initialTokenQty; // 4) Set private keysbalancesnonSlpUtxos // 5) Use "simpleTokenGenesis()" helper methodlet genesisTxid;{ genesisTxid = await bitboxNetwork console};
MINT - Create additional tokens
Adding additional tokens for a token that already exists is possible if you are in control of the minting "baton". This minting baton is a special UTXO that gives authority to add to the token's circulating supply. Also see the TypeScript example.
// Install BITBOX-SDK v8.1+ for blockchain access// For more information visit: https://www.npmjs.com/package/bitbox-sdkconst BITBOXSDK = const BigNumber = ;const slpjs = ; // FOR MAINNET UNCOMMENTconst BITBOX = restURL: 'https://rest.bitcoin.com/v2/' ;const fundingAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // <-- must be simpleledger formatconst fundingWif = "L3gngkDg1HW5P9v5GdWWiCi3DWwvw5XnzjSPwNwVPN5DSck3AaiF"; // <-- compressed WIF formatconst tokenReceiverAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // <-- must be simpleledger formatconst batonReceiverAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu";const bchChangeReceiverAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // <-- cashAddr or slpAddr formatconst tokenIdHexToMint = "adcf120f51d45056bc79353a2831ecd1843922b3d9fac5f109160bd2d49d3f4c";let additionalTokenQty = 1000 // FOR TESTNET UNCOMMENT// const BITBOX = new BITBOXSDK.BITBOX({ restURL: 'https://trest.bitcoin.com/v2/' });// const fundingAddress = "slptest:qpwyc9jnwckntlpuslg7ncmhe2n423304ueqcyw80l";// const fundingWif = "cVjzvdHGfQDtBEq7oddDRcpzpYuvNtPbWdi8tKQLcZae65G4zGgy";// const tokenReceiverAddress = "slptest:qpwyc9jnwckntlpuslg7ncmhe2n423304ueqcyw80l";// const batonReceiverAddress = "slptest:qpwyc9jnwckntlpuslg7ncmhe2n423304ueqcyw80l";// const bchChangeReceiverAddress = "slptest:qpwyc9jnwckntlpuslg7ncmhe2n423304ueqcyw80l";// const tokenIdHexToMint = "a67e2abb2fcfaa605c6a3b0dfb642cc830b63138d85b5e95eee523fdbded4d74";// let additionalTokenQty = 1000 const bitboxNetwork = BITBOX; // 1) Get all balances at the funding address.let balances; { balances = await bitboxNetwork; console; ifbalancesslpBatonUtxostokenIdHexToMint console; else throw Error"You don't have the minting baton for this token";}; // 2) Fetch critical token decimals information using bitdblet tokenDecimals; { const tokenInfo = await bitboxNetwork; tokenDecimals = tokenInfodecimals; console;}; // WAIT FOR ASYNC METHOD TO COMPLETE // 3) Multiply the specified token quantity by 10^(token decimal precision)let mintQty = additionalTokenQty // 4) Filter the list to choose ONLY the baton of interest // NOTE: (spending other batons for other tokens will result in losing ability to mint those tokens)let inputUtxos = balancesslpBatonUtxostokenIdHexToMint // 5) Simply sweep our BCH (non-SLP) utxos to fuel the transactioninputUtxos = inputUtxos; // 6) Set the proper private key for each UtxoinputUtxos // 7) MINT token using simple functionlet mintTxid; { mintTxid = await bitboxNetwork console;};
SEND - Send tokens
This example shows the general workflow for sending an existing token. Also see the TypeScript example.
// Install BITBOX-SDK v8.1+ for blockchain access// For more information visit: https://www.npmjs.com/package/bitbox-sdkconst BITBOXSDK = ;const BigNumber = ;const slpjs = ; // FOR MAINNET UNCOMMENTconst BITBOX = restURL: 'https://rest.bitcoin.com/v2/' ;const fundingAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // <-- must be simpleledger formatconst fundingWif = "L3gngkDg1HW5P9v5GdWWiCi3DWwvw5XnzjSPwNwVPN5DSck3AaiF"; // <-- compressed WIF formatconst tokenReceiverAddress = "simpleledger:qplrqmjgpug2qrfx4epuknvwaf7vxpnuevyswakrq9" ; // <-- must be simpleledger formatconst bchChangeReceiverAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // <-- must be simpleledger formatlet tokenId = "d32b4191d3f78909f43a3f5853ba59e9f2d137925f28e7780e717f4b4bfd4a3f";let sendAmounts = 1 ; // FOR TESTNET UNCOMMENT// const BITBOX = new BITBOXSDK.BITBOX({ restURL: 'https://trest.bitcoin.com/v2/' });// const fundingAddress = "slptest:qpwyc9jnwckntlpuslg7ncmhe2n423304ueqcyw80l"; // <-- must be simpleledger format// const fundingWif = "cVjzvdHGfQDtBEq7oddDRcpzpYuvNtPbWdi8tKQLcZae65G4zGgy"; // <-- compressed WIF format// const tokenReceiverAddress = "slptest:qpwyc9jnwckntlpuslg7ncmhe2n423304ueqcyw80l"; // <-- must be simpleledger format// const bchChangeReceiverAddress = "slptest:qpwyc9jnwckntlpuslg7ncmhe2n423304ueqcyw80l"; // <-- must be simpleledger format// let tokenId = "78d57a82a0dd9930cc17843d9d06677f267777dd6b25055bad0ae43f1b884091";// let sendAmounts = [ 10 ]; const bitboxNetwork = BITBOX; // 1) Fetch critical token informationlet tokenDecimals; { const tokenInfo = await bitboxNetwork; tokenDecimals = tokenInfodecimals; console;}; // Wait for network responses... // 2) Check that token balance is greater than our desired sendAmountlet balances; { balances = await bitboxNetwork; console; console; ifbalancesslpTokenBalancestokenId === undefined console console;}; // Wait for network responses... // 3) Calculate send amount in "Token Satoshis". In this example we want to just send 1 token unit to someone...sendAmounts = sendAmounts; // Don't forget to account for token precision // 4) Get all of our token's UTXOslet inputUtxos = balancesslpTokenUtxostokenId; // 5) Simply sweep our BCH utxos to fuel the transactioninputUtxos = inputUtxos; // 6) Set the proper private key for each UtxoinputUtxos; // 7) Send tokenlet sendTxid;{ sendTxid = await bitboxNetwork console;};
SEND - Send BCH
This example demonstrates how to send BCH from a SLP enabled wallet. This API ensures the BCH transaction does not use SLP UTXOs which can cause token loss for the wallet.
// Install BITBOX-SDK v8.1+ for blockchain access// For more information visit: https://www.npmjs.com/package/bitbox-sdkconst BITBOXSDK = ;const BigNumber = ;const slpjs = ; // FOR MAINNETconst BITBOX = restURL: 'https://rest.bitcoin.com/v2/' ;const fundingAddress = "bitcoincash:qzq6g2dzadew2ctt6cfhthwcc2q9m60mj56ld2hj5l"; // <-- must be CashAddr format // can use BITBOX.HDNode.toWIF() to generate thisconst fundingWif = "KzzMBS6twjSLAjH3a1wkd7rWs3PpiHq4eQzqSEfHuxbXfxYFUBiL"; // <-- compressed WIF formatconst bchReceiverAddress = "bitcoincash:qz42xz5y2hfltsa94mwm36pnl3ew8u72cc9l038x8m" ; // <-- must be CashAddr formatconst bchChangeReceiverAddress = "bitcoincash:qzd5hqnlu2gprdxphqt6jvft33s3m2hegcqtu6mktg"; // <-- must be CashAddr format let sendAmountsInSatoshi = 1000; const bitboxNetwork = BITBOX; // 1) Check that token balance is greater than our desired sendAmountlet balances; { balances = await bitboxNetwork; console; if balancessatoshis_available_bch < sendAmountsInSatoshi throw "You need to fund the addresses provided in this example with BCH."; console;}; // Wait for network responses... // 2) construct sendAmounts as an array of BigIntlet sendAmounts = sendAmountsInSatoshi ; // 3) Get all of non-SLP UTXOslet inputUtxos = balancesnonSlpUtxos; // 4) Set the proper private key for each UtxoinputUtxos = inputUtxos; // 5) Send tokenlet sendTxId;async { sendTxId = await bitboxNetwork; console;};
SEND - Send tokens from a frozen address
This example shows how to freeze funds until a future time using OP_CLTV. Also see the TypeScript example. First, the address is calculated based on a user-defined public key and locktime. After the locktime has elapsed the user can proceed to spend those funds as demonstrated in this example:
redeemScript (locking script) = <locktime> OP_CHECKLOCKTIMEVERIFY OP_DROP <pubkey> OP_CHECKSIG
unlocking script = <signature>
const BITBOXSDK = ;const BigNumber = ;const slpjs = ;const BITBOX = restURL: 'https://trest.bitcoin.com/v2/' ;const slp = BITBOX;const helpers = slp;const opcodes = BITBOXScriptopcodes; const pubkey = "0286d74c6fb92cb7b70b817094f48bf8fd398e64663bc3ddd7acc0a709212b9f69";const wif = "cPamRLmPyuuwgRAbB6JHhXvrGwvHtmw9LpVi8QnUZYBubCeyjgs1";const tokenReceiverAddress = "slptest:prk685k6r508xkj7u9g8v9p3f97hrmgr2qp7r4safs" ; // <-- must be simpleledger formatconst bchChangeReceiverAddress = "slptest:prk685k6r508xkj7u9g8v9p3f97hrmgr2qp7r4safs"; // <-- must be simpleledger formatlet tokenId = "f0c7a8a7addc29edbc193212057d91c3eb004678e15e4662773146bdd51f8d7a";let sendAmounts = 1 ; // Set our BIP-113 time lock (subtract an hour to acount for MTP-11)const time_delay_seconds = 0; // let's just set it to 0 so we can redeem it immediately.let locktime locktimeBip62;{ locktime = await BITBOXBlockchainmediantime + time_delay_seconds - 3600; // NOTE: the following locktime is hard-coded so that we can reuse the same P2SH address. locktimeBip62 = 'c808f05c' //slpjs.Utils.get_BIP62_locktime_hex(locktime); }; // Wait for network response... let redeemScript = BITBOXScript // Calculate the address for this script contract // We need to send some token and BCH to it before we can spend it!let fundingAddress = slpjsUtils; // gives us: slptest:prk685k6r508xkj7u9g8v9p3f97hrmgr2qp7r4safs const bitboxNetwork = BITBOX; // Fetch critical token informationlet tokenDecimals; { const tokenInfo = await bitboxNetwork; tokenDecimals = tokenInfodecimals; console;}; // Wait for network response... // Check that token balance is greater than our desired sendAmountlet balances; { balances = await bitboxNetwork; console; console; ifbalancesslpTokenBalancestokenId === undefined console console;}; // Wait for network response... // Calculate send amount in "Token Satoshis". In this example we want to just send 1 token unit to someone...sendAmounts = sendAmounts; // Don't forget to account for token precision // Get all of our token's UTXOslet inputUtxos = balancesslpTokenUtxostokenId; // Simply sweep our BCH utxos to fuel the transactioninputUtxos = inputUtxos; // Estimate the additional fee for our larger p2sh scriptSigslet extraFee = 8 * // for OP_CTLV and timelock data push inputUtxoslength // this many times since we swept inputs from p2sh address // Build an unsigned transactionlet unsignedTxnHex = helpers;unsignedTxnHex = helpers;unsignedTxnHex = helpers; // Build scriptSigs let scriptSigs = inputUtxos let signedTxn = helpers; // 11) Send tokenlet sendTxid;{ sendTxid = await bitboxNetwork console;};
SEND - Send tokens from 2-of-2 multisig (P2SH)
This example shows the general workflow for sending tokens from a P2SH multisig address. Also see the TypeScript example. Electron Cash SLP edition 3.4.13 is compatible with signing the partially signed transactions generated from this example by using the insert_input_values_for_EC_signers
helper method.
// Install BITBOX-SDK v8.1+ for blockchain access// For more information visit: https://www.npmjs.com/package/bitbox-sdkconst BITBOXSDK = ;const BigNumber = ;const slpjs = ;const BITBOX = restURL: 'https://rest.bitcoin.com/v2/' ;const slp = BITBOX;const helpers = slp; const pubkey_signer_1 = "02471e07bcf7d47afd40e0bf4f806347f9e8af4dfbbb3c45691bbaefd4ea926307"; // Signer #1const pubkey_signer_2 = "03472cfca5da3bf06a85c5fd860ffe911ef374cf2a9b754fd861d1ead668b15a32"; // Signer #2 // we have two signers for this 2-of-2 multisig address (so for the missing key we just put "null")const wifs = null "L2AdfmxwsYu3KnRASZ51C3UEnduUDy1b21sSF9JbLNVEPzsxEZib" //[ "Ky6iiLSL2K9stMd4G5dLeXfpVKu5YRB6dhjCsHyof3eaB2cDngSr", null ]; // to keep this example alive we will just send everything to the same addressconst tokenReceiverAddress = "simpleledger:pphnuh7dx24rcwjkj0sl6xqfyfzf23aj7udr0837gn" ; // <-- must be simpleledger formatconst bchChangeReceiverAddress = "simpleledger:pphnuh7dx24rcwjkj0sl6xqfyfzf23aj7udr0837gn"; // <-- must be simpleledger formatlet tokenId = "497291b8a1dfe69c8daea50677a3d31a5ef0e9484d8bebb610dac64bbc202fb7";let sendAmounts = 1 ; const bitboxNetwork = BITBOX; // 1) Fetch critical token informationlet tokenDecimals; { const tokenInfo = await bitboxNetwork; tokenDecimals = tokenInfodecimals; console;}; // Wait for network responses... // 2) Check that token balance is greater than our desired sendAmountlet fundingAddress = "simpleledger:pphnuh7dx24rcwjkj0sl6xqfyfzf23aj7udr0837gn";let balances; { balances = await bitboxNetwork; console; console; ifbalancesslpTokenBalancestokenId === undefined console console;}; // Wait for network responses... // 3) Calculate send amount in "Token Satoshis". In this example we want to just send 1 token unit to someone...sendAmounts = sendAmounts; // Don't forget to account for token precision // 4) Get all of our token's UTXOslet inputUtxos = balancesslpTokenUtxostokenId; // 5) Simply sweep our BCH utxos to fuel the transactioninputUtxos = inputUtxos; // 6) Estimate the additional fee for our larger p2sh scriptSigslet extraFee = 2 * 33 + // two pub keys in each redeemScript 2 * 72 + // two signatures in scriptSig 10 * // for OP_CMS and various length bytes inputUtxoslength // this many times since we swept inputs from p2sh address // 7) Build an unsigned transactionlet unsignedTxnHex = helpers; // 8) Build scriptSigs for all intputslet redeemData = helpers;let scriptSigs = inputUtxos // 9) apply our scriptSigs to the unsigned transactionlet signedTxn = helpers; // 10) Update transaction hex with input values to allow for our second signer who is using Electron Cash SLP edition (https://simpleledger.cash/project/electron-cash-slp-edition/)let input_values = inputUtxossignedTxn = helpers // 11) Send tokenlet sendTxid;{ sendTxid = await bitboxNetwork console;};
BURN - Destroy tokens for a certain Token Id
This example shows the general workflow for sending an existing token. Also see the TypeScript example.
// Install BITBOX-SDK v8.1+ for blockchain access// For more information visit: https://www.npmjs.com/package/bitbox-sdkconst BITBOXSDK = const BigNumber = ;const slpjs = ; const BITBOX = restURL: 'https://rest.bitcoin.com/v2/' ;const fundingAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // <-- must be simpleledger formatconst fundingWif = "L3gngkDg1HW5P9v5GdWWiCi3DWwvw5XnzjSPwNwVPN5DSck3AaiF"; // <-- compressed WIF formatconst bchChangeReceiverAddress = "simpleledger:qrhvcy5xlegs858fjqf8ssl6a4f7wpstaqnt0wauwu"; // <-- must be simpleledger formatlet tokenId = "495322b37d6b2eae81f045eda612b95870a0c2b6069c58f70cf8ef4e6a9fd43a";let burnAmount = 102; const bitboxNetwork = BITBOX; // 1) Fetch critical token informationlet tokenDecimals; { const tokenInfo = await bitboxNetwork; tokenDecimals = tokenInfodecimals; console;}; // 2) Check that token balance is greater than our desired sendAmountlet balances; { balances = await bitboxNetwork; console; console}; // Wait for network responses... // 3) Calculate send amount in "Token Satoshis". In this example we want to just send 1 token unit to someone...let amount = burnAmount; // Don't forget to account for token precision // 4) Get all of our token's UTXOslet inputUtxos = balancesslpTokenUtxostokenId; // 5) Simply sweep our BCH utxos to fuel the transactioninputUtxos = inputUtxos; // 6) Set the proper private key for each UtxoinputUtxos // 7) Send tokenlet sendTxid;{ sendTxid = await bitboxNetwork console;};
Address Conversion
let Utils = Utils; let slpAddr = Utils;console;// simpleledger:qzat5lfxt86mtph2fdmp96stxdmmw8hchy2cnqfh7h let cashAddr = Utils;console;// bitcoincash:qzat5lfxt86mtph2fdmp96stxdmmw8hchyxrcmuhqf
Validation Examples
The following examples show three different ways how you can use this library to validate SLP transactions. The validation techniques include:
- Local Validator with a JSON RPC full node connection
- Local Validation with a remote full node (using
rest.bitcoin.com
) - Remote Validation (using
rest.bitcoin.com
)
Local Validator with a JSON RPC full node connection
Validate SLP transaction locally with a local full node.
const BITBOXSDK = const BITBOX = ;const slpjs = ;const logger = console;const RpcClient = ;const connectionString = 'http://bitcoin:password@localhost:8332'const rpc = connectionString;const slpValidator = BITBOX async await rpc logger // Result = false//let txid = "903432f451049357d51c19eb529478621272e7572b05179f89bcb7be31e55aa7"; // Result = truelet txid = "4a3829d6da924a16bbc0cc43d5d62b40996648a0c8f74725c15ec56ee930d0fa"; let isValid; { console; console; isValid = await slpValidator; console;};
rest.bitcoin.com
)
Local Validation with a remote full node (using Validate SLP transaction locally with a remote full node (i.e., rest.bitcoin.com).
const BITBOXSDK = const BITBOX = restURL: 'https://rest.bitcoin.com/v2/' ;const slpjs = ;const logger = console; const getRawTransactions = { return await BITBOXRawTransactions }const slpValidator = BITBOX getRawTransactions logger; // Result = false//let txid = "903432f451049357d51c19eb529478621272e7572b05179f89bcb7be31e55aa7"; // Result = truelet txid = "4a3829d6da924a16bbc0cc43d5d62b40996648a0c8f74725c15ec56ee930d0fa"; let isValid; { console; console; isValid = await slpValidator; console;};
rest.bitcoin.com
)
Remote Validation (using Validate SLP transaction using rest.bitcoin.com.
const BITBOXSDK = const BITBOX = restURL: 'https://rest.bitcoin.com/v2/' ;const slpjs = ;const logger = console; const slpValidator = BITBOX undefined logger; // Result = false//let txid = "903432f451049357d51c19eb529478621272e7572b05179f89bcb7be31e55aa7"; // Result = truelet txid = "ab1550876e217d68bfac55e50b4a82535bb20842f976bdfbc07cca19e8028f13"; let isValid; { console; console; isValid = await slpValidator; console;};
Building & Testing
Building this project creates lib/*.js files and then creates browserified versions in the dist folder.
Requirements
Running the unit tests require node.js v8.15+.
Build
npm run build
Test
npm run test
Change Log
0.27.3
- Update packages
- Minor updates to token send example
- Remove extraneous regex checks
- Add flag to disable validator transaction cache in LocalValidator
0.27.2
- Fixed false positive case for MINT validation
0.27.1
- Updated for trusted validator
- Specify
0.27.0
- Update slp.ts internals to accept validator instead of network
- Add TrustedValidator class and example
0.26.0
- Utilizing simpleledger/slp-mdm package, update associated unit tests
- Update BigNumber library
0.25.6
- Update unit tests and examples for bchd based network
- Patch missing tokenIdHex in getTokenInformation after recent refactoring
0.25.4/5
- Typings fixes
0.25.3
- Typings update for bitcore-cash-lib
- Update mocha version and settings
0.25.2
- Update typings for bitcore-cash-lib
0.25.1
- Update typings for BchdNetwork
0.25.0
- Make bitcore-lib-cash a peer dependency to prevent conflicting version issues
- Breaking change: processUtxosForSlpAbstract now has getRawTransaction method parameter
- Add TrustedValidator class for remote validation
- Add BchdNetwork class, as an alternative to BitboxNetwork class
0.24.3
- Include extra baton/receiver sats in mint/genesis change calculation
0.24.0
- breaking change: use destructured parameters in txn helpers
- Truncate all decimals in satoshis value
0.23.1
- Update retrieveRawTransaction method in slp validator
0.23.0
- (breaking change) Enable "esModuleInterop" in tsconfig.json to align with default
tsc --init
settings - Update bitbox-sdk to 8.11.1
0.22.3
- Upgrade TransactionHelpers.simpleTokenMint and Slp.buildRawMintTx for p2sh compatibility
0.22.2
- Publish *.d.ts files instead of *.ts files
- Update types for bitbox-sdk
0.22.1
- Update bitbox-sdk to latest version
- Add toRegtestAddress method in Utils
- Added bitbox-sdk to peerDependency list in package.json
- Added missing typings modules to vendors.d.ts (for bitbox)
0.22.0
- Update bchaddr-slp package (adds "regtest:" compatibility)
- Add TransactionOutput interface to primatives.ts
- Updated unit tests with "allow_inconclusive" on missing tranasaction
- More linting
- (breaking change) Update applyInitialSlpJudgement (to be able to work with non-BITBOX sources of utxo data)
0.21.4
- Fixed a critical security vulnerability in the validation message parser
- Add ts linting / allow json comments
0.21.3
- Judge NFT1 child created directly from valid NFT1 Parent Genesis as valid
- Removed map files from npm package module
0.21.2
- Export bitcore
0.21.1
- Fix local validator cache for SLPDB (bug should have only impacted SLPDB application performance)
- Updated examples with more validation options
0.21.0
- Added new code examples for NFT1 Genesis Parent and Child (see examples directory)
- Updated Genesis/Mint/Send methods for handling new token types appropriately
- Breaking: Removed old NFT1 methods from v0.15.12, these were likely never used by anyone but bumping the version just in case.
0.20.5
- Fix accounting for unknown token type UTXOs in
SlpBalancesResult
by addingsatoshis_in_unknown_token_type
andunknownTokenTypeUtxos
objects.
0.20.4
- Now NFT Parents/Children are readily visible when using
getAllSlpBalancesAndUtxos(<address>)
- Add
nftParentChildBalances
dict/map toSlpBalancesResult
. - Add
nftParentId
property to each SLP UTXO object (in typeSlpAddressUtxoResult
).
- Add
- Created an examples directory, starting to mirror/migrate README examples to this folder. This will allow easier execution of the examples when they are in TypeScript
0.20.3
- Bump version for npm issue with previous version
0.20.2
- Export Primatives namespace
- Add 'Primatives.parseFromBuffer()' method
- Remove unused typing from vendors.d.ts
- Update dependency versions to address security flags
0.20.1
- Minor typings update
0.20.0
- Added full NFT1 validation support with updates to both the validator and parser.
- Critical Issue Fixed: This version fixed a critical bug associated with unsupported token types. All previous versions will allow unsupported token types to be burned because they are treated as if they are non-SLP UTXOs. This version includes a new type of UTXO judgement for unsupported token types (
UNSUPPORTED_TYPE
), and they any UTXO receiving this judgement is prevented from being spent in the built-in transaction methods. - Added more descriptive code commenting to localvalidator.ts.
0.19.0
- Breaking Change: Added initial NFT1 validation support (not yet activated in parser). Change is breaking due to new
tokenTypeFilter
parameter in methodisValidSlpTxid()
0.18.4
- Tweaked type for ScriptSigP2SH.unlockingScriptBufArray
0.18.3
- Added simpleTokenGenesis to bitbox network class
0.18.2
- Added example for freezing tokens
- Added Locktime and CLTV helper methods to TransactionHelpers
- Added get_BIP62_locktime_hex method to Utils
- Breaking Change: Updated Slp.buildSendOpReturn, Slp.buildMintOpReturn, and Slp.buildGenesisOpReturn methods to static
0.18.1
- Added generic support for P2SH
- Added specific helper methods for multisig compatible with Electron Cash signing
- Added README example for multisig w/ Electron Cash SLP co-signer
0.18.0
- Added
simpleledger:
URI scheme parser & builder to Utils class per spec - Removed unused remote proxy validator code
- Bumped Bitbox dep to v8.1 with TypeScript updates
0.17.0
- Breaking changes:
- Dev dependency BITBOX updated to latestest version 8.0.1 from 3.0.11
- Throws on network error instead of returning null/false
- Non-breaking changes:
- Added tests for BitboxNetwork class
- added "decimalConversion" parameter to getTransactionDetails() and getTokenInformation() methods in BitboxNetwork, default is false
0.16.3
- Added slp address to getTransactionDetails() response
0.16.2
- Added optional logger to LocalValidator & BitboxNetwork classes
- Fixed bug in default remote validation for BitboxNetwork.isValidSlpTxid()
- Added comments warning users about two rate limited methods
0.16.1
- Improved error messages for insufficient inputs and fee too low
0.16.0
- Breaking changes:
- For all types of SEND transactions the change address must be provided, and the change address must be in simpleledger address format since it may contain token change.
- Non-breaking changes:
- Added new
vout
property to validation parents inLocalValidator
class - Added change log to
readme.md
- Refactored transaction builder methods into a new class called
TransactionHelpers
- Added new
0.15.13
- Fixed issue in
isSlpAddress
where it would throw instead of return false on some inputs. - Added
isLegacyAddress
,toLegacy
, andslpAddressFromHash160
methods toUtils
class.
0.15.12
- Add transaction helper methods for NFT1
0.15.11
- validate chunks of 20 with bitcoin.com validator endpoint
0.15.10
- handle array object type response from
sendRawTransaction
method inBitboxNetwork
class
0,15.9
- Add default remote validation for BitboxNetwork
- Simplified all README examples to use default validator
- Add description for how to override the default validator