turing-wallet-provider 1.4.15 → 1.4.17
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 +455 -182
- package/dist/context/TuringWalletContext.d.ts +1 -1
- package/dist/types/providerTypes.d.ts +16 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -267,352 +267,543 @@ 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;
|
|
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
|
+
|
|
658
|
+
```ts
|
|
659
|
+
const params = [
|
|
660
|
+
{
|
|
661
|
+
flag: "FTLP_MERGE", // 必填
|
|
662
|
+
nft_contract_address: "", // 必填,PoolNFT 合约地址
|
|
663
|
+
poolNFT_version: 2, // 可选,强制为 2
|
|
664
|
+
lockTime: 0, // 可选,手动设置解锁参数到最大可解锁区块高度。如果启用了锁定但没有此参数,解锁参数将自动设置为(当前区块高度 - 2)
|
|
665
|
+
domain: "", // 可选
|
|
666
|
+
},
|
|
667
|
+
];
|
|
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
|
+
|
|
598
725
|
```ts
|
|
599
726
|
const params = [
|
|
600
727
|
{
|
|
601
|
-
flag: "
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
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: "", // 可选
|
|
606
735
|
},
|
|
607
736
|
];
|
|
608
|
-
|
|
609
|
-
|
|
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
|
|
613
802
|
|
|
614
803
|
批量请求功能支持一次性提交多个独立的请求,每个请求独立执行,一个请求失败不会影响其他请求的执行。
|
|
615
804
|
|
|
805
|
+
此外,当 `signMessage` 请求需要依赖 `signAssociatedTransaction` 的结果时,可以通过 `dependsOn` 字段将两者关联,详见下方[关联请求](#关联请求)章节。
|
|
806
|
+
|
|
616
807
|
**限制:** 单次批量请求最多支持 5 个请求。
|
|
617
808
|
|
|
618
809
|
### 支持的方法
|
|
@@ -728,6 +919,88 @@ const mixedOperations = [
|
|
|
728
919
|
const results = await wallet.sendBatchRequest(mixedOperations);
|
|
729
920
|
```
|
|
730
921
|
|
|
922
|
+
### 关联请求
|
|
923
|
+
|
|
924
|
+
在某些场景下,`signMessage` 的消息体中需要包含 `signAssociatedTransaction` 生成的交易 txid。由于 txid 需要从签名后的 `txraws` 中计算得出,无法提前填写,因此可以在 `signMessage` 请求上添加 `dependsOn` 字段,让钱包自动完成 txid 的计算和注入。
|
|
925
|
+
|
|
926
|
+
不添加 `dependsOn` 时,`signAssociatedTransaction` 和 `signMessage` 仍然作为独立请求各自执行,互不影响。
|
|
927
|
+
|
|
928
|
+
#### 用法
|
|
929
|
+
|
|
930
|
+
批量请求固定为两个请求:第一个是 `signAssociatedTransaction`,第二个是 `signMessage`。在 `signMessage` 上添加 `dependsOn` 字段,指定将 txids 注入到消息 JSON 的哪个字段名即可。
|
|
931
|
+
|
|
932
|
+
```ts
|
|
933
|
+
const requests = [
|
|
934
|
+
{
|
|
935
|
+
method: "signAssociatedTransaction",
|
|
936
|
+
params: {
|
|
937
|
+
sourceTxraw: "...",
|
|
938
|
+
sourceUtxos: [
|
|
939
|
+
{
|
|
940
|
+
txId: "",
|
|
941
|
+
outputIndex: 0,
|
|
942
|
+
satoshis: 500,
|
|
943
|
+
script: ftcode,
|
|
944
|
+
scriptSigType: "tbc20",
|
|
945
|
+
},
|
|
946
|
+
{
|
|
947
|
+
txId: "",
|
|
948
|
+
outputIndex: 2,
|
|
949
|
+
satoshis: 10000,
|
|
950
|
+
script: p2pkh,
|
|
951
|
+
scriptSigType: "p2pkh",
|
|
952
|
+
},
|
|
953
|
+
],
|
|
954
|
+
inputs: [
|
|
955
|
+
[
|
|
956
|
+
{ outputIndex: 0, scriptSigType: "tbc20" },
|
|
957
|
+
{ outputIndex: 2, scriptSigType: "p2pkh" },
|
|
958
|
+
],
|
|
959
|
+
],
|
|
960
|
+
outputs: [
|
|
961
|
+
[
|
|
962
|
+
{ script: ftcode, satoshis: 500 },
|
|
963
|
+
{ script: fttape, satoshis: 0 },
|
|
964
|
+
{ script: p2pkh, satoshis: 8000 },
|
|
965
|
+
],
|
|
966
|
+
],
|
|
967
|
+
},
|
|
968
|
+
},
|
|
969
|
+
{
|
|
970
|
+
method: "signMessage",
|
|
971
|
+
params: {
|
|
972
|
+
message: JSON.stringify({
|
|
973
|
+
action: "mint",
|
|
974
|
+
amount: 100,
|
|
975
|
+
}),
|
|
976
|
+
encoding: "utf8",
|
|
977
|
+
},
|
|
978
|
+
dependsOn: "txids", // 将 txids 注入到 message JSON 的 "txids" 字段
|
|
979
|
+
},
|
|
980
|
+
];
|
|
981
|
+
|
|
982
|
+
const results = await wallet.sendBatchRequest(requests);
|
|
983
|
+
|
|
984
|
+
// results[0] => signAssociatedTransaction 的结果: { txraws: string[] }
|
|
985
|
+
// results[1] => signMessage 的结果: { address, pubkey, sig, message }
|
|
986
|
+
// 其中 message 为包含 txids 的完整 JSON,例如:
|
|
987
|
+
// { "action": "mint", "amount": 100, "txids": ["txid1", "txid2", ...] }
|
|
988
|
+
```
|
|
989
|
+
|
|
990
|
+
#### 执行流程
|
|
991
|
+
|
|
992
|
+
1. 执行 `signAssociatedTransaction`,得到 `txraws`
|
|
993
|
+
2. 从 `txraws` 计算出 txid 数组
|
|
994
|
+
3. 解析 `signMessage` 的 `message` JSON,将 txid 数组注入到 `dependsOn` 指定的字段
|
|
995
|
+
4. 使用注入后的完整消息执行 `signMessage`
|
|
996
|
+
|
|
997
|
+
#### 约束
|
|
998
|
+
|
|
999
|
+
- 批量请求必须恰好包含两个请求:第一个为 `signAssociatedTransaction`,第二个为 `signMessage`
|
|
1000
|
+
- `dependsOn` 的值为字符串,表示注入到 message JSON 中的字段名
|
|
1001
|
+
- 如果 `signAssociatedTransaction` 执行失败,`signMessage` 也会失败
|
|
1002
|
+
- `signMessage` 的 `message` 参数必须是合法的 JSON 字符串
|
|
1003
|
+
|
|
731
1004
|
## evm.sendTransaction
|
|
732
1005
|
|
|
733
1006
|
通过 `evm` 对象发送 EVM 链上的交易,支持原生币和 ERC20 标准代币转账。
|
|
@@ -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 = {
|
|
@@ -150,6 +157,7 @@ export type BatchRequestMethod =
|
|
|
150
157
|
export type BatchRequest = {
|
|
151
158
|
method: BatchRequestMethod;
|
|
152
159
|
params: SendTransaction | SignMessage | SignTransaction | SignAssociatedTransaction | Encrypt | Decrypt;
|
|
160
|
+
dependsOn?: string;
|
|
153
161
|
};
|
|
154
162
|
|
|
155
163
|
export type BatchResponse = Array<
|