turing-wallet-provider 1.4.14 → 1.4.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +580 -182
- package/dist/context/TuringWalletContext.d.ts +1 -1
- package/dist/types/providerTypes.d.ts +60 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -267,346 +267,535 @@ const { txraws } = await wallet.signAssociatedTransaction(params);
|
|
|
267
267
|
|
|
268
268
|
## sendTransaction
|
|
269
269
|
|
|
270
|
+
使用钱包发送交易。支持多种交易类型,包括 P2PKH、NFT 操作、FT 操作和 PoolNFT 操作。
|
|
271
|
+
|
|
272
|
+
### 接口定义
|
|
273
|
+
|
|
270
274
|
```ts
|
|
271
275
|
interface FTData {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
276
|
+
name: string;
|
|
277
|
+
symbol: string;
|
|
278
|
+
decimal: number;
|
|
279
|
+
amount: number | string; // 大数请使用 string
|
|
280
|
+
}
|
|
277
281
|
|
|
278
282
|
interface CollectionData {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
283
|
+
collectionName: string;
|
|
284
|
+
description: string;
|
|
285
|
+
supply: number;
|
|
286
|
+
file: string; // base64
|
|
287
|
+
}
|
|
284
288
|
|
|
285
289
|
interface NFTData {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
interface RequestParam
|
|
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
|
-
|
|
290
|
+
nftName: string;
|
|
291
|
+
symbol: string;
|
|
292
|
+
description: string;
|
|
293
|
+
attributes: string;
|
|
294
|
+
file?: string; // base64
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
interface RequestParam {
|
|
298
|
+
flag: "P2PKH" | "COLLECTION_CREATE" | "NFT_CREATE" | "NFT_TRANSFER" | "FT_MINT" | "FT_TRANSFER" | "FT_MERGE" | "POOLNFT_MINT" | "POOLNFT_INIT" | "POOLNFT_LP_INCREASE" | "POOLNFT_LP_CONSUME" | "POOLNFT_LP_BURN" | "POOLNFT_SWAP_TO_TOKEN" | "POOLNFT_SWAP_TO_TBC" | "POOLNFT_MERGE" | "FTLP_MERGE" | "STABLECOIN_CREATE" | "STABLECOIN_MINT" | "STABLECOIN_TRANSFER" | "STABLECOIN_FREEZE" | "STABLECOIN_UNFREEZE" | "STABLECOIN_MERGE";
|
|
299
|
+
address?: string;
|
|
300
|
+
satoshis?: number | string; // 单位为 satoshis,大数请使用 string
|
|
301
|
+
collection_data?: string;
|
|
302
|
+
ft_data?: string;
|
|
303
|
+
nft_data?: string;
|
|
304
|
+
collection_id?: string;
|
|
305
|
+
nft_contract_address?: string;
|
|
306
|
+
ft_contract_address?: string; // FT 或稳定币合约交易 ID(稳定币的合约 ID 为 STABLECOIN_CREATE 返回的第一个 txid)
|
|
307
|
+
tbc_amount?: number | string; // 大数请使用 string
|
|
308
|
+
ft_amount?: number | string; // 大数请使用 string
|
|
309
|
+
merge_times?: number;
|
|
310
|
+
with_lock?: boolean;
|
|
311
|
+
lpCostAddress?: string;
|
|
312
|
+
lpCostAmount?: number | string; // 大数请使用 string
|
|
313
|
+
pubKeyLock?: string[];
|
|
314
|
+
poolNFT_version?: 1 | 2; // 强制为 2,若提供为别的值转为 2
|
|
315
|
+
serviceFeeRate?: number;
|
|
316
|
+
serverProvider_tag?: string;
|
|
317
|
+
lpPlan?: 1 | 2; // 默认 1
|
|
318
|
+
domain?: string;
|
|
319
|
+
isLockTime?: boolean;
|
|
320
|
+
lockTime?: number | string; // 锁仓至指定区块高度(POOLNFT 相关),或冻结至指定 unix 时间戳(STABLECOIN_FREEZE),大数请使用 string
|
|
321
|
+
broadcastEnabled?: boolean;
|
|
322
|
+
mint_message?: string; // 铸造/增发跨链信息(STABLECOIN_CREATE / STABLECOIN_MINT 使用)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const params = [param: RequestParam];
|
|
321
326
|
```
|
|
322
327
|
|
|
328
|
+
### 返回值
|
|
329
|
+
|
|
330
|
+
- `txid` - 交易 ID(当 `broadcastEnabled` 为 `true` 时)
|
|
331
|
+
- `txraw` - 交易原始字符串(当 `broadcastEnabled` 为 `false` 时)
|
|
332
|
+
- `error` - 错误对象(发生错误时)
|
|
333
|
+
|
|
323
334
|
### P2PKH
|
|
324
335
|
|
|
336
|
+
发送标准 P2PKH 交易。
|
|
337
|
+
|
|
325
338
|
```ts
|
|
326
339
|
const params = [
|
|
327
340
|
{
|
|
328
|
-
flag: "P2PKH",
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
broadcastEnabled
|
|
332
|
-
domain
|
|
341
|
+
flag: "P2PKH", // 必填
|
|
342
|
+
address: "", // 必填,接收地址
|
|
343
|
+
satoshis: 0, // 必填,转账金额,单位:聪
|
|
344
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
345
|
+
domain: "", // 可选,默认 api.turingbitchain.io
|
|
333
346
|
},
|
|
334
347
|
];
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
//const {
|
|
348
|
+
|
|
349
|
+
const { txid } = await wallet.sendTransaction(params); // broadcastEnabled 为 true 时
|
|
350
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
351
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
338
352
|
```
|
|
339
353
|
|
|
340
354
|
### COLLECTION_CREATE
|
|
341
355
|
|
|
356
|
+
创建新的 NFT 集合。
|
|
357
|
+
|
|
342
358
|
```ts
|
|
343
359
|
const params = [
|
|
344
360
|
{
|
|
345
|
-
flag: "COLLECTION_CREATE",
|
|
346
|
-
collection_data: "",
|
|
347
|
-
broadcastEnabled
|
|
348
|
-
domain
|
|
361
|
+
flag: "COLLECTION_CREATE", // 必填
|
|
362
|
+
collection_data: "", // 必填,JSON 格式的 CollectionData
|
|
363
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
364
|
+
domain: "", // 可选
|
|
349
365
|
},
|
|
350
366
|
];
|
|
367
|
+
|
|
351
368
|
const { txid } = await wallet.sendTransaction(params);
|
|
352
|
-
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false
|
|
353
|
-
//const { error } = await wallet.sendTransaction(params)
|
|
369
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
370
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
354
371
|
```
|
|
355
372
|
|
|
356
373
|
### NFT_CREATE
|
|
357
374
|
|
|
375
|
+
创建新的 NFT。
|
|
376
|
+
|
|
358
377
|
```ts
|
|
359
378
|
const params = [
|
|
360
379
|
{
|
|
361
|
-
flag: "NFT_CREATE",
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
broadcastEnabled
|
|
365
|
-
domain
|
|
380
|
+
flag: "NFT_CREATE", // 必填
|
|
381
|
+
collection_id: "", // 必填,集合 ID
|
|
382
|
+
nft_data: "", // 必填,JSON 格式的 NFTData
|
|
383
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
384
|
+
domain: "", // 可选
|
|
366
385
|
},
|
|
367
386
|
];
|
|
387
|
+
|
|
368
388
|
const { txid } = await wallet.sendTransaction(params);
|
|
369
|
-
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false
|
|
370
|
-
//const { error } = await wallet.sendTransaction(params)
|
|
389
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
390
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
371
391
|
```
|
|
372
392
|
|
|
373
393
|
### NFT_TRANSFER
|
|
374
394
|
|
|
395
|
+
将 NFT 转移到另一个地址。
|
|
396
|
+
|
|
375
397
|
```ts
|
|
376
398
|
const params = [
|
|
377
399
|
{
|
|
378
|
-
flag: "NFT_TRANSFER",
|
|
379
|
-
nft_contract_address: "",
|
|
380
|
-
address: "",
|
|
381
|
-
broadcastEnabled
|
|
382
|
-
domain
|
|
400
|
+
flag: "NFT_TRANSFER", // 必填
|
|
401
|
+
nft_contract_address: "", // 必填,NFT 合约地址
|
|
402
|
+
address: "", // 必填,接收地址
|
|
403
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
404
|
+
domain: "", // 可选
|
|
383
405
|
},
|
|
384
406
|
];
|
|
407
|
+
|
|
385
408
|
const { txid } = await wallet.sendTransaction(params);
|
|
386
|
-
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false
|
|
387
|
-
//const { error } = await wallet.sendTransaction(params)
|
|
409
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
410
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
388
411
|
```
|
|
389
412
|
|
|
390
413
|
### FT_MINT
|
|
391
414
|
|
|
415
|
+
铸造同质化代币。
|
|
416
|
+
|
|
392
417
|
```ts
|
|
393
418
|
const params = [
|
|
394
419
|
{
|
|
395
|
-
flag: "FT_MINT",
|
|
396
|
-
ft_data: "",
|
|
397
|
-
broadcastEnabled
|
|
398
|
-
domain
|
|
420
|
+
flag: "FT_MINT", // 必填
|
|
421
|
+
ft_data: "", // 必填,JSON 格式的 FTData
|
|
422
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
423
|
+
domain: "", // 可选
|
|
399
424
|
},
|
|
400
425
|
];
|
|
426
|
+
|
|
401
427
|
const { txid } = await wallet.sendTransaction(params);
|
|
402
|
-
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false
|
|
403
|
-
//const { error } = await wallet.sendTransaction(params)
|
|
428
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时,返回的 txraw 有两个,用逗号隔开,需批量广播,保证前面的 txraw 先广播
|
|
429
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
404
430
|
```
|
|
405
431
|
|
|
406
432
|
### FT_TRANSFER
|
|
407
433
|
|
|
434
|
+
转移同质化代币。
|
|
435
|
+
|
|
408
436
|
```ts
|
|
409
437
|
const params = [
|
|
410
438
|
{
|
|
411
|
-
flag: "FT_TRANSFER",
|
|
412
|
-
ft_contract_address: "",
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
tbc_amount
|
|
416
|
-
broadcastEnabled
|
|
417
|
-
domain
|
|
439
|
+
flag: "FT_TRANSFER", // 必填
|
|
440
|
+
ft_contract_address: "", // 必填,FT 合约地址
|
|
441
|
+
address: "", // 必填,接收地址
|
|
442
|
+
ft_amount: 0, // 必填,转移的 FT 数量
|
|
443
|
+
tbc_amount: 0, // 可选,同时转移 TBC 的数量,默认 0
|
|
444
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
445
|
+
domain: "", // 可选
|
|
418
446
|
},
|
|
419
447
|
];
|
|
448
|
+
|
|
420
449
|
const { txid } = await wallet.sendTransaction(params);
|
|
421
|
-
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false
|
|
422
|
-
//const { error } = await wallet.sendTransaction(params)
|
|
450
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
451
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
423
452
|
```
|
|
424
453
|
|
|
425
454
|
### FT_MERGE
|
|
426
455
|
|
|
456
|
+
合并 FT UTXO。
|
|
457
|
+
|
|
427
458
|
```ts
|
|
428
459
|
const params = [
|
|
429
460
|
{
|
|
430
|
-
flag: "FT_MERGE",
|
|
431
|
-
ft_contract_address: "",
|
|
432
|
-
domain
|
|
461
|
+
flag: "FT_MERGE", // 必填
|
|
462
|
+
ft_contract_address: "", // 必填,FT 合约地址
|
|
463
|
+
domain: "", // 可选
|
|
433
464
|
},
|
|
434
465
|
];
|
|
435
|
-
|
|
436
|
-
|
|
466
|
+
|
|
467
|
+
const { txid } = await wallet.sendTransaction(params); // txid 为多个 Merge 交易的 txid,用逗号隔开
|
|
468
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
437
469
|
```
|
|
438
470
|
|
|
439
471
|
### POOLNFT_MINT
|
|
440
472
|
|
|
473
|
+
铸造 PoolNFT。
|
|
474
|
+
|
|
441
475
|
```ts
|
|
442
476
|
const params = [
|
|
443
477
|
{
|
|
444
|
-
flag: "POOLNFT_MINT",
|
|
445
|
-
ft_contract_address: "",
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
serviceFeeRate
|
|
449
|
-
with_lock
|
|
450
|
-
pubKeyLock
|
|
451
|
-
lpCostAddress
|
|
452
|
-
lpCostAmount
|
|
453
|
-
lpPlan
|
|
454
|
-
isLockTime
|
|
455
|
-
broadcastEnabled
|
|
456
|
-
domain
|
|
478
|
+
flag: "POOLNFT_MINT", // 必填
|
|
479
|
+
ft_contract_address: "", // 必填,FT 合约地址
|
|
480
|
+
serverProvider_tag: "", // 必填,服务提供商标签
|
|
481
|
+
poolNFT_version: 2, // 可选,强制为 2
|
|
482
|
+
serviceFeeRate: 25, // 可选,0-100 整数,默认 25
|
|
483
|
+
with_lock: false, // 可选,默认 false;为 true 时创建带哈希锁的池子
|
|
484
|
+
pubKeyLock: ["pubkey1", "pubkey2"], // with_lock 为 true 时必填
|
|
485
|
+
lpCostAddress: "", // with_lock 为 true 时必填,扣除流动性添加成本的地址
|
|
486
|
+
lpCostAmount: 0, // with_lock 为 true 时必填,扣除流动性添加成本的 TBC 数量
|
|
487
|
+
lpPlan: 1, // 可选,1 或 2,默认 1
|
|
488
|
+
isLockTime: false, // 可选,默认 false
|
|
489
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
490
|
+
domain: "", // 可选
|
|
457
491
|
},
|
|
458
492
|
];
|
|
493
|
+
|
|
459
494
|
const { txid } = await wallet.sendTransaction(params);
|
|
460
|
-
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false
|
|
461
|
-
//const { error } = await wallet.sendTransaction(params)
|
|
495
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时,返回的 txraw 有两个,用逗号隔开,需批量广播,保证前面的 txraw 先广播
|
|
496
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
462
497
|
```
|
|
463
498
|
|
|
464
499
|
### POOLNFT_INIT
|
|
465
500
|
|
|
501
|
+
初始化 PoolNFT 池。
|
|
502
|
+
|
|
466
503
|
```ts
|
|
467
504
|
const params = [
|
|
468
505
|
{
|
|
469
|
-
flag: "POOLNFT_INIT",
|
|
470
|
-
nft_contract_address: "",
|
|
471
|
-
address: "",
|
|
472
|
-
tbc_amount:
|
|
473
|
-
ft_amount:
|
|
474
|
-
poolNFT_version
|
|
475
|
-
lockTime
|
|
476
|
-
broadcastEnabled
|
|
477
|
-
domain
|
|
506
|
+
flag: "POOLNFT_INIT", // 必填
|
|
507
|
+
nft_contract_address: "", // 必填,PoolNFT 合约地址
|
|
508
|
+
address: "", // 必填,接收地址
|
|
509
|
+
tbc_amount: 0, // 必填,初始注入的 TBC 数量
|
|
510
|
+
ft_amount: 0, // 必填,初始注入的 FT 数量
|
|
511
|
+
poolNFT_version: 2, // 可选,强制为 2
|
|
512
|
+
lockTime: 0, // 可选,锁定到指定的区块高度
|
|
513
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
514
|
+
domain: "", // 可选
|
|
478
515
|
},
|
|
479
516
|
];
|
|
517
|
+
|
|
480
518
|
const { txid } = await wallet.sendTransaction(params);
|
|
481
|
-
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false
|
|
482
|
-
//const { error } = await wallet.sendTransaction(params)
|
|
519
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
520
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
483
521
|
```
|
|
484
522
|
|
|
485
523
|
### POOLNFT_LP_INCREASE
|
|
486
524
|
|
|
525
|
+
增加 PoolNFT 池中的流动性。
|
|
526
|
+
|
|
487
527
|
```ts
|
|
488
528
|
const params = [
|
|
489
529
|
{
|
|
490
|
-
flag: "POOLNFT_LP_INCREASE",
|
|
491
|
-
nft_contract_address: "",
|
|
492
|
-
address: "",
|
|
493
|
-
tbc_amount:
|
|
494
|
-
poolNFT_version
|
|
495
|
-
lockTime
|
|
496
|
-
broadcastEnabled
|
|
497
|
-
domain
|
|
530
|
+
flag: "POOLNFT_LP_INCREASE", // 必填
|
|
531
|
+
nft_contract_address: "", // 必填,PoolNFT 合约地址
|
|
532
|
+
address: "", // 必填,接收地址
|
|
533
|
+
tbc_amount: 0, // 必填,增加的 TBC 数量
|
|
534
|
+
poolNFT_version: 2, // 可选,强制为 2
|
|
535
|
+
lockTime: 0, // 可选,锁定到指定的区块高度
|
|
536
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
537
|
+
domain: "", // 可选
|
|
498
538
|
},
|
|
499
539
|
];
|
|
540
|
+
|
|
500
541
|
const { txid } = await wallet.sendTransaction(params);
|
|
501
|
-
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false
|
|
502
|
-
//const { error } = await wallet.sendTransaction(params)
|
|
542
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
543
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
503
544
|
```
|
|
504
545
|
|
|
505
546
|
### POOLNFT_LP_CONSUME
|
|
506
547
|
|
|
548
|
+
从 PoolNFT 池中消耗流动性。
|
|
549
|
+
|
|
507
550
|
```ts
|
|
508
551
|
const params = [
|
|
509
552
|
{
|
|
510
|
-
flag: "POOLNFT_LP_CONSUME",
|
|
511
|
-
nft_contract_address: "",
|
|
512
|
-
address: "",
|
|
513
|
-
ft_amount:
|
|
514
|
-
poolNFT_version
|
|
515
|
-
lockTime
|
|
516
|
-
broadcastEnabled
|
|
517
|
-
domain
|
|
553
|
+
flag: "POOLNFT_LP_CONSUME", // 必填
|
|
554
|
+
nft_contract_address: "", // 必填,PoolNFT 合约地址
|
|
555
|
+
address: "", // 必填,接收地址
|
|
556
|
+
ft_amount: 0, // 必填,消耗的 FT LP 数量
|
|
557
|
+
poolNFT_version: 2, // 可选,强制为 2
|
|
558
|
+
lockTime: 0, // 可选,手动设置解锁参数到最大可解锁区块高度。如果启用了锁定但没有此参数,解锁参数将自动设置为(当前区块高度 - 2)
|
|
559
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
560
|
+
domain: "", // 可选
|
|
518
561
|
},
|
|
519
562
|
];
|
|
563
|
+
|
|
520
564
|
const { txid } = await wallet.sendTransaction(params);
|
|
521
|
-
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false
|
|
522
|
-
//const { error } = await wallet.sendTransaction(params)
|
|
565
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
566
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
523
567
|
```
|
|
524
568
|
|
|
525
569
|
### POOLNFT_LP_BURN
|
|
526
570
|
|
|
571
|
+
从 PoolNFT 池中销毁流动性。
|
|
572
|
+
|
|
527
573
|
```ts
|
|
528
574
|
const params = [
|
|
529
575
|
{
|
|
530
|
-
flag: "POOLNFT_LP_BURN",
|
|
531
|
-
nft_contract_address: "",
|
|
532
|
-
poolNFT_version
|
|
533
|
-
broadcastEnabled
|
|
534
|
-
domain
|
|
576
|
+
flag: "POOLNFT_LP_BURN", // 必填
|
|
577
|
+
nft_contract_address: "", // 必填,PoolNFT 合约地址
|
|
578
|
+
poolNFT_version: 2, // 可选,强制为 2
|
|
579
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
580
|
+
domain: "", // 可选
|
|
535
581
|
},
|
|
536
582
|
];
|
|
583
|
+
|
|
537
584
|
const { txid } = await wallet.sendTransaction(params);
|
|
538
|
-
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false
|
|
539
|
-
//const { error } = await wallet.sendTransaction(params)
|
|
585
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
586
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
540
587
|
```
|
|
541
588
|
|
|
542
589
|
### POOLNFT_SWAP_TO_TOKEN
|
|
543
590
|
|
|
591
|
+
在 PoolNFT 池中将 TBC 交换为代币。
|
|
592
|
+
|
|
544
593
|
```ts
|
|
545
594
|
const params = [
|
|
546
595
|
{
|
|
547
|
-
flag: "POOLNFT_SWAP_TO_TOKEN",
|
|
548
|
-
nft_contract_address: "",
|
|
549
|
-
address: "",
|
|
550
|
-
tbc_amount:
|
|
551
|
-
poolNFT_version
|
|
552
|
-
lpPlan
|
|
553
|
-
broadcastEnabled
|
|
554
|
-
domain
|
|
596
|
+
flag: "POOLNFT_SWAP_TO_TOKEN", // 必填
|
|
597
|
+
nft_contract_address: "", // 必填,PoolNFT 合约地址
|
|
598
|
+
address: "", // 必填,接收地址
|
|
599
|
+
tbc_amount: 0, // 必填,用于交换的 TBC 数量
|
|
600
|
+
poolNFT_version: 2, // 可选,强制为 2
|
|
601
|
+
lpPlan: 1, // 可选,1 或 2,默认 1
|
|
602
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
603
|
+
domain: "", // 可选
|
|
555
604
|
},
|
|
556
605
|
];
|
|
606
|
+
|
|
557
607
|
const { txid } = await wallet.sendTransaction(params);
|
|
558
|
-
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false
|
|
559
|
-
//const { error } = await wallet.sendTransaction(params)
|
|
608
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
609
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
560
610
|
```
|
|
561
611
|
|
|
562
612
|
### POOLNFT_SWAP_TO_TBC
|
|
563
613
|
|
|
614
|
+
在 PoolNFT 池中将代币交换为 TBC。
|
|
615
|
+
|
|
564
616
|
```ts
|
|
565
|
-
const params = [
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
617
|
+
const params = [
|
|
618
|
+
{
|
|
619
|
+
flag: "POOLNFT_SWAP_TO_TBC", // 必填
|
|
620
|
+
nft_contract_address: "", // 必填,PoolNFT 合约地址
|
|
621
|
+
address: "", // 必填,接收地址
|
|
622
|
+
ft_amount: 0, // 必填,用于交换的 FT 数量
|
|
623
|
+
poolNFT_version: 2, // 可选,强制为 2
|
|
624
|
+
lpPlan: 1, // 可选,1 或 2,默认 1
|
|
625
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
626
|
+
domain: "", // 可选
|
|
627
|
+
},
|
|
628
|
+
];
|
|
629
|
+
|
|
575
630
|
const { txid } = await wallet.sendTransaction(params);
|
|
576
|
-
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false
|
|
577
|
-
//const { error } = await wallet.sendTransaction(params)
|
|
631
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
632
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
578
633
|
```
|
|
579
634
|
|
|
580
635
|
### POOLNFT_MERGE
|
|
581
636
|
|
|
637
|
+
合并 PoolNFT 交易。
|
|
638
|
+
|
|
582
639
|
```ts
|
|
583
640
|
const params = [
|
|
584
641
|
{
|
|
585
|
-
flag: "POOLNFT_MERGE",
|
|
586
|
-
nft_contract_address: "",
|
|
587
|
-
poolNFT_version
|
|
588
|
-
merge_times
|
|
589
|
-
domain
|
|
642
|
+
flag: "POOLNFT_MERGE", // 必填
|
|
643
|
+
nft_contract_address: "", // 必填,PoolNFT 合约地址
|
|
644
|
+
poolNFT_version: 2, // 可选,强制为 2
|
|
645
|
+
merge_times: 10, // 可选,1-10 次,默认 10 次,不足时提前终止
|
|
646
|
+
domain: "", // 可选
|
|
590
647
|
},
|
|
591
648
|
];
|
|
592
|
-
|
|
593
|
-
|
|
649
|
+
|
|
650
|
+
const { txid } = await wallet.sendTransaction(params); // txid 为多个 Merge 交易的 txid,用逗号隔开
|
|
651
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
594
652
|
```
|
|
595
653
|
|
|
596
654
|
### FTLP_MERGE
|
|
597
655
|
|
|
656
|
+
合并 FTLP 交易。
|
|
657
|
+
|
|
598
658
|
```ts
|
|
599
659
|
const params = [
|
|
600
660
|
{
|
|
601
|
-
flag: "FTLP_MERGE",
|
|
602
|
-
nft_contract_address: "",
|
|
603
|
-
poolNFT_version
|
|
604
|
-
lockTime
|
|
605
|
-
domain
|
|
661
|
+
flag: "FTLP_MERGE", // 必填
|
|
662
|
+
nft_contract_address: "", // 必填,PoolNFT 合约地址
|
|
663
|
+
poolNFT_version: 2, // 可选,强制为 2
|
|
664
|
+
lockTime: 0, // 可选,手动设置解锁参数到最大可解锁区块高度。如果启用了锁定但没有此参数,解锁参数将自动设置为(当前区块高度 - 2)
|
|
665
|
+
domain: "", // 可选
|
|
606
666
|
},
|
|
607
667
|
];
|
|
608
|
-
|
|
609
|
-
|
|
668
|
+
|
|
669
|
+
const { txid } = await wallet.sendTransaction(params); // txid 为多个 Merge 交易的 txid,用逗号隔开
|
|
670
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
### STABLECOIN_CREATE
|
|
674
|
+
|
|
675
|
+
发行稳定币合约(仅需执行一次)。稳定币继承自 FT,构造方式与 FT 相同。
|
|
676
|
+
|
|
677
|
+
```ts
|
|
678
|
+
const params = [
|
|
679
|
+
{
|
|
680
|
+
flag: "STABLECOIN_CREATE", // 必填
|
|
681
|
+
ft_data: JSON.stringify({ // 必填,JSON 格式的 FTData
|
|
682
|
+
name: "USD Test",
|
|
683
|
+
symbol: "USDT",
|
|
684
|
+
decimal: 6,
|
|
685
|
+
amount: 100000000,
|
|
686
|
+
}),
|
|
687
|
+
address: "", // 必填,初始接收地址(一般是管理员自身)
|
|
688
|
+
mint_message: "SourceChain: BSC, TXID: 34434...", // 必填,跨链信息,起始链名称和交易 id
|
|
689
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
690
|
+
domain: "", // 可选
|
|
691
|
+
},
|
|
692
|
+
];
|
|
693
|
+
|
|
694
|
+
const { txid } = await wallet.sendTransaction(params); // txid 有两个,用逗号隔开,第一个 txid 即为稳定币合约 ID
|
|
695
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时,返回的 txraw 有两个,用逗号隔开,第一个 txraw 对应的 txid 即为稳定币合约 ID,需批量广播,保证前面的 txraw 先广播
|
|
696
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
### STABLECOIN_MINT
|
|
700
|
+
|
|
701
|
+
增发稳定币(仅管理员可操作)。
|
|
702
|
+
|
|
703
|
+
```ts
|
|
704
|
+
const params = [
|
|
705
|
+
{
|
|
706
|
+
flag: "STABLECOIN_MINT", // 必填
|
|
707
|
+
ft_contract_address: "", // 必填,稳定币合约交易 ID(STABLECOIN_CREATE 返回的第一个 txid)
|
|
708
|
+
address: "", // 必填,接收新铸稳定币的地址
|
|
709
|
+
ft_amount: 50000, // 必填,增发数量,大数请使用 string
|
|
710
|
+
mint_message: "SourceChain: BSC, TXID: 34434...", // 必填,跨链信息,起始链名称和交易 id
|
|
711
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
712
|
+
domain: "", // 可选
|
|
713
|
+
},
|
|
714
|
+
];
|
|
715
|
+
|
|
716
|
+
const { txid } = await wallet.sendTransaction(params);
|
|
717
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
718
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
### STABLECOIN_TRANSFER
|
|
722
|
+
|
|
723
|
+
转移稳定币。
|
|
724
|
+
|
|
725
|
+
```ts
|
|
726
|
+
const params = [
|
|
727
|
+
{
|
|
728
|
+
flag: "STABLECOIN_TRANSFER", // 必填
|
|
729
|
+
ft_contract_address: "", // 必填,稳定币合约交易 ID(STABLECOIN_CREATE 返回的第一个 txid)
|
|
730
|
+
address: "", // 必填,接收地址
|
|
731
|
+
ft_amount: 1000, // 必填,转移数量,大数请使用 string
|
|
732
|
+
tbc_amount: 0, // 可选,同时转 TBC 和稳定币时设置此值
|
|
733
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
734
|
+
domain: "", // 可选
|
|
735
|
+
},
|
|
736
|
+
];
|
|
737
|
+
|
|
738
|
+
const { txid } = await wallet.sendTransaction(params);
|
|
739
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
740
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
### STABLECOIN_FREEZE
|
|
744
|
+
|
|
745
|
+
冻结指定地址的稳定币 UTXO(仅管理员可操作)。冻结后,持有者须等到冻结到期才能使用该 UTXO。
|
|
746
|
+
|
|
747
|
+
```ts
|
|
748
|
+
const params = [
|
|
749
|
+
{
|
|
750
|
+
flag: "STABLECOIN_FREEZE", // 必填
|
|
751
|
+
ft_contract_address: "", // 必填,稳定币合约交易 ID(STABLECOIN_CREATE 返回的第一个 txid)
|
|
752
|
+
address: "", // 必填,被冻结的目标地址
|
|
753
|
+
lockTime: 1774410989, // 必填,冻结至指定 unix 时间戳
|
|
754
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
755
|
+
domain: "", // 可选
|
|
756
|
+
},
|
|
757
|
+
];
|
|
758
|
+
|
|
759
|
+
const { txid } = await wallet.sendTransaction(params);
|
|
760
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
761
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
762
|
+
```
|
|
763
|
+
|
|
764
|
+
### STABLECOIN_UNFREEZE
|
|
765
|
+
|
|
766
|
+
解冻指定地址的稳定币 UTXO(仅管理员可操作)。
|
|
767
|
+
|
|
768
|
+
```ts
|
|
769
|
+
const params = [
|
|
770
|
+
{
|
|
771
|
+
flag: "STABLECOIN_UNFREEZE", // 必填
|
|
772
|
+
ft_contract_address: "", // 必填,稳定币合约交易 ID(STABLECOIN_CREATE 返回的第一个 txid)
|
|
773
|
+
address: "", // 必填,被解冻的目标地址
|
|
774
|
+
broadcastEnabled: true, // 可选,默认 true
|
|
775
|
+
domain: "", // 可选
|
|
776
|
+
},
|
|
777
|
+
];
|
|
778
|
+
|
|
779
|
+
const { txid } = await wallet.sendTransaction(params);
|
|
780
|
+
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
781
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
### STABLECOIN_MERGE
|
|
785
|
+
|
|
786
|
+
合并稳定币 UTXO(要求所有 coinutxo 均已上链)。
|
|
787
|
+
|
|
788
|
+
```ts
|
|
789
|
+
const params = [
|
|
790
|
+
{
|
|
791
|
+
flag: "STABLECOIN_MERGE", // 必填
|
|
792
|
+
ft_contract_address: "", // 必填,稳定币合约交易 ID(STABLECOIN_CREATE 返回的第一个 txid)
|
|
793
|
+
domain: "", // 可选
|
|
794
|
+
},
|
|
795
|
+
];
|
|
796
|
+
|
|
797
|
+
const { txid } = await wallet.sendTransaction(params); // txid 为多个 Merge 交易的 txid,用逗号隔开
|
|
798
|
+
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
610
799
|
```
|
|
611
800
|
|
|
612
801
|
## sendBatchRequest
|
|
@@ -831,3 +1020,212 @@ if (result.txraw) {
|
|
|
831
1020
|
// 可以自行广播这个交易
|
|
832
1021
|
}
|
|
833
1022
|
```
|
|
1023
|
+
|
|
1024
|
+
## btc.sendTransaction
|
|
1025
|
+
|
|
1026
|
+
通过 `btc` 对象发送 BTC 链上的交易。
|
|
1027
|
+
|
|
1028
|
+
### 参数说明
|
|
1029
|
+
|
|
1030
|
+
```ts
|
|
1031
|
+
interface BtcSendTransaction {
|
|
1032
|
+
toAddress: string; // 接收地址
|
|
1033
|
+
amount: string; // 转账金额,字符串格式,单位为 satoshis
|
|
1034
|
+
broadcastEnabled?: boolean; // 是否广播交易,默认为 true
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
interface BtcSendTransactionResponse {
|
|
1038
|
+
txid?: string; // 交易哈希(广播成功时返回)
|
|
1039
|
+
txraw?: string; // 交易原始数据(broadcastEnabled为false时返回)
|
|
1040
|
+
error?: string; // 错误信息
|
|
1041
|
+
}
|
|
1042
|
+
```
|
|
1043
|
+
|
|
1044
|
+
### 使用示例
|
|
1045
|
+
|
|
1046
|
+
#### 转账 BTC
|
|
1047
|
+
|
|
1048
|
+
```ts
|
|
1049
|
+
const wallet = useTuringWallet();
|
|
1050
|
+
|
|
1051
|
+
const result = await wallet.btc.sendTransaction({
|
|
1052
|
+
toAddress: "bc1qxyz...",
|
|
1053
|
+
amount: "100000", // 100000 satoshis
|
|
1054
|
+
broadcastEnabled: true,
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1057
|
+
if (result.txid) {
|
|
1058
|
+
console.log("交易哈希:", result.txid);
|
|
1059
|
+
} else if (result.error) {
|
|
1060
|
+
console.error("交易失败:", result.error);
|
|
1061
|
+
}
|
|
1062
|
+
```
|
|
1063
|
+
|
|
1064
|
+
#### 不广播,仅返回签名交易
|
|
1065
|
+
|
|
1066
|
+
```ts
|
|
1067
|
+
const wallet = useTuringWallet();
|
|
1068
|
+
|
|
1069
|
+
const result = await wallet.btc.sendTransaction({
|
|
1070
|
+
toAddress: "bc1qxyz...",
|
|
1071
|
+
amount: "100000",
|
|
1072
|
+
broadcastEnabled: false,
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
if (result.txraw) {
|
|
1076
|
+
console.log("交易原始数据:", result.txraw);
|
|
1077
|
+
}
|
|
1078
|
+
```
|
|
1079
|
+
|
|
1080
|
+
## btc.signTransaction
|
|
1081
|
+
|
|
1082
|
+
通过 `btc` 对象对单个 BTC 裸交易进行签名,支持 legacy、segwit_v0、taproot 三种签名类型。taproot 类型下通过 `leafHashesHex` 区分 key path 和 script path:对应输入为 `undefined` 则走 key path,有值则走 script path。
|
|
1083
|
+
|
|
1084
|
+
### 参数说明
|
|
1085
|
+
|
|
1086
|
+
```ts
|
|
1087
|
+
type BtcSigHashType = "legacy" | "segwit_v0" | "taproot";
|
|
1088
|
+
|
|
1089
|
+
interface BtcSignTransaction {
|
|
1090
|
+
txHex: string; // 裸交易 hex
|
|
1091
|
+
type: BtcSigHashType; // 签名哈希类型
|
|
1092
|
+
prevOutScriptsHex: string[]; // 每个输入对应的前置输出脚本 hex
|
|
1093
|
+
values?: number[]; // 每个输入对应的金额(satoshis),segwit_v0/taproot 必填
|
|
1094
|
+
leafHashesHex?: (string | undefined)[]; // 每个输入对应的叶子哈希,仅 taproot 类型使用,undefined 表示 key path,有值表示 script path
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
interface BtcSignTransactionResponse {
|
|
1098
|
+
sigs?: string[]; // 每个输入对应的签名 hex
|
|
1099
|
+
error?: string; // 错误信息
|
|
1100
|
+
}
|
|
1101
|
+
```
|
|
1102
|
+
|
|
1103
|
+
### 使用示例
|
|
1104
|
+
|
|
1105
|
+
#### Legacy (P2PKH) 签名
|
|
1106
|
+
|
|
1107
|
+
```ts
|
|
1108
|
+
const wallet = useTuringWallet();
|
|
1109
|
+
|
|
1110
|
+
const result = await wallet.btc.signTransaction({
|
|
1111
|
+
txHex: "0200000001...",
|
|
1112
|
+
type: "legacy",
|
|
1113
|
+
prevOutScriptsHex: ["76a914...88ac"],
|
|
1114
|
+
});
|
|
1115
|
+
|
|
1116
|
+
if (result.sigs) {
|
|
1117
|
+
console.log("签名列表:", result.sigs);
|
|
1118
|
+
} else if (result.error) {
|
|
1119
|
+
console.error("签名失败:", result.error);
|
|
1120
|
+
}
|
|
1121
|
+
```
|
|
1122
|
+
|
|
1123
|
+
#### SegWit V0 (P2WPKH) 签名
|
|
1124
|
+
|
|
1125
|
+
```ts
|
|
1126
|
+
const wallet = useTuringWallet();
|
|
1127
|
+
|
|
1128
|
+
const result = await wallet.btc.signTransaction({
|
|
1129
|
+
txHex: "0200000001...",
|
|
1130
|
+
type: "segwit_v0",
|
|
1131
|
+
prevOutScriptsHex: ["76a914...88ac"],
|
|
1132
|
+
values: [100000],
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1135
|
+
if (result.sigs) {
|
|
1136
|
+
console.log("签名列表:", result.sigs);
|
|
1137
|
+
}
|
|
1138
|
+
```
|
|
1139
|
+
|
|
1140
|
+
#### Taproot Key Path 签名
|
|
1141
|
+
|
|
1142
|
+
```ts
|
|
1143
|
+
const wallet = useTuringWallet();
|
|
1144
|
+
|
|
1145
|
+
const result = await wallet.btc.signTransaction({
|
|
1146
|
+
txHex: "0200000001...",
|
|
1147
|
+
type: "taproot",
|
|
1148
|
+
prevOutScriptsHex: ["5120..."],
|
|
1149
|
+
values: [100000],
|
|
1150
|
+
// leafHashesHex 不传或对应位置为 undefined,走 key path
|
|
1151
|
+
});
|
|
1152
|
+
|
|
1153
|
+
if (result.sigs) {
|
|
1154
|
+
console.log("签名列表:", result.sigs);
|
|
1155
|
+
}
|
|
1156
|
+
```
|
|
1157
|
+
|
|
1158
|
+
#### Taproot Script Path 签名
|
|
1159
|
+
|
|
1160
|
+
```ts
|
|
1161
|
+
const wallet = useTuringWallet();
|
|
1162
|
+
|
|
1163
|
+
const result = await wallet.btc.signTransaction({
|
|
1164
|
+
txHex: "0200000001...",
|
|
1165
|
+
type: "taproot",
|
|
1166
|
+
prevOutScriptsHex: ["5120..."],
|
|
1167
|
+
values: [100000],
|
|
1168
|
+
leafHashesHex: ["ab12cd34..."], // 对应输入有 leafHash,走 script path
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1171
|
+
if (result.sigs) {
|
|
1172
|
+
console.log("签名列表:", result.sigs);
|
|
1173
|
+
}
|
|
1174
|
+
```
|
|
1175
|
+
|
|
1176
|
+
## btc.sendBatchRequest
|
|
1177
|
+
|
|
1178
|
+
通过 `btc` 对象批量提交 BTC 相关请求,每个请求独立执行,一个失败不影响其他请求。
|
|
1179
|
+
|
|
1180
|
+
### 支持的方法
|
|
1181
|
+
|
|
1182
|
+
- `sendTransaction` - 发送交易
|
|
1183
|
+
- `signTransaction` - 签名交易
|
|
1184
|
+
|
|
1185
|
+
### 参数说明
|
|
1186
|
+
|
|
1187
|
+
```ts
|
|
1188
|
+
type BtcBatchRequestMethod = "sendTransaction" | "signTransaction";
|
|
1189
|
+
|
|
1190
|
+
interface BtcBatchRequest {
|
|
1191
|
+
method: BtcBatchRequestMethod;
|
|
1192
|
+
params: BtcSendTransaction | BtcSignTransaction;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
type BtcBatchResponse = Array<BtcSendTransactionResponse | BtcSignTransactionResponse>;
|
|
1196
|
+
```
|
|
1197
|
+
|
|
1198
|
+
### 使用示例
|
|
1199
|
+
|
|
1200
|
+
```ts
|
|
1201
|
+
const wallet = useTuringWallet();
|
|
1202
|
+
|
|
1203
|
+
const requests = [
|
|
1204
|
+
{
|
|
1205
|
+
method: "sendTransaction",
|
|
1206
|
+
params: {
|
|
1207
|
+
toAddress: "bc1qxyz...",
|
|
1208
|
+
amount: "100000",
|
|
1209
|
+
broadcastEnabled: true,
|
|
1210
|
+
},
|
|
1211
|
+
},
|
|
1212
|
+
{
|
|
1213
|
+
method: "signTransaction",
|
|
1214
|
+
params: {
|
|
1215
|
+
txHex: "0200000001...",
|
|
1216
|
+
type: "legacy",
|
|
1217
|
+
prevOutScriptsHex: ["76a914...88ac"],
|
|
1218
|
+
},
|
|
1219
|
+
},
|
|
1220
|
+
];
|
|
1221
|
+
|
|
1222
|
+
const results = await wallet.btc.sendBatchRequest(requests);
|
|
1223
|
+
|
|
1224
|
+
results.forEach((result, index) => {
|
|
1225
|
+
if (result.error) {
|
|
1226
|
+
console.error(`Request ${index + 1} failed:`, result.error);
|
|
1227
|
+
} else {
|
|
1228
|
+
console.log(`Request ${index + 1} success:`, result);
|
|
1229
|
+
}
|
|
1230
|
+
});
|
|
1231
|
+
```
|
|
@@ -33,12 +33,18 @@ export type TransactionFlag =
|
|
|
33
33
|
| "POOLNFT_SWAP_TO_TOKEN"
|
|
34
34
|
| "POOLNFT_SWAP_TO_TBC"
|
|
35
35
|
| "POOLNFT_MERGE"
|
|
36
|
-
| "FTLP_MERGE"
|
|
36
|
+
| "FTLP_MERGE"
|
|
37
|
+
| "STABLECOIN_CREATE"
|
|
38
|
+
| "STABLECOIN_MINT"
|
|
39
|
+
| "STABLECOIN_TRANSFER"
|
|
40
|
+
| "STABLECOIN_FREEZE"
|
|
41
|
+
| "STABLECOIN_UNFREEZE"
|
|
42
|
+
| "STABLECOIN_MERGE";
|
|
37
43
|
|
|
38
44
|
|
|
39
45
|
export type SendTransaction = {
|
|
40
46
|
flag: TransactionFlag;
|
|
41
|
-
satoshis?: number;
|
|
47
|
+
satoshis?: number | string;
|
|
42
48
|
address?: string;
|
|
43
49
|
collection_data?: string;
|
|
44
50
|
ft_data?: string;
|
|
@@ -46,21 +52,22 @@ export type SendTransaction = {
|
|
|
46
52
|
collection_id?: string;
|
|
47
53
|
nft_contract_address?: string;
|
|
48
54
|
ft_contract_address?: string;
|
|
49
|
-
tbc_amount?: number;
|
|
50
|
-
ft_amount?: number;
|
|
55
|
+
tbc_amount?: number | string;
|
|
56
|
+
ft_amount?: number | string;
|
|
51
57
|
merge_times?: number;
|
|
52
58
|
with_lock?: boolean;
|
|
53
59
|
lpCostAddress?: string;
|
|
54
|
-
lpCostAmount?: number;
|
|
60
|
+
lpCostAmount?: number | string;
|
|
55
61
|
pubKeyLock?: string[];
|
|
56
|
-
poolNFT_version?:
|
|
62
|
+
poolNFT_version?: 1 | 2;
|
|
57
63
|
serviceFeeRate?: number;
|
|
58
64
|
serviceProvider_flag?: string;
|
|
59
|
-
lpPlan?:
|
|
65
|
+
lpPlan?: 1 | 2;
|
|
60
66
|
domain?: string;
|
|
61
67
|
isLockTime?: boolean;
|
|
62
|
-
lockTime?: number;
|
|
68
|
+
lockTime?: number | string;
|
|
63
69
|
broadcastEnabled?: boolean;
|
|
70
|
+
mint_message?: string;
|
|
64
71
|
};
|
|
65
72
|
|
|
66
73
|
export type SendTransactionResponse = {
|
|
@@ -179,6 +186,50 @@ export type EvmProvider = {
|
|
|
179
186
|
sendTransaction: (params: EvmSendTransaction) => Promise<EvmSendTransactionResponse | undefined>;
|
|
180
187
|
};
|
|
181
188
|
|
|
189
|
+
export type BtcSendTransaction = {
|
|
190
|
+
toAddress: string;
|
|
191
|
+
amount: string;
|
|
192
|
+
broadcastEnabled?: boolean;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export type BtcSendTransactionResponse = {
|
|
196
|
+
txid?: string;
|
|
197
|
+
txraw?: string;
|
|
198
|
+
error?: string;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export type BtcSigHashType = "legacy" | "segwit_v0" | "taproot";
|
|
202
|
+
|
|
203
|
+
export type BtcSignTransaction = {
|
|
204
|
+
txHex: string;
|
|
205
|
+
type: BtcSigHashType;
|
|
206
|
+
prevOutScriptsHex: string[];
|
|
207
|
+
values?: number[];
|
|
208
|
+
leafHashesHex?: (string | undefined)[];
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export type BtcSignTransactionResponse = {
|
|
212
|
+
sigs?: string[];
|
|
213
|
+
error?: string;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export type BtcBatchRequestMethod = "sendTransaction" | "signTransaction";
|
|
217
|
+
|
|
218
|
+
export type BtcBatchRequest = {
|
|
219
|
+
method: BtcBatchRequestMethod;
|
|
220
|
+
params: BtcSendTransaction | BtcSignTransaction;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export type BtcBatchResponse = Array<
|
|
224
|
+
BtcSendTransactionResponse | BtcSignTransactionResponse
|
|
225
|
+
>;
|
|
226
|
+
|
|
227
|
+
export type BtcProvider = {
|
|
228
|
+
sendTransaction: (params: BtcSendTransaction) => Promise<BtcSendTransactionResponse | undefined>;
|
|
229
|
+
signTransaction: (params: BtcSignTransaction) => Promise<BtcSignTransactionResponse | undefined>;
|
|
230
|
+
sendBatchRequest: (requests: BtcBatchRequest[]) => Promise<BtcBatchResponse | undefined>;
|
|
231
|
+
};
|
|
232
|
+
|
|
182
233
|
export type TuringProviderType = {
|
|
183
234
|
isReady: boolean;
|
|
184
235
|
connect: () => Promise<ConnectResponse | undefined>;
|
|
@@ -203,4 +254,5 @@ export type TuringProviderType = {
|
|
|
203
254
|
) => Promise<SignAssociatedTransactionResponse | undefined>;
|
|
204
255
|
sendBatchRequest: (requests: BatchRequest[]) => Promise<BatchResponse | undefined>;
|
|
205
256
|
evm: EvmProvider;
|
|
257
|
+
btc: BtcProvider;
|
|
206
258
|
};
|