-
Notifications
You must be signed in to change notification settings - Fork 212
/
API.md
1459 lines (1154 loc) · 57.2 KB
/
API.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# API Specification
NBXplorer is a multi crypto currency lightweight block explorer.
NBXplorer does not index the whole blockchain, rather, it listens transactions and blocks from a trusted full node and index only addresses and transactions which belongs to a `DerivationScheme` that you decide to track.
## Table of content
* [Configuration](#configuration)
* [Tracked Sources](#tracked-sources)
* [Derivation schemes](#derivationScheme)
* [Groups](#groups)
* [Addresses](#addresses)
* [Authentication](#authentication)
* [Tracking derivation scheme or address](#track)
* [Query transactions of tracked sources](#transactions)
* [Query specifc transactions of tracked sources](#singletransaction)
* [Get balance of tracked sources](#balance)
* [Get a transaction](#gettransaction)
* [Get connection status to the chain](#status)
* [Get a new unused address](#unused)
* [Get scriptPubKey information of a Derivation Scheme](#scriptPubKey)
* [Get available Unspent Transaction Outputs (UTXOs) of tracked sources](#utxos)
* [Notifications via websocket](#websocket)
* [Broadcast a transaction](#broadcast)
* [Rescan a transaction](#rescan)
* [Get fee rate](#feerate)
* [Scan UTXO Set](#scanUtxoSet)
* [Wipe derivation scheme transactions](#wipe)
* [Query event stream](#eventStream)
* [Query event stream from most recent](#eventStreamLatest)
* [Create Partially Signed Bitcoin Transaction](#psbt)
* [Update Partially Signed Bitcoin Transaction](#updatepsbt)
* [Attach metadata to a derivation scheme](#metadata)
* [Detach metadata from a derivation scheme](#detachmetadata)
* [Retrieve metadata from a derivation scheme](#getmetadata)
* [Manual pruning](#pruning)
* [Generate a wallet](#wallet)
* [Node RPC Proxy](#rpc-proxy)
* [Health check](#health)
* [Liquid integration](#liquid)
* [Create group](#create-group)
* [Get group](#get-group)
* [Add group children](#add-group-children)
* [Add address to group](#delete-group-children)
## Configuration
You can check the available settings with `--help`.
NBXplorer can be configured in three way:
* Through command line arguments (eg. `--chains btc`)
* Through environment variables (eg. `NBXPLORER_CHAINS=btc`)
* Through configuration file (eg. `chains=btc`)
If you use configuration file, you can find it on windows in:
```pwsh
C:\Users\<user>\AppData\Roaming\NBXplorer\<network>\settings.config
```
On linux or mac:
```bash
~/.nbxplorer/<network>/settings.config
```
Be careful, if you run NBXplorer with `dotnet run`, you should do it this way, with settings after the `--`:
```bash
dotnet run --no-launch-profile --no-build -c Release -p .\NBXplorer\NBXplorer.csproj -- --chains btc
```
Else, launch profiles, which are settings meant to be used only for debugging time, might be taken into account.
## <a name="tracked-source"></a>Tracked Sources
A tracked source is a generic way to track a set of scripts (addresses) and its UTXOs, transactions, and balances.
### <a name="derivationScheme"></a>Derivation scheme
A derivation scheme, also called `derivationStrategy` in the code, is a flexible way to define how to generate deterministic addresses for a wallet.
NBXplorer will track any addresses on the `0/x`, `1/x` and `x` path.
Here a documentation of the different derivation scheme supported:
| Address type | Format |
| ------------- |-------------|
| P2WPKH | xpub1 |
| P2SH-P2WPKH | xpub1-[p2sh] |
| P2PKH | xpub-[legacy] |
| Multi-sig P2WSH | 2-of-xpub1-xpub2 |
| Multi-sig P2SH-P2WSH | 2-of-xpub1-xpub2-[p2sh] |
| Multi-sig P2SH | 2-of-xpub1-xpub2-[legacy] |
| P2TR | xpub1-[taproot] |
For multisig, the public keys are ordered before generating the address by default for privacy reason, use `-[keeporder]` to disable it.
You can use more than one options at same time, example: `2-of-xpub1-xpub2-[legacy]-[keeporder]`
Most of routes asks for a `cryptoCode`. This identify the crypto currency to request data from. (eg. `BTC`, `LTC`...)
Note: Taproot is incompatible with all other options.
You can create one by calling [Tracking derivation scheme or address](#track).
### <a name="groups"></a>Groups
A group is a tracked source which serves as a logical method for grouping several tracked sources into a single entity. You can add or remove tracked sources to and from a group.
Additionally, specific addresses can be tracked through the group.
Every address attached by a child tracked source will be added to the group, including all related UTXOs and transactions.
A group can have any number of children, and a group can also be a child of another group.
Please note that all the children are returned by [Get a group](#get-group). As such, it is advised not to add too many children to avoid slowing down this call.
A group tracked source's format is `GROUP:groupid`.
You can create a new group by calling [Create a group](#create-group).
### <a name="addresses"></a>Addresses
This refers to a tracked source that monitors a single address. It functions similarly to a group, but with only one specific address to it.
The address tracked source's format is `ADDRESS:bc1...`.
You can create one by calling [Tracking derivation scheme or address](#track).
## Authentication
By default a cookie file is generated when NBXplorer is starting, for windows in:
```pwsh
C:\Users\<user>\AppData\Roaming\NBXplorer\<network>\.cookie
```
On linux or mac:
```bash
~/.nbxplorer/<network>/.cookie
```
The content of this cookie must be used is used as HTTP BASIC authentication to use the API.
This can be disabled with `--noauth`.
Also, NBXPlorer listen by default on `127.0.0.1`, if you want to access it from another machine, run `--bind "0.0.0.0"`.
## <a name="track"></a>Tracking derivation scheme or address
This call add a derivation scheme tracked source, or a address tracked source.
`HTTP POST v1/cryptos/{cryptoCode}/derivations/{derivationScheme}`
`HTTP POST v1/cryptos/{cryptoCode}/addresses/{address}`
Returns nothing.
Optionally, you can attach a json body:
```json
{
"derivationOptions": [
{
"feature": "Deposit",
"minAddresses": 30,
"maxAddresses": null
}
],
"wait": true
}
```
* `wait`: Optional. If `true` the call will return when all addresses has been generated, addresses will be generated in the background (default: `false`)
* `derivationOptions`: Optional. Options to manually start the address generation process. (default: empty)
* `derivationOptions.feature`: Optional. Define to which feature this option should be used. (defaut: null, which match all feature)
* `derivationOptions.minAddresses`: Optional. The minimum addresses that need to be generated with this call. (default: null, make sure the number of address in the pool is between MinGap and MaxGap)
* `derivationOptions.maxAddresses`: Optional. The maximum addresses that need to be generated with this call. (default: null, make sure the number of address in the pool is between MinGap and MaxGap)
## <a name="transactions"></a>Query transactions of tracked sources
To query all transactions of a tracked source:
`HTTP GET v1/cryptos/{cryptoCode}/derivations/{derivationScheme}/transactions`
`HTTP GET v1/cryptos/{cryptoCode}/addresses/{address}/transactions`
`HTTP GET v1/cryptos/{cryptoCode}/groups/{groupId}/transactions`
Optional Parameters:
* `includeTransaction` includes the hex of the transaction, not only information (default: true)
Returns:
```json
{
"height": 104,
"confirmedTransactions": {
"transactions": [
{
"blockHash": "3e7bcca309f92ab78a47c1cdd1166de9190fa49e97165c93e2b10ae1a14b99eb",
"confirmations": 1,
"height": 104,
"transactionId": "cc33dfaf2ed794b11af83dc6e29303e2d8ff9e5e29303153dad1a1d3d8b43e40",
"transaction": "020000000166d6befa387fd646f77a10e4b0f0e66b3569f18a83f77104a0c440e4156f80890000000048473044022064b1398653171440d3e79924cb6593633e7b2c3d80b60a2e21d6c6e287ee785a02203899009df443d0a0a1b06cb970aee0158d35166fd3e26d4e3e85570738e706d101feffffff028c02102401000000160014ee0a1889783da2e1f9bba47be4184b6610efd00400e1f5050000000016001452f88af314ef3b6d03d40a5fd1f2c906188a477567000000",
"outputs": [
{
"keyPath": "0/0",
"scriptPubKey": "001452f88af314ef3b6d03d40a5fd1f2c906188a4775",
"index": 1,
"value": 100000000
}
],
"inputs": [
{
"inputIndex": 0,
"transactionId": "194d6dc4e1c4c983b5235ad2b82cc7c48c36def4960fdcf37697253c9d9854a2",
"scriptPubKey": "001409249118830af97a029217f3a8744973c5a4a02e",
"index": 4,
"value": 90000000,
"address": "bcrt1qpyjfzxyrptuh5q5jzle6sazfw0z6fgpwuz2rye"
},
{
"inputIndex": 1,
"transactionId": "194d6dc4e1c4c983b5235ad2b82cc7c48c36def4960fdcf37697253c9d9854a2",
"scriptPubKey": "0014d83837bd474d799ad4decba4bac561a7356e0371",
"index": 1,
"value": 50000000,
"address": "bcrt1qmqur0028f4ue44x7ewjt43tp5u6kuqm3eqa3ua"
}
],
"timestamp": 1540381888,
"balanceChange": 100000000,
"replaceable": false,
"replacing": null,
"replacedBy": null
}
]
},
"unconfirmedTransactions": {
"transactions": [
{
"blockHash": null,
"confirmations": 0,
"height": null,
"transactionId": "7ec0bcbd3b7685b6bbdb4287a250b64bfcb799dbbbcffa78c00e6cc11185e5f1",
"transaction": null,
"outputs": [
{
"keyPath": "0",
"scriptPubKey": "0014b39fc4eb5c6dd238d39449b70a2e30d575426d99",
"index": 1,
"value": 100000000
}
],
"inputs": [],
"timestamp": 1540381889,
"balanceChange": 100000000,
"replaceable": false,
"replacing": "e070e213a0815b84b4ae96d4d64ce551158524364d3522e7d6bd5415c6c15d3f",
"replacedBy": null
}
]
},
"replacedTransactions": {
"transactions": [
{
"blockHash": null,
"confirmations": 0,
"height": null,
"transactionId": "7ec0bcbd3b7685b6bbdb4287a250b64bfcb799dbbbcffa78c00e6cc11185e5f1",
"transaction": null,
"outputs": [
{
"keyPath": "0",
"scriptPubKey": "0014b39fc4eb5c6dd238d39449b70a2e30d575426d99",
"index": 1,
"value": 100000000
}
],
"inputs": [],
"timestamp": 1540381889,
"balanceChange": 100000000,
"replaceable": false,
"replacing": null,
"replacedBy": "7ec0bcbd3b7685b6bbdb4287a250b64bfcb799dbbbcffa78c00e6cc11185e5f1"
}
]
},
"immatureTransactions": {
"transactions": []
}
}
```
* `inputs`: The spent outputs of this transaction.
* `inputs.inputIndex`: The index of the input in this transaction.
* `replaceable`: `true` if the transaction can be replaced (the transaction has RBF activated, is in the unconfirmed list and is not an intermediate transaction in a chain of unconfirmed transaction)
* `replacing`: Only set in the unconfirmed list, and is pointing to a transaction id in the replaced list.
* `replacedBy`: Only set in the replaced list, and is pointing to a transaction id in the unconfirmed list.
* `immatureTransactions`: Coinbase transactions with less than 100 confirmations.
Note for liquid, `balanceChange` is an array of [AssetMoney](#liquid).
Note that the list of confirmed transaction also include immature transactions.
## <a name="singletransaction"></a>Query specifc transactions of tracked sources
`HTTP GET v1/cryptos/{cryptoCode}/derivations/{derivationScheme}/transactions/{txId}`
`HTTP GET v1/cryptos/{cryptoCode}/addresses/{address}/transactions/{txId}`
`HTTP GET v1/cryptos/{cryptoCode}/groups/{groupId}/transactions/{txId}`
Error codes:
* HTTP 404: Transaction not found
Optional Parameters:
* `includeTransaction` includes the hex of the transaction, not only information (default: true)
Returns:
```json
{
"blockHash": null,
"confirmations": 0,
"height": null,
"transactionId": "7ec0bcbd3b7685b6bbdb4287a250b64bfcb799dbbbcffa78c00e6cc11185e5f1",
"transaction": null,
"outputs": [
{
"scriptPubKey": "0014b39fc4eb5c6dd238d39449b70a2e30d575426d99",
"index": 1,
"value": 100000000
}
],
"inputs": [],
"timestamp": 1540381889,
"balanceChange": 100000000
}
```
## <a name="balance"></a>Get balance of tracked sources
`HTTP GET v1/cryptos/{cryptoCode}/derivations/{derivationScheme}/balance`
`HTTP GET v1/cryptos/{cryptoCode}/addresses/{address}/balance`
`HTTP GET v1/cryptos/{cryptoCode}/groups/{groupId}/balance`
Returns:
```json
{
"unconfirmed": 110000000,
"confirmed": 100000000,
"available": 210000000,
"immature": 0,
"total": 210000000
}
```
Note for liquid, the values are array of [AssetMoney](#liquid).
* `unconfirmed`: How the confirmed balance would be updated once all the unconfirmed transactions were confirmed.
* `confirmed`: The balance of all funds in confirmed transactions.
* `total`: The total of funds owned (ie, `confirmed + unconfirmed`)
* `immature`: The total unspendable funds (ie, coinbase reward which need 100 confirmations before being spendable)
* `available`: The total spendable balance. (ie, `total - immature`)
Immature funds is the sum of UTXO's belonging to a coinbase transaction with less than 100 confirmations.
## <a name="gettransaction"></a>Get a transaction
`HTTP GET v1/cryptos/{cryptoCode}/transactions/{txId}`
Optional Parameters:
* `includeTransaction` includes the hex of the transaction, not only information (default: true)
Error codes:
* HTTP 404: Transaction not found
Returns:
```json
{
"confirmations": 3,
"blockId": "5efa23803df818cd21faa0c11e84db28c8352e76acb93d0c0adfe123db827190",
"transactionHash": "ed86c55b519c26ab4ba8130c976294753934c1f9f6d30203e65bb222648a8cdf",
"transaction": "0200000001205dcde69a5bd2b3281d387e6f125338f9ccb904d94df383ff56d9923599681e000000004847304402200b9d78e01691339acb238d7cd7a40ae620796bdcf8cb167dff4e100b71a2b0950220518e3a955ea7229d57c0160ecf491e8048662d7112fe5feaa312ff71388fda9701feffffff028c02102401000000160014a4ccb74ada7dd01b3018c3308894fea27b4813be00e1f5050000000016001408f86300ddff26ddf779ddce833f7e9e7442156c67000000",
"height": 104,
"timestamp": 1540390804,
"replacedBy": "7ec0bcbd3b7685b6bbdb4287a250b64bfcb799dbbbcffa78c00e6cc11185e5f1"
}
```
`height` and `blockId` will be null if the transaction is not confirmed.
## <a name="status"></a>Get connection status to the chain
`HTTP GET v1/cryptos/{cryptoCode}/status`
Returns:
```json
{
"bitcoinStatus": {
"blocks": 103,
"headers": 103,
"verificationProgress": 1.0,
"isSynched": true,
"incrementalRelayFee": 1,
"minRelayTxFee": 1,
"capabilities": {
"canScanTxoutSet": true,
"canSupportSegwit": true,
"canSupportTaproot": true,
"canSupportTransactionCheck": true
}
},
"isFullySynched": true,
"chainHeight": 103,
"syncHeight": 103,
"networkType": "Regtest",
"cryptoCode": "BTC",
"instanceName": "MyInstance",
"supportedCryptoCodes": [
"BTC"
],
"version": "1.0.3.5"
}
```
`instanceName` can be configured via configuration's key `instancename`.
## <a name="unused"></a>Get a new unused address
`HTTP GET v1/cryptos/{cryptoCode}/derivations/{derivationScheme}/addresses/unused`
Error codes:
* HTTP 404: `cryptoCode-not-supported`
* HTTP 400: `strategy-not-found`
Optional parameters:
* `feature`: Use `Deposit` to get a deposit address (`0/x`), `Change` to get a change address (`1/x`), `Direct` to get `x` or `Custom` if `customKeyPathTemplate` is configured (default: `Deposit`)
* `skip`: How many addresses to skip, needed if the user want multiple unused addresses (default:0)
* `reserve`: Mark the returned address as used (default: false)
Returns:
```json
{
"trackedSource": "DERIVATIONSCHEME:tpubD6NzVbkrYhZ4Wo2RMq8Xbnrorf1xnABkKMS3EGshPkQ3Z4N4GN8uyLuDPvnK7Ekc2FHdXbLvcuZny1gPiohMksFGKmaX3APD2DbTeBWj751-[p2sh]",
"feature": "Deposit",
"derivationStrategy": "tpubD6NzVbkrYhZ4Wo2RMq8Xbnrorf1xnABkKMS3EGshPkQ3Z4N4GN8uyLuDPvnK7Ekc2FHdXbLvcuZny1gPiohMksFGKmaX3APD2DbTeBWj751-[p2sh]",
"keyPath": "0/2",
"scriptPubKey": "a91412cbf6154ef6d9aecf9c978dc2bdc43f1881dd5f87",
"address": "2MtxcVDMiRrJ3V4zfsAwZGbZfPiDUxSXDY2",
"redeem": "0014e2eb89edba1fe6c6c0863699eeb78f6ec3271b45"
}
```
Note: `redeem` is returning the segwit redeem if the derivation scheme is a P2SH-P2WSH or P2WSH, or the p2sh redeem if just a p2sh.
## <a name="scriptPubKey"></a>Get scriptPubKey information of a Derivation Scheme
`HTTP GET v1/cryptos/{cryptoCode}/derivations/{derivationScheme}/scripts/{script}`
Error codes:
* HTTP 404: `cryptoCode-not-supported`
Returns:
```json
{
"trackedSource": "DERIVATIONSCHEME:tpubD6NzVbkrYhZ4WcPozSqALNCrJEt4C45sPDhEBBuokoCeDgjX6YTs4QVvhD9kao6f2uZLqZF4qcXprYyRqooSXr1uPp1KPH1o4m6aw9nxbiA",
"feature": "Deposit",
"derivationStrategy": "tpubD6NzVbkrYhZ4WcPozSqALNCrJEt4C45sPDhEBBuokoCeDgjX6YTs4QVvhD9kao6f2uZLqZF4qcXprYyRqooSXr1uPp1KPH1o4m6aw9nxbiA",
"keyPath": "0/0",
"scriptPubKey": "001460c25d29559774803f262acf5ee5c922eff52ccd",
"address": "tb1qvrp96224ja6gq0ex9t84aewfythl2txdkpdmu0"
}
```
## <a name="utxos"></a>Get available Unspent Transaction Outputs (UTXOs) of tracked sources
`HTTP GET v1/cryptos/{cryptoCode}/derivations/{derivationScheme}/utxos`
`HTTP GET v1/cryptos/{cryptoCode}/addresses/{address}/utxos`
`HTTP GET v1/cryptos/{cryptoCode}/groups/{groupId}/utxos`
Error:
* HTTP 404: `cryptoCode-not-supported`
Result:
```json
{
"trackedSource": "DERIVATIONSCHEME:tpubD6NzVbkrYhZ4XQVi1sSEDBWTcicDqVSCTnYDxpwGwcSZVbPii2b7baRg57YfL64ed36sBRe6GviihHwhy3D1cnBe5uXb27DjrDZCKUA7PQi",
"derivationStrategy": "tpubD6NzVbkrYhZ4XQVi1sSEDBWTcicDqVSCTnYDxpwGwcSZVbPii2b7baRg57YfL64ed36sBRe6GviihHwhy3D1cnBe5uXb27DjrDZCKUA7PQi",
"currentHeight": 107,
"unconfirmed": {
"utxOs": [
{
"feature": "Deposit",
"outpoint": "10ba4bcadd03130b1bd98b0bc7aea9910f871b25b87ec06e484456e84440c88a01000000",
"index": 1,
"transactionHash": "8ac84044e85644486ec07eb8251b870f91a9aec70b8bd91b0b1303ddca4bba10",
"scriptPubKey": "00149681ae465a045e2068460b9d281cf97dede87cd8",
"address": "bcrt1qj6q6u3j6q30zq6zxpwwjs88e0hk7slxcunru7u",
"value": 100000000,
"keyPath": "0/0",
"timestamp": 1540376171,
"confirmations": 0
}
],
"spentOutpoints": [],
"hasChanges": true
},
"confirmed": {
"utxOs": [
{
"feature": "Deposit",
"outpoint": "29ca6590f3f03a6523ad79975392e74e385bf2b7dafe6c537ffa12f9e124348800000000",
"index": 0,
"transactionHash": "883424e1f912fa7f536cfedab7f25b384ee792539779ad23653af0f39065ca29",
"scriptPubKey": "001436a37f2f508650f7074bec4d091fc82bb01cc57f",
"address": "bcrt1qx63h7t6sseg0wp6ta3xsj87g9wcpe3tlgqgnql",
"value": 50000000,
"keyPath": "0/3",
"timestamp": 1540376174,
"confirmations": 1
}
],
"spentOutpoints": [
"9345f9585d643a31202e686ec7a4c2fe17917a5e7731a79d2327d24d25c0339f01000000"
],
"spentUnconfirmed": [
{
"feature": "Deposit",
"outpoint": "c8fd6675624d0b88056b9eaf945c5fd0c4614f7ddf44eb81911b3a66ba0e57a001000000",
"index": 1,
"transactionHash": "a0570eba663a1b9181eb44df7d4f61c4d05f5c94af9e6b05880b4d627566fdc8",
"scriptPubKey": "0014d77089591a85fa3a91e14f587c50e4b777ffd833",
"address": "bcrt1q6acgjkg6shar4y0pfav8c58ykamllkpnz6rnxh",
"value": 100000,
"keyPath": "0/0",
"timestamp": 1699930040,
"confirmations": 0
}
],
"hasChanges": true
},
"hasChanges": true
}
```
Response:
* `confirmed.utxOs`: UTXOs that are confirmed. (UTXO spent by an unconfirmed transaction are also included)
* `unconfirmed.spentOutpoints`: Always empty.
* `unconfirmed.utxOs`: UTXOs that will be confirmed once the unconfirmed transactions are confirmed.
* `unconfirmed.spentOutpoints`: Confirmed UTXOs that will spent once the transactions are confirmed.
* `spentUnconfirmed`: UTXOs that are spent by an unconfirmed transaction.
This call does not returns conflicted unconfirmed UTXOs.
Note that confirmed utxo, do not include immature UTXOs. (ie. UTXOs belonging to a coinbase transaction with less than 100 confirmations)
## <a name="websocket"></a>Notifications via websocket
NBXplorer implements real-time notification via websocket supports for new block or transaction.
`HTTP GET v1/cryptos/{cryptoCode}/connect`
Once you are connected to the websocket, you can subscribe to block notifications by sending the following JSON to it.
```json
{
"type": "subscribeblock",
"data": {
"cryptoCode": "BTC"
}
}
```
Then a notification will be delivered through the websocket when a new block is mined:
```json
{
"type": "newblock",
"eventId": 1,
"data": {
"height": 104,
"hash": "10b0e5178aaf42c4a938f0d37430413b7d76feae14b01fc07e1f23300b8821ce",
"previousBlockHash": "4c6a9c1cadf143c87249519639e86e236feac9d3cea2904e4c42bc5bc32a48a7",
"cryptoCode": "BTC",
"confirmations": 1
}
}
```
For notification concerning `Derivation Scheme` transactions, you can subscribe by sending through the websocket:
```json
{
"type": "subscribetransaction",
"data": {
"cryptoCode": "BTC",
"derivationSchemes": [
"tpubD6NzVbkrYhZ4YL91Ez5fdgaBPQbFhedFdn5gQL4tSCJn1usmHsV1L6VokzLbgcqzh9hiBnfnQANp5BYW15QdFGRKspZVSW1v2QY917RDs1V-[legacy]"
]
}
}
```
Then you will receive such notifications when a transaction is impacting the `derivation scheme`:
```json
{
"type": "newtransaction",
"eventId": 2,
"data": {
"blockId": null,
"trackedSource": "DERIVATIONSCHEME:tpubD6NzVbkrYhZ4X2p2D8kx6XV9V5iCJKMBHuBim1BLnZAZC1JobYkdwSrwF8R74V2oUWkJG3H24LwxnXs9wb6Ksivs2gj4RudMteyVai2AsmA-[p2sh]",
"derivationStrategy": "tpubD6NzVbkrYhZ4X2p2D8kx6XV9V5iCJKMBHuBim1BLnZAZC1JobYkdwSrwF8R74V2oUWkJG3H24LwxnXs9wb6Ksivs2gj4RudMteyVai2AsmA-[p2sh]",
"transactionData": {
"confirmations": 0,
"blockId": null,
"transactionHash": "f135537b40ac7a524273176b60e464b7f279f622031ec53af302d959966d7364",
"transaction": "0200000001dd7f53b09438fed83abe25dd6cdc30ee2092ce8c855cb9e7b0faa38aba8bc0f500000000484730440220093a837ff4be4b64b2ed4625abb128966caad0cb7830cac7af4f615bbf6b52ce02206227a3ddec3fac9e49f414eeab1388d0e67829620ac3a8fb2f4bbfc5b67bd02901feffffff0200e1f5050000000017a91476de0c5d07fd202880672bc702162b7f18e13aca87640210240100000017a9147cfa038496438a6d3c95cfac990f4dffc6cb44f28768000000",
"height": null,
"timestamp": 1540434424
},
"inputs": [
{
"inputIndex": 0,
"transactionId": "194d6dc4e1c4c983b5235ad2b82cc7c48c36def4960fdcf37697253c9d9854a2",
"scriptPubKey": "001409249118830af97a029217f3a8744973c5a4a02e",
"index": 4,
"value": 90000000,
"address": "bcrt1qpyjfzxyrptuh5q5jzle6sazfw0z6fgpwuz2rye"
},
{
"inputIndex": 1,
"transactionId": "194d6dc4e1c4c983b5235ad2b82cc7c48c36def4960fdcf37697253c9d9854a2",
"scriptPubKey": "0014d83837bd474d799ad4decba4bac561a7356e0371",
"index": 1,
"value": 50000000,
"address": "bcrt1qmqur0028f4ue44x7ewjt43tp5u6kuqm3eqa3ua"
}],
"outputs": [
{
"keyPath": "0/1",
"scriptPubKey": "a91476de0c5d07fd202880672bc702162b7f18e13aca87",
"address": "2N45jj76a7YjGLDoKs2mnQ4tt5N7t6R9xoM",
"redeem": "00147d31e1c7959cd047bb7b9b35e4c877a28efe2f0b",
"index": 0,
"value": 100000000
}
],
"cryptoCode": "BTC",
"replacing": ["25d6bc1b2812670550aca8b2984670203b5ebf00e75f9b2bbf1940c3fa27841e", "81a20eb55ec16b92c65d4e142278fd521caa9e5dcad9d941c8e256dbd917ae84"]
}
}
```
If you want all transactions of all derivation schemes of BTC, send this to the WebSocket:
```json
{
"type": "subscribetransaction",
"data": {
"cryptoCode": "BTC"
}
}
```
If you want all transactions of all derivation schemes of all crypto currencies, send this to the WebSocket:
```json
{
"type": "subscribetransaction",
"data": {
"cryptoCode": "*"
}
}
```
As an alternative to get notification, you can also use long polling with the [event stream](#eventStream).
Fields:
* `replacing`: The list of the unconfirmed transactions of this wallet which have been replaced by this new transaction. This can typically be used to detect when the sender is bumping fee. This can't be used to detect when the sender is attempting to abort a transaction.
## <a name="broadcast"></a>Broadcast a transaction
`HTTP POST v1/cryptos/{cryptoCode}/transactions`
Body:
Raw bytes of the transaction.
Parameter:
* `testMempoolAccept`: If `true`, will not attempt to broadcast the transaction but just test its acceptance in the mempool. (default: `false`)
Error codes:
* HTTP 404: `cryptoCode-not-supported`
* HTTP 400: `rpc-unavailable`
* HTTP 400: `not-supported` if `testMempoolAccept` is `true`, but the underlying node does not support it
Returns:
```json
{
"success":false,
"rpcCode":-25,
"rpcCodeMessage":"General error during transaction submission",
"rpcMessage":"Missing inputs"
}
```
## <a name="rescan"></a>Rescan a transaction
NBXplorer does not rescan the whole blockchain when tracking a new derivation scheme.
This means that if the derivation scheme already received UTXOs in the past, NBXplorer will not be aware of it and might reuse addresses already generated in the past, and will not show past transactions.
By using this route, you can ask NBXplorer to rescan specific transactions found in the blockchain.
This way, the transactions and the UTXOs present before tracking the derivation scheme will appear correctly.
`HTTP POST v1/cryptos/{cryptoCode}/rescan`
Body:
```json
{
"transactions":[
// Specify the blockId and transactionId to scan. Your node must not be pruned for this to work.
{
"blockId":"19b44484c79c40d4e74da406e25390348b86a252c1ab784cfd7198c724a0169f",
"transactionId":"f83c7f31e2c39202bbbca619ab354ca8841721cf3440a253e056a7bea43e9745",
},
// Only the transactionId is specified. Your node must run --txindex=1 for this to work
{
"transactionId":"754c14060b958de0ff4e77e2ccdca617964c939d40ec9a01ef21fca2aad78d00",
},
// This will index the transaction without using RPC. Careful: A wrong blockId will corrupt the database.
{
"blockId":"19b44484c79c40d4e74da406e25390348b86a252c1ab784cfd7198c724a0169f",
"transaction":"02000000000101008dd7aaa2fc21ef019aec409d934c9617a6dccce2774effe08d950b06144c750000000000feffffff026c3e2e12010000001600143072110b34b66acd9469b2882d6d57a8ae27183900e1f505000000001600140429b3eebb7d55c50ca36ace12ae874ff2fd16af0247304402202e32739cc6e42877699d4159159941f3cc39027c7626f9962cca9a865816d43502205389e9d6c1a4cab41f2c504413cf0f46a5c1f8814f368e03c9bf1f8017c6787e012103b8858085f2a0c9c906fb793bedb2c115c340de1f7b279d6099f675ddf3eec0bf67000000"
}
]
}
```
Returns:
HTTP 200
Error codes:
* HTTP 400: `rpc-unavailable`
## <a name="feerate"></a>Get fee rate
HTTP GET v1/cryptos/{cryptoCode}/fees/{blockCount}
Get expected fee rate for being confirmed in `blockCount` blocks.
Error codes:
* HTTP 400: `fee-estimation-unavailable`
* HTTP 404: `cryptoCode-not-supported`
* HTTP 400: `rpc-unavailable`
Returns:
```json
{
"feeRate": 5,
"blockCount": 1
}
```
The fee rate is in satoshi/byte.
## <a name="scanUtxoSet"></a>Scan UTXO Set
NBXplorer can scan the UTXO Set for output belonging to your derivationScheme.
`HTTP POST v1/cryptos/BTC/derivations/{derivationScheme}/utxos/scan`
In order to not consume too much RAM, NBXplorer splits the addresses to scan in several `batch` and scan the whole UTXO set sequentially.
Three branches are scanned: 0/x, 1/x and x.
If a UTXO in one branch get found at a specific x, then all addresses inferior to index x will be considered used and not proposed when fetching a new unused address.
Query parameters:
* `batchSize` the number of addresses scanned at once per derivation scheme branch (default: 1000)
* `gapLimit` If no UTXO are detected in this interval, the scan stop (default: 10000)
* `from` the first address index to check (default: 0)
This call queue the request for scanning and returns immediately.
Error codes:
* HTTP 405: `scanutxoset-not-suported` ScanUTXOSet is not supported for this currency
* HTTP 409: `scanutxoset-in-progress` ScanUTXOSet has already been called for this derivationScheme
* HTTP 400: `rpc-unavailable`
## Get scan status
You can poll the status of the scan. Note that if the scan is complete, the result will be kept for 24H.
The state can be:
* `Queued` the demand has been done, but the scan request is queuing to be started
* `Pending` the scan is in progress
* `Complete` the scan is successful
* `Error` the scan errored
```json
{
"error": null,
"queuedAt": 1540439841,
"status": "Pending",
"progress": {
"startedAt": 1540439841,
"completedAt": null,
"found": 2,
"batchNumber": 9,
"remainingBatches": 1,
"currentBatchProgress": 50,
"remainingSeconds": 10,
"overallProgress": 91,
"from": 900,
"count": 100,
"totalSearched": 2700,
"totalSizeOfUTXOSet": null,
"highestKeyIndexFound": {
"change": null,
"deposit": 51,
"direct": null
}
}
}
```
`TotalSizeOfUTXOSet` is set only when the scan is complete.
Error codes:
* HTTP 404 `scanutxoset-info-not-found` if the scan has been done above the last 24H.
## <a name="wipe"></a>Wipe derivation scheme transactions
Wipe all the transactions from a derivation scheme.
`HTTP POST cryptos/{cryptoCode}/derivations/{derivationScheme}/utxos/wipe`
## <a name="eventStream"></a>Query event stream
All notifications sent through websocket are also saved in a crypto specifc event stream.
`HTTP GET v1/cryptos/{cryptoCode}/events`
Query parameters:
* `lastEventId`: Will query all events which happened after this event id, the first event has id 1 (default: 0)
* `longPolling`: If no events have been received since `lastEventId`, the call will block (default: false)
* `limit`: Limit the maximum number of events to return (default: null)
All events are registered in a query stream which you can replay by keeping track of the `lastEventId`.
The smallest `eventId` is 1.
```json
[
{
"eventId": 1,
"type": "newblock",
"data": {
"height": 104,
"hash": "1f31c605c0a5d54b65fa39dc8cb4db025be63c66280279ade9338571a9e63d35",
"previousBlockHash": "7639350b31f3ce07ff976ebae772fef1602b30a10ccb8ca69047fe0fe8b9083c",
"cryptoCode": "BTC",
"confirmations": 1
}
},
{
"eventId": 2,
"type": "newtransaction",
"data": {
"blockId": null,
"trackedSource": "DERIVATIONSCHEME:tpubD6NzVbkrYhZ4XfeFUTn2D4RQ7D5HpvnHywa3eZYhxZBriRTsfe8ZKFSDMcEMBqGrAighxxmq5VUqoRvo7DnNMS5VbJjRHwqDfCAMXLwAL5j",
"derivationStrategy": "tpubD6NzVbkrYhZ4XfeFUTn2D4RQ7D5HpvnHywa3eZYhxZBriRTsfe8ZKFSDMcEMBqGrAighxxmq5VUqoRvo7DnNMS5VbJjRHwqDfCAMXLwAL5j",
"transactionData": {
"confirmations": 0,
"blockId": null,
"transactionHash": "500359d971698c021587ea952bd38bd57dafc2b99615f71f7f978af394682737",
"transaction": "0200000001b8af58c5dbed4bd0ea60ae8ba7e68e66143440b8c1c69b6eaaf719566676ab1b0000000048473044022040b419aeb9042a53fb2d03abec911901ed42fc50d6a143e322bc61d51e4e35a9022073c10fe827b53332d50fbde581e36ad31f57b98ec35a125562dc8c739762ec8901feffffff028c02102401000000160014b6bedaf0cb795c01a1e427bd7752d6ef058964f100e1f50500000000160014c5e0b07f40b8dbe69b22864d84d83d5b4120835368000000",
"height": null,
"timestamp": 1542703963
},
"outputs": [
{
"keyPath": "0/0",
"scriptPubKey": "0014c5e0b07f40b8dbe69b22864d84d83d5b41208353",
"address": "bcrt1qchstql6qhrd7dxezsexcfkpatdqjpq6nntvtrd",
"index": 1,
"value": 100000000
}
],
"cryptoCode": "BTC",
}
}
]
```
## <a name="eventStreamLatest"></a>Query event stream (from most recent)
Exact same as [event stream](#eventStream) but it returns a maximum number `#limit` of the most recent events.
`HTTP GET v1/cryptos/{cryptoCode}/events/latest`
Query parameters:
* `limit`: Limit the maximum number of events to return (default: 10)
## <a name="psbt"></a>Create Partially Signed Bitcoin Transaction
Create a [Partially Signed Bitcoin Transaction](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki) (PSBT).
A PSBT is a standard format to represent a transaction with pending signatures associated to it.
A PSBT can be signed independently by many signers, and combined together before broadcast.
`HTTP POST v1/cryptos/{cryptoCode}/derivations/{derivationScheme}/psbt/create`
Error codes:
* HTTP 400: `not-enough-funds`
* HTTP 400: `output-too-small` (if the output on which the `substractFee=true` is too small to cover the fees)
* HTTP 400: `fee-estimation-unavailable`
* HTTP 404: `cryptoCode-not-supported`
Fields:
```json
{
"seed": 1,
"rbf": false,
"version": 1,
"timeLock": 512000,
"includeGlobalXPub": false,
"explicitChangeAddress": "mu5kevv6FiLygJfVvxQnB4hArXCUArMC7C",
"destinations": [
{
"destination": "mu5kevv6FiLygJfVvxQnB4hArXCUArMC7C",
"amount": 50000000,
"substractFees": false,
"sweepAll": false
}
],
"feePreference": {
"explicitFeeRate": 10,
"explicitFee": 23000,
"blockTarget": 1,
"fallbackFeeRate": 100
},
"discourageFeeSniping": true,
"reserveChangeAddress": false,
"spendAllMatchingOutpoints": false,
"minConfirmations": 0,
"excludeOutpoints": [
"7c02d7d6923ab5e9bbdadf7cf6873a5454ae5aa86d15308ed8d68840a79cf644-1",
"7c02d7d6923ab5e9bbdadf7cf6873a5454ae5aa86d15308ed8d68840a79cf644-2"
],
"includeOnlyOutpoints": [ "7c02d7d6923ab5e9bbdadf7cf6873a5454ae5aa86d15308ed8d68840a79cf644-1" ],
"minValue": 1000,
"rebaseKeyPaths": [
{
"accountKey": "tpubD6NzVbkrYhZ4XfeFUTn2D4RQ7D5HpvnHywa3eZYhxZBriRTsfe8ZKFSDMcEMBqGrAighxxmq5VUqoRvo7DnNMS5VbJjRHwqDfCAMXLwAL5j",
"accountKeyPath": "ab5ed9ab/49'/0'/0'"
}
],
"disableFingerprintRandomization": false,
"alwaysIncludeNonWitnessUTXO": false,
"mergeOutputs": true
}
```
* `seed`: Optional, default to null, a seed to specific to get a deterministic PSBT (useful for tests)
* `version`: Optional, the version of the transaction (default: 1, if `disableFingerprintRandomization` is `true`)
* `timeLock`: Optional, The timelock of the transaction, activate RBF if not null (default: 0, if `disableFingerprintRandomization` is `true`)
* `includeGlobalXPub`: Optional. Whether or not to include the global xpubs of the derivation scheme in the PSBT. (default: false)
* `rbf`: Optional, determine if the transaction should have Replace By Fee (RBF) activated (default: `true`, if `disableFingerprintRandomization` is `true`)
* `reserveChangeAddress`: default to false, whether the creation of this PSBT will reserve a new change address.
* `spendAllMatchingOutpoints`: If `true`, all the UTXOs that have been selected will be used as input in the PSBT. (default to false)