turing-wallet-provider 1.4.12 → 1.4.14
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 +120 -4
- package/dist/types/providerTypes.d.ts +26 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,21 +18,25 @@ root.render(
|
|
|
18
18
|
import { useTuringWallet } from "turing-wallet-provider";
|
|
19
19
|
|
|
20
20
|
const wallet = useTuringWallet();
|
|
21
|
-
await wallet.connect();
|
|
21
|
+
const addresses = await wallet.connect();
|
|
22
|
+
// 返回地址对象,根据账户类型不同返回不同字段:
|
|
23
|
+
// BVM账户: { tbcAddress, btcAddress }
|
|
24
|
+
// EVM账户: { ethAddress, bnbAddress }
|
|
25
|
+
// 全部账户: { tbcAddress, btcAddress, ethAddress, bnbAddress }
|
|
22
26
|
```
|
|
23
27
|
|
|
24
28
|
## disconnect
|
|
25
29
|
|
|
26
30
|
```ts
|
|
27
31
|
const wallet = useTuringWallet();
|
|
28
|
-
await wallet.disconnect();
|
|
32
|
+
const result = await wallet.disconnect(); // 返回 true/false
|
|
29
33
|
```
|
|
30
34
|
|
|
31
35
|
## isConnected
|
|
32
36
|
|
|
33
37
|
```ts
|
|
34
38
|
const wallet = useTuringWallet();
|
|
35
|
-
const
|
|
39
|
+
const result = await wallet.isConnected(); // 返回 true/false
|
|
36
40
|
```
|
|
37
41
|
|
|
38
42
|
## getPubKey
|
|
@@ -46,7 +50,11 @@ const { tbcPubKey } = await wallet.getPubKey(); //tbcPubKey为string类型
|
|
|
46
50
|
|
|
47
51
|
```ts
|
|
48
52
|
const wallet = useTuringWallet();
|
|
49
|
-
const
|
|
53
|
+
const addresses = await wallet.getAddress();
|
|
54
|
+
// 返回地址对象,根据账户类型不同返回不同字段:
|
|
55
|
+
// BVM账户: { tbcAddress, btcAddress }
|
|
56
|
+
// EVM账户: { ethAddress, bnbAddress }
|
|
57
|
+
// 全部账户: { tbcAddress, btcAddress, ethAddress, bnbAddress }
|
|
50
58
|
```
|
|
51
59
|
|
|
52
60
|
## getInfo
|
|
@@ -386,10 +394,12 @@ const params = [
|
|
|
386
394
|
{
|
|
387
395
|
flag: "FT_MINT",
|
|
388
396
|
ft_data: "",
|
|
397
|
+
broadcastEnabled?:true,
|
|
389
398
|
domain?: "",
|
|
390
399
|
},
|
|
391
400
|
];
|
|
392
401
|
const { txid } = await wallet.sendTransaction(params);
|
|
402
|
+
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false 这里返回的txraw有两个,用逗号隔开,需批量广播,保证前面的txraw先广播
|
|
393
403
|
//const { error } = await wallet.sendTransaction(params);构建或广播交易时出现错误
|
|
394
404
|
```
|
|
395
405
|
|
|
@@ -442,10 +452,12 @@ const params = [
|
|
|
442
452
|
lpCostAmount?: 5, //设置添加流动性扣款TBC数量
|
|
443
453
|
lpPlan?: 1, //默认值为1
|
|
444
454
|
isLockTime?: false, //是否具备锁仓功能 默认为false
|
|
455
|
+
broadcastEnabled?:true,
|
|
445
456
|
domain?: "",
|
|
446
457
|
},
|
|
447
458
|
];
|
|
448
459
|
const { txid } = await wallet.sendTransaction(params);
|
|
460
|
+
//const { txraw } = await wallet.sendTransaction(params);broadcastEnabled为false 这里返回的txraw有两个,用逗号隔开,需批量广播,保证前面的txraw先广播
|
|
449
461
|
//const { error } = await wallet.sendTransaction(params);构建或广播交易时出现错误
|
|
450
462
|
```
|
|
451
463
|
|
|
@@ -715,3 +727,107 @@ const mixedOperations = [
|
|
|
715
727
|
|
|
716
728
|
const results = await wallet.sendBatchRequest(mixedOperations);
|
|
717
729
|
```
|
|
730
|
+
|
|
731
|
+
## evm.sendTransaction
|
|
732
|
+
|
|
733
|
+
通过 `evm` 对象发送 EVM 链上的交易,支持原生币和 ERC20 标准代币转账。
|
|
734
|
+
|
|
735
|
+
> **当前支持范围:**
|
|
736
|
+
>
|
|
737
|
+
> - 支持链: 以太坊主网(ETH)、BSC 主网(BNB)
|
|
738
|
+
> - 支持代币: USDT、USDC
|
|
739
|
+
|
|
740
|
+
### 参数说明
|
|
741
|
+
|
|
742
|
+
```ts
|
|
743
|
+
interface EvmSendTransaction {
|
|
744
|
+
chainId: number; // EVM 链 ID: 1(以太坊主网) 或 56(BSC主网)
|
|
745
|
+
contractAddress?: string; // ERC20 合约地址,如果为空则转账原生币(ETH/BNB)
|
|
746
|
+
toAddress: string; // 接收地址
|
|
747
|
+
amount: string; // 转账金额,字符串格式,单位为 token 的最小单位
|
|
748
|
+
broadcastEnabled?: boolean; // 是否广播交易,默认为 true
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
interface EvmSendTransactionResponse {
|
|
752
|
+
txid?: string; // 交易哈希(广播成功时返回)
|
|
753
|
+
txraw?: string; // 交易原始数据(broadcastEnabled为false时返回)
|
|
754
|
+
error?: string; // 错误信息
|
|
755
|
+
}
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
### 支持的链和代币
|
|
759
|
+
|
|
760
|
+
| 链 | chainId | 原生币 | USDT 合约地址 | USDC 合约地址 |
|
|
761
|
+
| ---------- | ------- | ------ | ------------------------------------------ | ------------------------------------------ |
|
|
762
|
+
| 以太坊主网 | 1 | ETH | 0xdAC17F958D2ee523a2206206994597C13D831ec7 | 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 |
|
|
763
|
+
| BSC 主网 | 56 | BNB | 0x55d398326f99059fF775485246999027B3197955 | 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d |
|
|
764
|
+
|
|
765
|
+
### 使用示例
|
|
766
|
+
|
|
767
|
+
#### 转账原生币
|
|
768
|
+
|
|
769
|
+
```ts
|
|
770
|
+
const wallet = useTuringWallet();
|
|
771
|
+
|
|
772
|
+
// 以太坊转账 ETH
|
|
773
|
+
const result = await wallet.evm.sendTransaction({
|
|
774
|
+
chainId: 1,
|
|
775
|
+
toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
|
|
776
|
+
amount: "1000000000000000000", // 1 ETH (18位小数)
|
|
777
|
+
broadcastEnabled: true,
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
if (result.txid) {
|
|
781
|
+
console.log("交易哈希:", result.txid);
|
|
782
|
+
} else if (result.error) {
|
|
783
|
+
console.error("交易失败:", result.error);
|
|
784
|
+
}
|
|
785
|
+
```
|
|
786
|
+
|
|
787
|
+
#### 转账 ERC20 代币
|
|
788
|
+
|
|
789
|
+
```ts
|
|
790
|
+
const wallet = useTuringWallet();
|
|
791
|
+
|
|
792
|
+
// BSC 上转账 USDT
|
|
793
|
+
const result = await wallet.evm.sendTransaction({
|
|
794
|
+
chainId: 56,
|
|
795
|
+
contractAddress: "0x55d398326f99059fF775485246999027B3197955", // BSC USDT 合约
|
|
796
|
+
toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
|
|
797
|
+
amount: "1000000000000000000", // 1 USDT (18位小数)
|
|
798
|
+
broadcastEnabled: true,
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
// 以太坊主网转账 USDC
|
|
802
|
+
const result2 = await wallet.evm.sendTransaction({
|
|
803
|
+
chainId: 1,
|
|
804
|
+
contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // ETH USDC 合约
|
|
805
|
+
toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
|
|
806
|
+
amount: "1000000", // 1 USDC (6位小数)
|
|
807
|
+
broadcastEnabled: true,
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
if (result.txid) {
|
|
811
|
+
console.log("交易哈希:", result.txid);
|
|
812
|
+
} else if (result.error) {
|
|
813
|
+
console.error("交易失败:", result.error);
|
|
814
|
+
}
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
#### 不广播,仅返回签名交易
|
|
818
|
+
|
|
819
|
+
```ts
|
|
820
|
+
const wallet = useTuringWallet();
|
|
821
|
+
|
|
822
|
+
const result = await wallet.evm.sendTransaction({
|
|
823
|
+
chainId: 1,
|
|
824
|
+
toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
|
|
825
|
+
amount: "1000000000000000000",
|
|
826
|
+
broadcastEnabled: false, // 不广播
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
if (result.txraw) {
|
|
830
|
+
console.log("交易原始数据:", result.txraw);
|
|
831
|
+
// 可以自行广播这个交易
|
|
832
|
+
}
|
|
833
|
+
```
|
|
@@ -3,9 +3,14 @@ export type PubKey = {
|
|
|
3
3
|
};
|
|
4
4
|
|
|
5
5
|
export type Address = {
|
|
6
|
-
tbcAddress
|
|
6
|
+
tbcAddress?: string;
|
|
7
|
+
btcAddress?: string;
|
|
8
|
+
ethAddress?: string;
|
|
9
|
+
bnbAddress?: string;
|
|
7
10
|
};
|
|
8
11
|
|
|
12
|
+
export type ConnectResponse = Address;
|
|
13
|
+
|
|
9
14
|
export type Info = {
|
|
10
15
|
name: string;
|
|
11
16
|
platform: string;
|
|
@@ -156,9 +161,27 @@ export type BatchResponse = Array<
|
|
|
156
161
|
| DecryptResponse
|
|
157
162
|
>;
|
|
158
163
|
|
|
164
|
+
export type EvmSendTransaction = {
|
|
165
|
+
chainId: number;
|
|
166
|
+
contractAddress?: string;
|
|
167
|
+
toAddress: string;
|
|
168
|
+
amount: string;
|
|
169
|
+
broadcastEnabled?: boolean;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export type EvmSendTransactionResponse = {
|
|
173
|
+
txid?: string;
|
|
174
|
+
txraw?: string;
|
|
175
|
+
error?: string;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export type EvmProvider = {
|
|
179
|
+
sendTransaction: (params: EvmSendTransaction) => Promise<EvmSendTransactionResponse | undefined>;
|
|
180
|
+
};
|
|
181
|
+
|
|
159
182
|
export type TuringProviderType = {
|
|
160
183
|
isReady: boolean;
|
|
161
|
-
connect: () => Promise<
|
|
184
|
+
connect: () => Promise<ConnectResponse | undefined>;
|
|
162
185
|
disconnect: () => Promise<boolean>;
|
|
163
186
|
isConnected: () => Promise<boolean>;
|
|
164
187
|
getPubKey: () => Promise<PubKey | undefined>;
|
|
@@ -179,4 +202,5 @@ export type TuringProviderType = {
|
|
|
179
202
|
params: SignAssociatedTransaction
|
|
180
203
|
) => Promise<SignAssociatedTransactionResponse | undefined>;
|
|
181
204
|
sendBatchRequest: (requests: BatchRequest[]) => Promise<BatchResponse | undefined>;
|
|
205
|
+
evm: EvmProvider;
|
|
182
206
|
};
|