Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit a90dfd4

Browse files
committed
Several documentation updates to slp-sdk Utils class
1 parent 28a0139 commit a90dfd4

1 file changed

Lines changed: 167 additions & 1 deletion

File tree

Lines changed: 167 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Utils
2+
title: Util
33
icon: exchange
44
ordinal: 10
55
---
@@ -553,6 +553,172 @@ transactions: `Array`
553553
}
554554
]
555555

556+
### `decodeOpReturn`
557+
558+
Get high-level SLP data on a transaction by decoding the OP_RETURN data.
559+
Throws an error if the txid is not an SLP transaction.
560+
561+
Note: It is convention in the SLP protocol to use the lowest denomination
562+
of decimal in the calculations. e.g. Using integer `satoshis` for calculations
563+
instead of floating point `bitcoins`. For this reason, the decimal information
564+
for the token only exists in the Genesis transaction, and other transactions
565+
display all token quantities as large integers.
566+
567+
#### Arguments
568+
569+
1. txid: `string` **required**. The txid of an SLP transaction
570+
571+
#### Result
572+
573+
slpData: `Object`
574+
575+
#### Examples
576+
577+
// A Genesis SLP transaction.
578+
(async () => {
579+
try {
580+
const txid =
581+
"bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90"
582+
583+
const slpData = await SLP.Utils.decodeOpReturn(txid)
584+
console.log(slpData)
585+
} catch (error) {
586+
console.error(error)
587+
}
588+
})()
589+
590+
// returns
591+
{
592+
"tokenType": 1,
593+
"transactionType": "genesis",
594+
"ticker": "SLPSDK",
595+
"name": "SLP SDK example using BITBOX",
596+
"documentUrl": "developer.bitcoin.com",
597+
"documentHash": "",
598+
"decimals": 8,
599+
"mintBatonVout": 2,
600+
"initialQty": 507,
601+
"tokensSentTo": "bitcoincash:qpcqs0n5xap26un2828n55gan2ylj7wavvzeuwdx05",
602+
"batonHolder": "bitcoincash:qpcqs0n5xap26un2828n55gan2ylj7wavvzeuwdx05"
603+
}
604+
605+
// A Mint SLP transaction.
606+
(async () => {
607+
try {
608+
const txid =
609+
"65f21bbfcd545e5eb515e38e861a9dfe2378aaa2c4e458eb9e59e4d40e38f3a4"
610+
611+
const slpData = await SLP.Utils.decodeOpReturn(txid)
612+
console.log(slpData)
613+
} catch (error) {
614+
console.error(error)
615+
}
616+
})()
617+
618+
// returns
619+
{
620+
"tokenType": 1,
621+
"transactionType": "mint",
622+
"tokenId": "023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4",
623+
"mintBatonVout": 2,
624+
"batonStillExists": true,
625+
"quantity": "10000000000",
626+
"tokensSentTo": "bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q",
627+
"batonHolder": "bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q"
628+
}
629+
630+
// A Send SLP transaction.
631+
(async () => {
632+
try {
633+
const txid =
634+
"4f922565af664b6fdf0a1ba3924487344be721b3d8815c62cafc8a51e04a8afa"
635+
636+
const slpData = await SLP.Utils.decodeOpReturn(txid)
637+
console.log(slpData)
638+
} catch (error) {
639+
console.error(error)
640+
}
641+
})()
642+
643+
// returns
644+
{
645+
"tokenType": 1,
646+
"transactionType": "send",
647+
"tokenId": "023cd3e95a3947058b994fd15a9a4c47937a9d9b6e0c0b1b5898d2ce84f354e4",
648+
"spendData": [
649+
{
650+
"quantity": "300000000",
651+
"sentTo": "bitcoincash:qzv7t2pzn2d0pklnetdjt65crh6fe8vnhuwvhsk2nn",
652+
"vout": 1
653+
},
654+
{
655+
"quantity": "60400000000",
656+
"sentTo": "bitcoincash:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5u5k0yyr2q",
657+
"vout": 2
658+
}
659+
]
660+
}
661+
662+
### `isTokenUtxo`
663+
664+
Given an array of UTXOs, this function returns an array of Boolean values
665+
indicating if each UTXO belongs to an SLP transaction (true) or not (false).
666+
If false, the UTXO is safe for a wallet to spend in a normal BCH transaction.
667+
668+
#### Arguments
669+
670+
1. utxos: `Array` of utxo objects **required**.
671+
672+
#### Result
673+
674+
- `Array` of Boolean values.
675+
- `true`: The UTXO belongs to an SLP token.
676+
- `false`: The UTXO does not belong to an SLP token.
677+
678+
#### Examples
679+
680+
(async () => {
681+
try {
682+
const u = await SLP.Address.utxo("bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90")
683+
const utxos = u.utxos
684+
685+
console.log(`utxos: ${JSON.stringify(utxos,null,2)}`)
686+
687+
const isSLPUtxo: await SLP.Utils.isTokenUtxo(utxos)
688+
console.log(`canSpend: ${JSON.stringify(canSpend,null,2}`)
689+
} catch (error) {
690+
console.error(error)
691+
}
692+
})()
693+
694+
// returns
695+
utxos: [
696+
{
697+
txid:
698+
"bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90",
699+
vout: 3,
700+
amount: 0.00002015,
701+
satoshis: 2015,
702+
height: 594892,
703+
confirmations: 5
704+
},
705+
{
706+
txid:
707+
"bd158c564dd4ef54305b14f44f8e94c44b649f246dab14bcb42fb0d0078b8a90",
708+
vout: 2,
709+
amount: 0.00000546,
710+
satoshis: 546,
711+
height: 594892,
712+
confirmations: 5
713+
}
714+
]
715+
716+
isSLPUtxo:
717+
[
718+
false,
719+
true
720+
]
721+
556722
### `burnTotal`
557723

558724
List input, output and burn total for slp transaction

0 commit comments

Comments
 (0)