turing-wallet-provider 1.0.11 → 1.0.12
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 +300 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
### connect
|
|
2
|
+
|
|
3
|
+
```tsx
|
|
4
|
+
npm install turing-wallet-provider@latest
|
|
5
|
+
|
|
6
|
+
import { TuringProvider } from "turing-wallet-provider";
|
|
7
|
+
|
|
8
|
+
root.render(
|
|
9
|
+
<TuringProvider>
|
|
10
|
+
<App />
|
|
11
|
+
</TuringProvider>
|
|
12
|
+
);
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { useTuringsWallet } from 'turing-wallet-provider';
|
|
17
|
+
|
|
18
|
+
const wallet = useTuringsWallet();
|
|
19
|
+
await wallet.connect();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### disconnect
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
const wallet = useTuringsWallet();
|
|
26
|
+
await wallet.disconnect();
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### isConnected
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
const wallet = useTuringsWallet();
|
|
33
|
+
const ture/false = await wallet.isConnected();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### getPubKey
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
const wallet = useTuringsWallet();
|
|
40
|
+
const {tbcPubKey} = await wallet.getPubKey(); //tbcPubKey为string类型
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### getAddress
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
const wallet = useTuringsWallet();
|
|
47
|
+
const {tbcAddress} = await wallet.getAddress(); //tbcAddress为string类型
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### getBalance
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
const wallet = useTuringsWallet();
|
|
54
|
+
const {tbc} = await wallet.getBalance();//tbc为number类型,单位为tbc
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### getPaymentUtxos
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
const wallet = useTuringsWallet();
|
|
61
|
+
try {
|
|
62
|
+
const utxos = await wallet.getPaymentUtxos();
|
|
63
|
+
console.log(utxos);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.log(err);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
[
|
|
69
|
+
{
|
|
70
|
+
satoshis: 205551
|
|
71
|
+
script: "76a914b681d8032b448405d44e82807fab2c8894eed57788ac"
|
|
72
|
+
txid: "c58e8b0dd25e56af0696b026c1961dccd0cab3fe42fb2f3ac934ebdc3accbb40"
|
|
73
|
+
vout: 0
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
satoshis: 19909
|
|
77
|
+
script: "76a914b681d8032b448405d44e82807fab2c8894eed57788ac"
|
|
78
|
+
txid: "4c52add57a2c9cda29501a810a1312eaee9423d28440a09acbf5d9d8d0467382"
|
|
79
|
+
vout: 0
|
|
80
|
+
}
|
|
81
|
+
]//模拟的输出
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### signMessage
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
const wallet = useTuringsWallet();
|
|
88
|
+
try{
|
|
89
|
+
const { address, pubKey, sig, message } = await wallet.signMessage({ message: "hello world", encoding: "base64" });//encoding可为utf-8,base64,hex
|
|
90
|
+
}catch(error){
|
|
91
|
+
console.log(err);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//本地验证签名
|
|
95
|
+
import * as tbc from "tbc-lib-js"
|
|
96
|
+
|
|
97
|
+
const msg_buf = Buffer.from(message,encoding);
|
|
98
|
+
const true/false = tbc.Message.verify(msg_buf,address,sig);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### sendTransaction
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
interface FTData {
|
|
105
|
+
name :string;
|
|
106
|
+
symbol :string;
|
|
107
|
+
decimal :number;
|
|
108
|
+
amount :number;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
interface CollectionData {
|
|
112
|
+
collectionName: string;
|
|
113
|
+
description: string;
|
|
114
|
+
supply: number;
|
|
115
|
+
file: string;//file为图片base64编码后数据
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
interface NFTData {
|
|
119
|
+
nftName: string;
|
|
120
|
+
symbol: string;
|
|
121
|
+
discription: string;
|
|
122
|
+
attributes: string;
|
|
123
|
+
file?: string;//file为图片base64编码后数据,若无则为引用合集图片
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
interface RequestParam = {
|
|
127
|
+
flag: "P2PKH" | "COLLECTION_CREATE" | "NFT_CREATE" | "NFT_TRANSFER" | "FT_MINT" | "FT_TRANSFER" | "POOLNFT_MINT" | "POOLNFT_INIT" | "POOLNFT_LP_INCREASE" |"POOLNFT_LP_CONSUME"| "POOLNFT_SWAP_TO_TOKEN" | "POOLNFT_SWAP_TO_TBC" | "POOLNFT_MERGE"|"FTLP_MERGE";
|
|
128
|
+
address?: string;//交易接收者地址
|
|
129
|
+
satoshis?: number;//单位为satoshis
|
|
130
|
+
collection_data?: string; //json格式传
|
|
131
|
+
ft_data?: string; //json格式传
|
|
132
|
+
nft_data?: string; //json格式传
|
|
133
|
+
collection_id?: string;
|
|
134
|
+
nft_contract_address?: string;
|
|
135
|
+
ft_contract_address?: string;
|
|
136
|
+
tbc_amount?: number;
|
|
137
|
+
ft_amount?: number;
|
|
138
|
+
merge_times?:number;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const params = [param:RequestParam] //目前参数里只能放一个对象,有批量发送需求再扩展
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### P2PKH
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
const params = [{
|
|
148
|
+
flag:"P2PKH",
|
|
149
|
+
satoshis: 1000,
|
|
150
|
+
address: "",
|
|
151
|
+
}] ;
|
|
152
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### COLLECTION_CREATE
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
const params = [{
|
|
159
|
+
flag:"COLLECTION_CREATE",
|
|
160
|
+
collection_data:"",
|
|
161
|
+
}];
|
|
162
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### NFT_CREATE
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
const params = [{
|
|
169
|
+
flag:"NFT_CREATE",
|
|
170
|
+
nft_data:"",
|
|
171
|
+
collection_id:""
|
|
172
|
+
}];
|
|
173
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
#### NFT_TRANSFER
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
const params = [{
|
|
180
|
+
flag:"NFT_TRANSFER",
|
|
181
|
+
nft_contract_address:"",
|
|
182
|
+
address:""
|
|
183
|
+
}];
|
|
184
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### FT_MINT
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
const params = [{
|
|
191
|
+
flag:"FT_MINT",
|
|
192
|
+
ft_data:""
|
|
193
|
+
}];
|
|
194
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### FT_TRANSFER
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
const params = [{
|
|
201
|
+
flag:"FT_TRANSFER",
|
|
202
|
+
ft_contract_address:"",
|
|
203
|
+
ft_amount:0.1,
|
|
204
|
+
address::""
|
|
205
|
+
}];
|
|
206
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
#### POOLNFT_MINT
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
const params = [{
|
|
213
|
+
flag:"POOLNFT_MINT",
|
|
214
|
+
ft_contract_address:"",
|
|
215
|
+
}];
|
|
216
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
#### POOLNFT_INIT
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
const params = [{
|
|
223
|
+
flag:"POOLNFT_INIT",
|
|
224
|
+
nft_contract_address:"",
|
|
225
|
+
address:"",
|
|
226
|
+
tbc_amount:30,
|
|
227
|
+
ft_amount:1000
|
|
228
|
+
}];
|
|
229
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
#### POOLNFT_LP_INCREASE
|
|
233
|
+
|
|
234
|
+
```
|
|
235
|
+
const params = [{
|
|
236
|
+
flag:"POOLNFT_LP_INCREASE",
|
|
237
|
+
nft_contract_address:"",
|
|
238
|
+
address:"",
|
|
239
|
+
tbc_amount:3
|
|
240
|
+
}];
|
|
241
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
#### POOLNFT_LP_CONSUME
|
|
245
|
+
|
|
246
|
+
```
|
|
247
|
+
const params = [{
|
|
248
|
+
flag:"POOLNFT_LP_CONSUME",
|
|
249
|
+
nft_contract_address:"",
|
|
250
|
+
address:""
|
|
251
|
+
ft_amount:100
|
|
252
|
+
}];
|
|
253
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
#### POOLNFT_SWAP_TO_TOKEN
|
|
257
|
+
|
|
258
|
+
```
|
|
259
|
+
const params = [{
|
|
260
|
+
flag:"POOLNFT_SWAP_TO_TOKEN",
|
|
261
|
+
nft_contract_address:"",
|
|
262
|
+
address:"",
|
|
263
|
+
tbc_amount:10
|
|
264
|
+
}];
|
|
265
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
#### POOLNFT_SWAP_TO_TBC
|
|
269
|
+
|
|
270
|
+
```
|
|
271
|
+
const params = [{
|
|
272
|
+
flag:"POOLNFT_SWAP_TO_TBC",
|
|
273
|
+
nft_contract_address:"",
|
|
274
|
+
address:"",
|
|
275
|
+
ft_amount:10
|
|
276
|
+
}];
|
|
277
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
#### POOLNFT_MERGE
|
|
281
|
+
|
|
282
|
+
```
|
|
283
|
+
const params = [{
|
|
284
|
+
flag:"POOLNFT_MERGE",
|
|
285
|
+
nft_contract_address:"",
|
|
286
|
+
merge_times:1; //1-10次
|
|
287
|
+
}];
|
|
288
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
#### FTLP_MERGE
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
const params = [{
|
|
295
|
+
flag:"POOLNFT_MERGE",
|
|
296
|
+
nft_contract_address:""
|
|
297
|
+
}];
|
|
298
|
+
const { txid, rawtx } = await wallet.sendTransaction(params);
|
|
299
|
+
```
|
|
300
|
+
|