@awarizon/web3 1.0.1 → 1.1.0
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/dist/index.d.mts +805 -44
- package/dist/index.d.ts +805 -44
- package/dist/index.js +591 -95
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +568 -78
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Chain, WalletClient, Address, Abi, PublicClient } from 'viem';
|
|
1
|
+
import { Chain, WalletClient, Address, Abi, PublicClient, Hex } from 'viem';
|
|
2
2
|
export { Abi, Address, Chain, Hash, TransactionReceipt, WalletClient } from 'viem';
|
|
3
|
-
import { WalletEngine } from '@awarizon/wallet-engine';
|
|
3
|
+
import { WalletEngine, CreatedWallet, ImportedWalletFromMnemonic, ImportedWalletFromPrivateKey, ExternalWalletClient } from '@awarizon/wallet-engine';
|
|
4
4
|
export { ChainSwitchError, InvalidMnemonicError, InvalidPrivateKeyError, WalletEngine, WalletNotConnectedError } from '@awarizon/wallet-engine';
|
|
5
|
+
import { TransactionResult } from '@awarizon/tx-engine';
|
|
5
6
|
export { ContractExecutionError, GasEstimationError, SimulationError, TransactionEngine, TransactionResult, TransactionTimeoutError } from '@awarizon/tx-engine';
|
|
6
7
|
export { DuplicateFunctionError, InvalidABIError, UnsupportedABIItemError, generateAllMethodSignatures, generateMethodSignature, isPayableFunction, isWriteFunction, parseABI } from '@awarizon/abi-engine';
|
|
7
8
|
|
|
@@ -12,6 +13,12 @@ interface AwarizonConfig {
|
|
|
12
13
|
* - a viem Chain object: `import { base } from "viem/chains"`
|
|
13
14
|
*/
|
|
14
15
|
chain: Chain | string;
|
|
16
|
+
/**
|
|
17
|
+
* Awarizon API key (required).
|
|
18
|
+
* Generate one at https://awarizon.com/dashboard/api-keys
|
|
19
|
+
* Format: "awz_live_..."
|
|
20
|
+
*/
|
|
21
|
+
apiKey: string;
|
|
15
22
|
/**
|
|
16
23
|
* Optional RPC URL override.
|
|
17
24
|
* If omitted, the chain's default public RPC endpoint is used.
|
|
@@ -19,9 +26,14 @@ interface AwarizonConfig {
|
|
|
19
26
|
rpcUrl?: string;
|
|
20
27
|
/**
|
|
21
28
|
* Optional pre-connected external signer.
|
|
22
|
-
* Equivalent to calling `
|
|
29
|
+
* Equivalent to calling `awarizon.connectWallet(signer)` after construction.
|
|
23
30
|
*/
|
|
24
31
|
signer?: WalletClient;
|
|
32
|
+
/**
|
|
33
|
+
* Base URL of the Awarizon API. Defaults to "https://awarizon.com".
|
|
34
|
+
* Override for local development or staging environments.
|
|
35
|
+
*/
|
|
36
|
+
baseUrl?: string;
|
|
25
37
|
}
|
|
26
38
|
interface ContractConfig<TAbi extends Abi = Abi> {
|
|
27
39
|
/** The deployed contract address */
|
|
@@ -39,7 +51,7 @@ interface PayableOptions {
|
|
|
39
51
|
gas?: bigint;
|
|
40
52
|
}
|
|
41
53
|
/**
|
|
42
|
-
* The dynamically-generated contract instance returned by
|
|
54
|
+
* The dynamically-generated contract instance returned by awarizon.contract().
|
|
43
55
|
*
|
|
44
56
|
* Every function in the ABI is exposed as a method:
|
|
45
57
|
* - read functions (view/pure) → return decoded values
|
|
@@ -65,6 +77,543 @@ interface SDKWalletInfo {
|
|
|
65
77
|
chain: Chain;
|
|
66
78
|
isExternal: boolean;
|
|
67
79
|
}
|
|
80
|
+
interface ContractRegistryEntry {
|
|
81
|
+
address: Address;
|
|
82
|
+
abi: Abi;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
declare const ERC20_ABI: readonly [{
|
|
86
|
+
readonly type: "event";
|
|
87
|
+
readonly name: "Approval";
|
|
88
|
+
readonly inputs: readonly [{
|
|
89
|
+
readonly indexed: true;
|
|
90
|
+
readonly name: "owner";
|
|
91
|
+
readonly type: "address";
|
|
92
|
+
}, {
|
|
93
|
+
readonly indexed: true;
|
|
94
|
+
readonly name: "spender";
|
|
95
|
+
readonly type: "address";
|
|
96
|
+
}, {
|
|
97
|
+
readonly indexed: false;
|
|
98
|
+
readonly name: "value";
|
|
99
|
+
readonly type: "uint256";
|
|
100
|
+
}];
|
|
101
|
+
}, {
|
|
102
|
+
readonly type: "event";
|
|
103
|
+
readonly name: "Transfer";
|
|
104
|
+
readonly inputs: readonly [{
|
|
105
|
+
readonly indexed: true;
|
|
106
|
+
readonly name: "from";
|
|
107
|
+
readonly type: "address";
|
|
108
|
+
}, {
|
|
109
|
+
readonly indexed: true;
|
|
110
|
+
readonly name: "to";
|
|
111
|
+
readonly type: "address";
|
|
112
|
+
}, {
|
|
113
|
+
readonly indexed: false;
|
|
114
|
+
readonly name: "value";
|
|
115
|
+
readonly type: "uint256";
|
|
116
|
+
}];
|
|
117
|
+
}, {
|
|
118
|
+
readonly type: "function";
|
|
119
|
+
readonly name: "allowance";
|
|
120
|
+
readonly stateMutability: "view";
|
|
121
|
+
readonly inputs: readonly [{
|
|
122
|
+
readonly name: "owner";
|
|
123
|
+
readonly type: "address";
|
|
124
|
+
}, {
|
|
125
|
+
readonly name: "spender";
|
|
126
|
+
readonly type: "address";
|
|
127
|
+
}];
|
|
128
|
+
readonly outputs: readonly [{
|
|
129
|
+
readonly type: "uint256";
|
|
130
|
+
}];
|
|
131
|
+
}, {
|
|
132
|
+
readonly type: "function";
|
|
133
|
+
readonly name: "approve";
|
|
134
|
+
readonly stateMutability: "nonpayable";
|
|
135
|
+
readonly inputs: readonly [{
|
|
136
|
+
readonly name: "spender";
|
|
137
|
+
readonly type: "address";
|
|
138
|
+
}, {
|
|
139
|
+
readonly name: "amount";
|
|
140
|
+
readonly type: "uint256";
|
|
141
|
+
}];
|
|
142
|
+
readonly outputs: readonly [{
|
|
143
|
+
readonly type: "bool";
|
|
144
|
+
}];
|
|
145
|
+
}, {
|
|
146
|
+
readonly type: "function";
|
|
147
|
+
readonly name: "balanceOf";
|
|
148
|
+
readonly stateMutability: "view";
|
|
149
|
+
readonly inputs: readonly [{
|
|
150
|
+
readonly name: "account";
|
|
151
|
+
readonly type: "address";
|
|
152
|
+
}];
|
|
153
|
+
readonly outputs: readonly [{
|
|
154
|
+
readonly type: "uint256";
|
|
155
|
+
}];
|
|
156
|
+
}, {
|
|
157
|
+
readonly type: "function";
|
|
158
|
+
readonly name: "decimals";
|
|
159
|
+
readonly stateMutability: "view";
|
|
160
|
+
readonly inputs: readonly [];
|
|
161
|
+
readonly outputs: readonly [{
|
|
162
|
+
readonly type: "uint8";
|
|
163
|
+
}];
|
|
164
|
+
}, {
|
|
165
|
+
readonly type: "function";
|
|
166
|
+
readonly name: "name";
|
|
167
|
+
readonly stateMutability: "view";
|
|
168
|
+
readonly inputs: readonly [];
|
|
169
|
+
readonly outputs: readonly [{
|
|
170
|
+
readonly type: "string";
|
|
171
|
+
}];
|
|
172
|
+
}, {
|
|
173
|
+
readonly type: "function";
|
|
174
|
+
readonly name: "symbol";
|
|
175
|
+
readonly stateMutability: "view";
|
|
176
|
+
readonly inputs: readonly [];
|
|
177
|
+
readonly outputs: readonly [{
|
|
178
|
+
readonly type: "string";
|
|
179
|
+
}];
|
|
180
|
+
}, {
|
|
181
|
+
readonly type: "function";
|
|
182
|
+
readonly name: "totalSupply";
|
|
183
|
+
readonly stateMutability: "view";
|
|
184
|
+
readonly inputs: readonly [];
|
|
185
|
+
readonly outputs: readonly [{
|
|
186
|
+
readonly type: "uint256";
|
|
187
|
+
}];
|
|
188
|
+
}, {
|
|
189
|
+
readonly type: "function";
|
|
190
|
+
readonly name: "transfer";
|
|
191
|
+
readonly stateMutability: "nonpayable";
|
|
192
|
+
readonly inputs: readonly [{
|
|
193
|
+
readonly name: "recipient";
|
|
194
|
+
readonly type: "address";
|
|
195
|
+
}, {
|
|
196
|
+
readonly name: "amount";
|
|
197
|
+
readonly type: "uint256";
|
|
198
|
+
}];
|
|
199
|
+
readonly outputs: readonly [{
|
|
200
|
+
readonly type: "bool";
|
|
201
|
+
}];
|
|
202
|
+
}, {
|
|
203
|
+
readonly type: "function";
|
|
204
|
+
readonly name: "transferFrom";
|
|
205
|
+
readonly stateMutability: "nonpayable";
|
|
206
|
+
readonly inputs: readonly [{
|
|
207
|
+
readonly name: "sender";
|
|
208
|
+
readonly type: "address";
|
|
209
|
+
}, {
|
|
210
|
+
readonly name: "recipient";
|
|
211
|
+
readonly type: "address";
|
|
212
|
+
}, {
|
|
213
|
+
readonly name: "amount";
|
|
214
|
+
readonly type: "uint256";
|
|
215
|
+
}];
|
|
216
|
+
readonly outputs: readonly [{
|
|
217
|
+
readonly type: "bool";
|
|
218
|
+
}];
|
|
219
|
+
}];
|
|
220
|
+
interface Erc20Contract {
|
|
221
|
+
name(): Promise<string>;
|
|
222
|
+
symbol(): Promise<string>;
|
|
223
|
+
decimals(): Promise<number>;
|
|
224
|
+
totalSupply(): Promise<bigint>;
|
|
225
|
+
balanceOf(owner: Address): Promise<bigint>;
|
|
226
|
+
allowance(owner: Address, spender: Address): Promise<bigint>;
|
|
227
|
+
transfer(to: Address, amount: bigint): Promise<TransactionResult>;
|
|
228
|
+
transferFrom(from: Address, to: Address, amount: bigint): Promise<TransactionResult>;
|
|
229
|
+
approve(spender: Address, amount: bigint): Promise<TransactionResult>;
|
|
230
|
+
on: ContractInstance['on'];
|
|
231
|
+
estimateGas: ContractInstance['estimateGas'];
|
|
232
|
+
readonly _address: Address;
|
|
233
|
+
readonly _abi: Abi;
|
|
234
|
+
}
|
|
235
|
+
declare const ERC721_ABI: readonly [{
|
|
236
|
+
readonly type: "function";
|
|
237
|
+
readonly name: "name";
|
|
238
|
+
readonly stateMutability: "view";
|
|
239
|
+
readonly inputs: readonly [];
|
|
240
|
+
readonly outputs: readonly [{
|
|
241
|
+
readonly type: "string";
|
|
242
|
+
}];
|
|
243
|
+
}, {
|
|
244
|
+
readonly type: "function";
|
|
245
|
+
readonly name: "symbol";
|
|
246
|
+
readonly stateMutability: "view";
|
|
247
|
+
readonly inputs: readonly [];
|
|
248
|
+
readonly outputs: readonly [{
|
|
249
|
+
readonly type: "string";
|
|
250
|
+
}];
|
|
251
|
+
}, {
|
|
252
|
+
readonly type: "function";
|
|
253
|
+
readonly name: "tokenURI";
|
|
254
|
+
readonly stateMutability: "view";
|
|
255
|
+
readonly inputs: readonly [{
|
|
256
|
+
readonly name: "tokenId";
|
|
257
|
+
readonly type: "uint256";
|
|
258
|
+
}];
|
|
259
|
+
readonly outputs: readonly [{
|
|
260
|
+
readonly type: "string";
|
|
261
|
+
}];
|
|
262
|
+
}, {
|
|
263
|
+
readonly type: "function";
|
|
264
|
+
readonly name: "totalSupply";
|
|
265
|
+
readonly stateMutability: "view";
|
|
266
|
+
readonly inputs: readonly [];
|
|
267
|
+
readonly outputs: readonly [{
|
|
268
|
+
readonly type: "uint256";
|
|
269
|
+
}];
|
|
270
|
+
}, {
|
|
271
|
+
readonly type: "function";
|
|
272
|
+
readonly name: "ownerOf";
|
|
273
|
+
readonly stateMutability: "view";
|
|
274
|
+
readonly inputs: readonly [{
|
|
275
|
+
readonly name: "tokenId";
|
|
276
|
+
readonly type: "uint256";
|
|
277
|
+
}];
|
|
278
|
+
readonly outputs: readonly [{
|
|
279
|
+
readonly type: "address";
|
|
280
|
+
}];
|
|
281
|
+
}, {
|
|
282
|
+
readonly type: "function";
|
|
283
|
+
readonly name: "balanceOf";
|
|
284
|
+
readonly stateMutability: "view";
|
|
285
|
+
readonly inputs: readonly [{
|
|
286
|
+
readonly name: "owner";
|
|
287
|
+
readonly type: "address";
|
|
288
|
+
}];
|
|
289
|
+
readonly outputs: readonly [{
|
|
290
|
+
readonly type: "uint256";
|
|
291
|
+
}];
|
|
292
|
+
}, {
|
|
293
|
+
readonly type: "function";
|
|
294
|
+
readonly name: "getApproved";
|
|
295
|
+
readonly stateMutability: "view";
|
|
296
|
+
readonly inputs: readonly [{
|
|
297
|
+
readonly name: "tokenId";
|
|
298
|
+
readonly type: "uint256";
|
|
299
|
+
}];
|
|
300
|
+
readonly outputs: readonly [{
|
|
301
|
+
readonly type: "address";
|
|
302
|
+
}];
|
|
303
|
+
}, {
|
|
304
|
+
readonly type: "function";
|
|
305
|
+
readonly name: "isApprovedForAll";
|
|
306
|
+
readonly stateMutability: "view";
|
|
307
|
+
readonly inputs: readonly [{
|
|
308
|
+
readonly name: "owner";
|
|
309
|
+
readonly type: "address";
|
|
310
|
+
}, {
|
|
311
|
+
readonly name: "operator";
|
|
312
|
+
readonly type: "address";
|
|
313
|
+
}];
|
|
314
|
+
readonly outputs: readonly [{
|
|
315
|
+
readonly type: "bool";
|
|
316
|
+
}];
|
|
317
|
+
}, {
|
|
318
|
+
readonly type: "function";
|
|
319
|
+
readonly name: "transferFrom";
|
|
320
|
+
readonly stateMutability: "nonpayable";
|
|
321
|
+
readonly inputs: readonly [{
|
|
322
|
+
readonly name: "from";
|
|
323
|
+
readonly type: "address";
|
|
324
|
+
}, {
|
|
325
|
+
readonly name: "to";
|
|
326
|
+
readonly type: "address";
|
|
327
|
+
}, {
|
|
328
|
+
readonly name: "tokenId";
|
|
329
|
+
readonly type: "uint256";
|
|
330
|
+
}];
|
|
331
|
+
readonly outputs: readonly [];
|
|
332
|
+
}, {
|
|
333
|
+
readonly type: "function";
|
|
334
|
+
readonly name: "safeTransferFrom";
|
|
335
|
+
readonly stateMutability: "nonpayable";
|
|
336
|
+
readonly inputs: readonly [{
|
|
337
|
+
readonly name: "from";
|
|
338
|
+
readonly type: "address";
|
|
339
|
+
}, {
|
|
340
|
+
readonly name: "to";
|
|
341
|
+
readonly type: "address";
|
|
342
|
+
}, {
|
|
343
|
+
readonly name: "tokenId";
|
|
344
|
+
readonly type: "uint256";
|
|
345
|
+
}];
|
|
346
|
+
readonly outputs: readonly [];
|
|
347
|
+
}, {
|
|
348
|
+
readonly type: "function";
|
|
349
|
+
readonly name: "approve";
|
|
350
|
+
readonly stateMutability: "nonpayable";
|
|
351
|
+
readonly inputs: readonly [{
|
|
352
|
+
readonly name: "to";
|
|
353
|
+
readonly type: "address";
|
|
354
|
+
}, {
|
|
355
|
+
readonly name: "tokenId";
|
|
356
|
+
readonly type: "uint256";
|
|
357
|
+
}];
|
|
358
|
+
readonly outputs: readonly [];
|
|
359
|
+
}, {
|
|
360
|
+
readonly type: "function";
|
|
361
|
+
readonly name: "setApprovalForAll";
|
|
362
|
+
readonly stateMutability: "nonpayable";
|
|
363
|
+
readonly inputs: readonly [{
|
|
364
|
+
readonly name: "operator";
|
|
365
|
+
readonly type: "address";
|
|
366
|
+
}, {
|
|
367
|
+
readonly name: "approved";
|
|
368
|
+
readonly type: "bool";
|
|
369
|
+
}];
|
|
370
|
+
readonly outputs: readonly [];
|
|
371
|
+
}, {
|
|
372
|
+
readonly type: "event";
|
|
373
|
+
readonly name: "Transfer";
|
|
374
|
+
readonly inputs: readonly [{
|
|
375
|
+
readonly indexed: true;
|
|
376
|
+
readonly name: "from";
|
|
377
|
+
readonly type: "address";
|
|
378
|
+
}, {
|
|
379
|
+
readonly indexed: true;
|
|
380
|
+
readonly name: "to";
|
|
381
|
+
readonly type: "address";
|
|
382
|
+
}, {
|
|
383
|
+
readonly indexed: true;
|
|
384
|
+
readonly name: "tokenId";
|
|
385
|
+
readonly type: "uint256";
|
|
386
|
+
}];
|
|
387
|
+
}, {
|
|
388
|
+
readonly type: "event";
|
|
389
|
+
readonly name: "Approval";
|
|
390
|
+
readonly inputs: readonly [{
|
|
391
|
+
readonly indexed: true;
|
|
392
|
+
readonly name: "owner";
|
|
393
|
+
readonly type: "address";
|
|
394
|
+
}, {
|
|
395
|
+
readonly indexed: true;
|
|
396
|
+
readonly name: "approved";
|
|
397
|
+
readonly type: "address";
|
|
398
|
+
}, {
|
|
399
|
+
readonly indexed: true;
|
|
400
|
+
readonly name: "tokenId";
|
|
401
|
+
readonly type: "uint256";
|
|
402
|
+
}];
|
|
403
|
+
}, {
|
|
404
|
+
readonly type: "event";
|
|
405
|
+
readonly name: "ApprovalForAll";
|
|
406
|
+
readonly inputs: readonly [{
|
|
407
|
+
readonly indexed: true;
|
|
408
|
+
readonly name: "owner";
|
|
409
|
+
readonly type: "address";
|
|
410
|
+
}, {
|
|
411
|
+
readonly indexed: true;
|
|
412
|
+
readonly name: "operator";
|
|
413
|
+
readonly type: "address";
|
|
414
|
+
}, {
|
|
415
|
+
readonly name: "approved";
|
|
416
|
+
readonly type: "bool";
|
|
417
|
+
}];
|
|
418
|
+
}];
|
|
419
|
+
interface Erc721Contract {
|
|
420
|
+
name(): Promise<string>;
|
|
421
|
+
symbol(): Promise<string>;
|
|
422
|
+
tokenURI(tokenId: bigint): Promise<string>;
|
|
423
|
+
totalSupply(): Promise<bigint>;
|
|
424
|
+
ownerOf(tokenId: bigint): Promise<Address>;
|
|
425
|
+
balanceOf(owner: Address): Promise<bigint>;
|
|
426
|
+
getApproved(tokenId: bigint): Promise<Address>;
|
|
427
|
+
isApprovedForAll(owner: Address, operator: Address): Promise<boolean>;
|
|
428
|
+
transferFrom(from: Address, to: Address, tokenId: bigint): Promise<TransactionResult>;
|
|
429
|
+
safeTransferFrom(from: Address, to: Address, tokenId: bigint): Promise<TransactionResult>;
|
|
430
|
+
approve(to: Address, tokenId: bigint): Promise<TransactionResult>;
|
|
431
|
+
setApprovalForAll(operator: Address, approved: boolean): Promise<TransactionResult>;
|
|
432
|
+
on: ContractInstance['on'];
|
|
433
|
+
estimateGas: ContractInstance['estimateGas'];
|
|
434
|
+
readonly _address: Address;
|
|
435
|
+
readonly _abi: Abi;
|
|
436
|
+
}
|
|
437
|
+
declare const ERC1155_ABI: readonly [{
|
|
438
|
+
readonly type: "function";
|
|
439
|
+
readonly name: "uri";
|
|
440
|
+
readonly stateMutability: "view";
|
|
441
|
+
readonly inputs: readonly [{
|
|
442
|
+
readonly name: "id";
|
|
443
|
+
readonly type: "uint256";
|
|
444
|
+
}];
|
|
445
|
+
readonly outputs: readonly [{
|
|
446
|
+
readonly type: "string";
|
|
447
|
+
}];
|
|
448
|
+
}, {
|
|
449
|
+
readonly type: "function";
|
|
450
|
+
readonly name: "balanceOf";
|
|
451
|
+
readonly stateMutability: "view";
|
|
452
|
+
readonly inputs: readonly [{
|
|
453
|
+
readonly name: "account";
|
|
454
|
+
readonly type: "address";
|
|
455
|
+
}, {
|
|
456
|
+
readonly name: "id";
|
|
457
|
+
readonly type: "uint256";
|
|
458
|
+
}];
|
|
459
|
+
readonly outputs: readonly [{
|
|
460
|
+
readonly type: "uint256";
|
|
461
|
+
}];
|
|
462
|
+
}, {
|
|
463
|
+
readonly type: "function";
|
|
464
|
+
readonly name: "balanceOfBatch";
|
|
465
|
+
readonly stateMutability: "view";
|
|
466
|
+
readonly inputs: readonly [{
|
|
467
|
+
readonly name: "accounts";
|
|
468
|
+
readonly type: "address[]";
|
|
469
|
+
}, {
|
|
470
|
+
readonly name: "ids";
|
|
471
|
+
readonly type: "uint256[]";
|
|
472
|
+
}];
|
|
473
|
+
readonly outputs: readonly [{
|
|
474
|
+
readonly type: "uint256[]";
|
|
475
|
+
}];
|
|
476
|
+
}, {
|
|
477
|
+
readonly type: "function";
|
|
478
|
+
readonly name: "isApprovedForAll";
|
|
479
|
+
readonly stateMutability: "view";
|
|
480
|
+
readonly inputs: readonly [{
|
|
481
|
+
readonly name: "account";
|
|
482
|
+
readonly type: "address";
|
|
483
|
+
}, {
|
|
484
|
+
readonly name: "operator";
|
|
485
|
+
readonly type: "address";
|
|
486
|
+
}];
|
|
487
|
+
readonly outputs: readonly [{
|
|
488
|
+
readonly type: "bool";
|
|
489
|
+
}];
|
|
490
|
+
}, {
|
|
491
|
+
readonly type: "function";
|
|
492
|
+
readonly name: "setApprovalForAll";
|
|
493
|
+
readonly stateMutability: "nonpayable";
|
|
494
|
+
readonly inputs: readonly [{
|
|
495
|
+
readonly name: "operator";
|
|
496
|
+
readonly type: "address";
|
|
497
|
+
}, {
|
|
498
|
+
readonly name: "approved";
|
|
499
|
+
readonly type: "bool";
|
|
500
|
+
}];
|
|
501
|
+
readonly outputs: readonly [];
|
|
502
|
+
}, {
|
|
503
|
+
readonly type: "function";
|
|
504
|
+
readonly name: "safeTransferFrom";
|
|
505
|
+
readonly stateMutability: "nonpayable";
|
|
506
|
+
readonly inputs: readonly [{
|
|
507
|
+
readonly name: "from";
|
|
508
|
+
readonly type: "address";
|
|
509
|
+
}, {
|
|
510
|
+
readonly name: "to";
|
|
511
|
+
readonly type: "address";
|
|
512
|
+
}, {
|
|
513
|
+
readonly name: "id";
|
|
514
|
+
readonly type: "uint256";
|
|
515
|
+
}, {
|
|
516
|
+
readonly name: "amount";
|
|
517
|
+
readonly type: "uint256";
|
|
518
|
+
}, {
|
|
519
|
+
readonly name: "data";
|
|
520
|
+
readonly type: "bytes";
|
|
521
|
+
}];
|
|
522
|
+
readonly outputs: readonly [];
|
|
523
|
+
}, {
|
|
524
|
+
readonly type: "function";
|
|
525
|
+
readonly name: "safeBatchTransferFrom";
|
|
526
|
+
readonly stateMutability: "nonpayable";
|
|
527
|
+
readonly inputs: readonly [{
|
|
528
|
+
readonly name: "from";
|
|
529
|
+
readonly type: "address";
|
|
530
|
+
}, {
|
|
531
|
+
readonly name: "to";
|
|
532
|
+
readonly type: "address";
|
|
533
|
+
}, {
|
|
534
|
+
readonly name: "ids";
|
|
535
|
+
readonly type: "uint256[]";
|
|
536
|
+
}, {
|
|
537
|
+
readonly name: "amounts";
|
|
538
|
+
readonly type: "uint256[]";
|
|
539
|
+
}, {
|
|
540
|
+
readonly name: "data";
|
|
541
|
+
readonly type: "bytes";
|
|
542
|
+
}];
|
|
543
|
+
readonly outputs: readonly [];
|
|
544
|
+
}, {
|
|
545
|
+
readonly type: "event";
|
|
546
|
+
readonly name: "TransferSingle";
|
|
547
|
+
readonly inputs: readonly [{
|
|
548
|
+
readonly indexed: true;
|
|
549
|
+
readonly name: "operator";
|
|
550
|
+
readonly type: "address";
|
|
551
|
+
}, {
|
|
552
|
+
readonly indexed: true;
|
|
553
|
+
readonly name: "from";
|
|
554
|
+
readonly type: "address";
|
|
555
|
+
}, {
|
|
556
|
+
readonly indexed: true;
|
|
557
|
+
readonly name: "to";
|
|
558
|
+
readonly type: "address";
|
|
559
|
+
}, {
|
|
560
|
+
readonly name: "id";
|
|
561
|
+
readonly type: "uint256";
|
|
562
|
+
}, {
|
|
563
|
+
readonly name: "value";
|
|
564
|
+
readonly type: "uint256";
|
|
565
|
+
}];
|
|
566
|
+
}, {
|
|
567
|
+
readonly type: "event";
|
|
568
|
+
readonly name: "TransferBatch";
|
|
569
|
+
readonly inputs: readonly [{
|
|
570
|
+
readonly indexed: true;
|
|
571
|
+
readonly name: "operator";
|
|
572
|
+
readonly type: "address";
|
|
573
|
+
}, {
|
|
574
|
+
readonly indexed: true;
|
|
575
|
+
readonly name: "from";
|
|
576
|
+
readonly type: "address";
|
|
577
|
+
}, {
|
|
578
|
+
readonly indexed: true;
|
|
579
|
+
readonly name: "to";
|
|
580
|
+
readonly type: "address";
|
|
581
|
+
}, {
|
|
582
|
+
readonly name: "ids";
|
|
583
|
+
readonly type: "uint256[]";
|
|
584
|
+
}, {
|
|
585
|
+
readonly name: "values";
|
|
586
|
+
readonly type: "uint256[]";
|
|
587
|
+
}];
|
|
588
|
+
}, {
|
|
589
|
+
readonly type: "event";
|
|
590
|
+
readonly name: "ApprovalForAll";
|
|
591
|
+
readonly inputs: readonly [{
|
|
592
|
+
readonly indexed: true;
|
|
593
|
+
readonly name: "account";
|
|
594
|
+
readonly type: "address";
|
|
595
|
+
}, {
|
|
596
|
+
readonly indexed: true;
|
|
597
|
+
readonly name: "operator";
|
|
598
|
+
readonly type: "address";
|
|
599
|
+
}, {
|
|
600
|
+
readonly name: "approved";
|
|
601
|
+
readonly type: "bool";
|
|
602
|
+
}];
|
|
603
|
+
}];
|
|
604
|
+
interface Erc1155Contract {
|
|
605
|
+
uri(id: bigint): Promise<string>;
|
|
606
|
+
balanceOf(account: Address, id: bigint): Promise<bigint>;
|
|
607
|
+
balanceOfBatch(accounts: Address[], ids: bigint[]): Promise<bigint[]>;
|
|
608
|
+
isApprovedForAll(account: Address, operator: Address): Promise<boolean>;
|
|
609
|
+
setApprovalForAll(operator: Address, approved: boolean): Promise<TransactionResult>;
|
|
610
|
+
safeTransferFrom(from: Address, to: Address, id: bigint, amount: bigint, data: `0x${string}`): Promise<TransactionResult>;
|
|
611
|
+
safeBatchTransferFrom(from: Address, to: Address, ids: bigint[], amounts: bigint[], data: `0x${string}`): Promise<TransactionResult>;
|
|
612
|
+
on: ContractInstance['on'];
|
|
613
|
+
estimateGas: ContractInstance['estimateGas'];
|
|
614
|
+
readonly _address: Address;
|
|
615
|
+
readonly _abi: Abi;
|
|
616
|
+
}
|
|
68
617
|
|
|
69
618
|
declare class NetworkMismatchError extends Error {
|
|
70
619
|
readonly code: "NETWORK_MISMATCH";
|
|
@@ -85,79 +634,233 @@ declare class UnsupportedChainError extends Error {
|
|
|
85
634
|
readonly chain: string;
|
|
86
635
|
constructor(chain: string);
|
|
87
636
|
}
|
|
637
|
+
declare class ApiKeyRequiredError extends Error {
|
|
638
|
+
readonly code: "API_KEY_REQUIRED";
|
|
639
|
+
constructor();
|
|
640
|
+
}
|
|
641
|
+
declare class InvalidApiKeyError extends Error {
|
|
642
|
+
readonly code: "INVALID_API_KEY";
|
|
643
|
+
constructor(message?: string);
|
|
644
|
+
}
|
|
88
645
|
|
|
89
646
|
/**
|
|
90
|
-
*
|
|
647
|
+
* Wraps WalletEngine and gates mutating operations (create, import) behind
|
|
648
|
+
* API key validation. Read-only operations (address, isConnected, etc.) are
|
|
649
|
+
* never gated since they need no network access.
|
|
650
|
+
*/
|
|
651
|
+
declare class WalletProxy {
|
|
652
|
+
private readonly engine;
|
|
653
|
+
private readonly ensureReady;
|
|
654
|
+
constructor(engine: WalletEngine, ensureReady: () => Promise<void>);
|
|
655
|
+
create(): Promise<CreatedWallet>;
|
|
656
|
+
importMnemonic(mnemonic: string, accountIndex?: number): Promise<ImportedWalletFromMnemonic>;
|
|
657
|
+
importPrivateKey(privateKey: Hex): Promise<ImportedWalletFromPrivateKey>;
|
|
658
|
+
address(): Address;
|
|
659
|
+
getSigner(): WalletClient;
|
|
660
|
+
getWalletClient(): WalletClient;
|
|
661
|
+
isConnected(): boolean;
|
|
662
|
+
hasExternalWallet(): boolean;
|
|
663
|
+
hasInternalWallet(): boolean;
|
|
664
|
+
connectExternal(c: ExternalWalletClient): void;
|
|
665
|
+
disconnectExternal(): void;
|
|
666
|
+
disconnect(): void;
|
|
667
|
+
switchChain(chain: Chain): Promise<void>;
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Primary entry point for the Awarizon Web3 SDK.
|
|
671
|
+
*
|
|
672
|
+
* An API key is required — get yours at https://awarizon.com/dashboard/api-keys
|
|
91
673
|
*
|
|
92
674
|
* ```ts
|
|
93
|
-
* const
|
|
675
|
+
* const awarizon = new AwarizonWeb3({ chain: "base", apiKey: "awz_live_..." })
|
|
94
676
|
*
|
|
95
677
|
* // Internal wallet
|
|
96
|
-
* const wallet = await
|
|
678
|
+
* const wallet = await awarizon.wallet.create()
|
|
97
679
|
*
|
|
98
|
-
* // Load a contract
|
|
99
|
-
* const staking = await
|
|
680
|
+
* // Load a contract
|
|
681
|
+
* const staking = await awarizon.contract({ address: "0x...", abi })
|
|
100
682
|
* await staking.stake(100n)
|
|
101
|
-
* const balance = await staking.getBalance(wallet.address)
|
|
102
|
-
*
|
|
103
|
-
* // Listen for events
|
|
104
683
|
* staking.on("Staked", (log) => console.log(log))
|
|
105
684
|
* ```
|
|
106
685
|
*/
|
|
107
686
|
declare class AwarizonWeb3 {
|
|
108
|
-
/** The resolved viem Chain */
|
|
109
687
|
readonly chain: Chain;
|
|
110
|
-
/** Internal wallet + signer management */
|
|
111
|
-
readonly wallet: WalletEngine;
|
|
112
|
-
/** The underlying viem PublicClient used for reads */
|
|
113
688
|
readonly publicClient: PublicClient;
|
|
689
|
+
/** Wallet management — create, import, or connect external wallets */
|
|
690
|
+
readonly wallet: WalletProxy;
|
|
691
|
+
private readonly _engine;
|
|
692
|
+
private readonly _txEngine;
|
|
693
|
+
private readonly _telemetry;
|
|
694
|
+
private _contractCache;
|
|
695
|
+
private _registry;
|
|
114
696
|
constructor(config: AwarizonConfig);
|
|
697
|
+
connectWallet(walletClient: WalletClient): this;
|
|
698
|
+
disconnectWallet(): this;
|
|
699
|
+
switchChain(chain: Chain | string): Promise<this>;
|
|
700
|
+
getWalletInfo(): SDKWalletInfo;
|
|
115
701
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
702
|
+
* Load a deployed contract and return a fully typed, ABI-powered instance.
|
|
703
|
+
* Validates the API key on the first call — subsequent calls are instant.
|
|
704
|
+
*
|
|
705
|
+
* Results are cached by address — calling contract() twice with the same
|
|
706
|
+
* address and ABI object returns the same instance without rebuilding.
|
|
707
|
+
*/
|
|
708
|
+
contract<TAbi extends Abi>(config: ContractConfig<TAbi>): Promise<ContractInstance>;
|
|
709
|
+
/**
|
|
710
|
+
* Load multiple contracts in parallel. Validates the API key once, then
|
|
711
|
+
* instantiates all contracts concurrently.
|
|
118
712
|
*
|
|
119
713
|
* @example
|
|
120
|
-
*
|
|
714
|
+
* ```ts
|
|
715
|
+
* const [token, staking, nft] = await awarizon.contracts([
|
|
716
|
+
* { address: tokenAddr, abi: ERC20_ABI },
|
|
717
|
+
* { address: stakingAddr, abi: STAKING_ABI },
|
|
718
|
+
* { address: nftAddr, abi: ERC721_ABI },
|
|
719
|
+
* ])
|
|
720
|
+
* ```
|
|
121
721
|
*/
|
|
122
|
-
|
|
722
|
+
contracts(configs: Array<{
|
|
723
|
+
address: Address;
|
|
724
|
+
abi: Abi;
|
|
725
|
+
}>): Promise<ContractInstance[]>;
|
|
123
726
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
727
|
+
* Call a read-only (view/pure) contract function directly without loading
|
|
728
|
+
* a full contract instance. Best for one-off reads.
|
|
729
|
+
*
|
|
730
|
+
* @example
|
|
731
|
+
* ```ts
|
|
732
|
+
* const balance = await awarizon.read<bigint>({
|
|
733
|
+
* address: tokenAddress,
|
|
734
|
+
* abi: ERC20_ABI,
|
|
735
|
+
* method: "balanceOf",
|
|
736
|
+
* args: [userAddress],
|
|
737
|
+
* })
|
|
738
|
+
* ```
|
|
126
739
|
*/
|
|
127
|
-
|
|
740
|
+
read<T = unknown>(params: {
|
|
741
|
+
address: Address;
|
|
742
|
+
abi: Abi;
|
|
743
|
+
method: string;
|
|
744
|
+
args?: unknown[];
|
|
745
|
+
}): Promise<T>;
|
|
128
746
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
747
|
+
* Execute a state-mutating contract function directly without loading a full
|
|
748
|
+
* contract instance. Best for one-off writes.
|
|
749
|
+
*
|
|
750
|
+
* @example
|
|
751
|
+
* ```ts
|
|
752
|
+
* const { hash, receipt } = await awarizon.write({
|
|
753
|
+
* address: tokenAddress,
|
|
754
|
+
* abi: ERC20_ABI,
|
|
755
|
+
* method: "transfer",
|
|
756
|
+
* args: [recipient, 100n],
|
|
757
|
+
* })
|
|
758
|
+
* ```
|
|
131
759
|
*/
|
|
132
|
-
|
|
760
|
+
write(params: {
|
|
761
|
+
address: Address;
|
|
762
|
+
abi: Abi;
|
|
763
|
+
method: string;
|
|
764
|
+
args?: unknown[];
|
|
765
|
+
value?: bigint;
|
|
766
|
+
gas?: bigint;
|
|
767
|
+
}): Promise<TransactionResult>;
|
|
133
768
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
769
|
+
* Batch multiple read calls into a single RPC round-trip using multicall3.
|
|
770
|
+
* Falls back to parallel individual reads on chains where multicall3 is
|
|
771
|
+
* not deployed.
|
|
772
|
+
*
|
|
773
|
+
* @example
|
|
774
|
+
* ```ts
|
|
775
|
+
* const [balance, supply, allowance] = await awarizon.multicall([
|
|
776
|
+
* { address: tokenAddr, abi: ERC20_ABI, method: "balanceOf", args: [userAddr] },
|
|
777
|
+
* { address: tokenAddr, abi: ERC20_ABI, method: "totalSupply" },
|
|
778
|
+
* { address: tokenAddr, abi: ERC20_ABI, method: "allowance", args: [userAddr, spenderAddr] },
|
|
779
|
+
* ])
|
|
780
|
+
* ```
|
|
136
781
|
*/
|
|
137
|
-
|
|
782
|
+
multicall(calls: Array<{
|
|
783
|
+
address: Address;
|
|
784
|
+
abi: Abi;
|
|
785
|
+
method: string;
|
|
786
|
+
args?: unknown[];
|
|
787
|
+
}>): Promise<unknown[]>;
|
|
138
788
|
/**
|
|
139
|
-
* Load
|
|
140
|
-
* instance. Every function in the ABI is exposed as a direct method.
|
|
789
|
+
* Load an ERC-20 token with fully typed methods — no ABI import needed.
|
|
141
790
|
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
791
|
+
* ```ts
|
|
792
|
+
* const token = await awarizon.erc20("0x...")
|
|
793
|
+
* const balance = await token.balanceOf(userAddress)
|
|
794
|
+
* const symbol = await token.symbol()
|
|
795
|
+
* await token.transfer(recipient, 100n)
|
|
796
|
+
* ```
|
|
797
|
+
*/
|
|
798
|
+
erc20(address: Address): Promise<Erc20Contract>;
|
|
799
|
+
/**
|
|
800
|
+
* Load an ERC-721 NFT contract with fully typed methods — no ABI import needed.
|
|
144
801
|
*
|
|
145
|
-
*
|
|
146
|
-
* const
|
|
147
|
-
* const
|
|
148
|
-
* await
|
|
149
|
-
*
|
|
802
|
+
* ```ts
|
|
803
|
+
* const nft = await awarizon.erc721("0x...")
|
|
804
|
+
* const owner = await nft.ownerOf(1n)
|
|
805
|
+
* const uri = await nft.tokenURI(1n)
|
|
806
|
+
* await nft.transferFrom(from, to, 1n)
|
|
807
|
+
* ```
|
|
150
808
|
*/
|
|
151
|
-
|
|
809
|
+
erc721(address: Address): Promise<Erc721Contract>;
|
|
152
810
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
811
|
+
* Load an ERC-1155 multi-token contract with fully typed methods — no ABI import needed.
|
|
812
|
+
*
|
|
813
|
+
* ```ts
|
|
814
|
+
* const items = await awarizon.erc1155("0x...")
|
|
815
|
+
* const balance = await items.balanceOf(userAddress, 42n)
|
|
816
|
+
* const uri = await items.uri(42n)
|
|
817
|
+
* await items.safeTransferFrom(from, to, 42n, 1n, "0x")
|
|
818
|
+
* ```
|
|
155
819
|
*/
|
|
156
|
-
|
|
820
|
+
erc1155(address: Address): Promise<Erc1155Contract>;
|
|
821
|
+
/**
|
|
822
|
+
* Register a contract under a human-readable name.
|
|
823
|
+
* After registering, use `awarizon.use(name)` anywhere instead of repeating
|
|
824
|
+
* address + ABI every time.
|
|
825
|
+
*
|
|
826
|
+
* ```ts
|
|
827
|
+
* awarizon.register("USDC", { address: "0x...", abi: erc20Abi })
|
|
828
|
+
* awarizon.register("Vault", { address: "0x...", abi: vaultAbi })
|
|
829
|
+
*
|
|
830
|
+
* const usdc = await awarizon.use("USDC")
|
|
831
|
+
* const vault = await awarizon.use("Vault")
|
|
832
|
+
* ```
|
|
833
|
+
*/
|
|
834
|
+
register(name: string, config: ContractRegistryEntry): this;
|
|
835
|
+
/**
|
|
836
|
+
* Retrieve a previously registered contract by name.
|
|
837
|
+
* Throws a descriptive error if the name was never registered.
|
|
838
|
+
*
|
|
839
|
+
* ```ts
|
|
840
|
+
* const usdc = await awarizon.use("USDC")
|
|
841
|
+
* await usdc.transfer(recipient, 100n)
|
|
842
|
+
* ```
|
|
843
|
+
*/
|
|
844
|
+
use(name: string): Promise<ContractInstance>;
|
|
845
|
+
/**
|
|
846
|
+
* Remove a registered contract from the registry.
|
|
847
|
+
*
|
|
848
|
+
* ```ts
|
|
849
|
+
* awarizon.unregister("USDC")
|
|
850
|
+
* ```
|
|
851
|
+
*/
|
|
852
|
+
unregister(name: string): this;
|
|
157
853
|
/**
|
|
158
|
-
*
|
|
854
|
+
* Return all registered contract names.
|
|
159
855
|
*/
|
|
856
|
+
registeredContracts(): string[];
|
|
857
|
+
get chainId(): number;
|
|
160
858
|
get isConnected(): boolean;
|
|
859
|
+
/**
|
|
860
|
+
* Flush pending telemetry and stop background timers.
|
|
861
|
+
* Call when tearing down a long-lived SDK instance (e.g. on server shutdown).
|
|
862
|
+
*/
|
|
863
|
+
destroy(): Promise<void>;
|
|
161
864
|
}
|
|
162
865
|
|
|
163
866
|
declare const CHAINS: Record<string, Chain>;
|
|
@@ -173,4 +876,62 @@ declare function resolveChain(chain: Chain | string): Chain;
|
|
|
173
876
|
/** Returns a list of all unique supported chain IDs */
|
|
174
877
|
declare function getSupportedChainIds(): number[];
|
|
175
878
|
|
|
176
|
-
|
|
879
|
+
type TelemetryEventType = 'contract.read' | 'contract.write' | 'contract.gas_estimate' | 'wallet.create' | 'wallet.import' | 'chain.switch';
|
|
880
|
+
interface TelemetryEvent {
|
|
881
|
+
type: TelemetryEventType;
|
|
882
|
+
chain: string;
|
|
883
|
+
chainId: number;
|
|
884
|
+
functionName?: string;
|
|
885
|
+
success: boolean;
|
|
886
|
+
durationMs: number;
|
|
887
|
+
ts: number;
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Handles SDK-to-Awarizon API communication:
|
|
891
|
+
* 1. Validates the API key on first meaningful operation (5s timeout)
|
|
892
|
+
* 2. Batches usage events and flushes them fire-and-forget
|
|
893
|
+
* 3. Flushes remaining events via sendBeacon on browser page unload
|
|
894
|
+
*
|
|
895
|
+
* All telemetry failures are swallowed — they never surface to the caller.
|
|
896
|
+
* The only hard error is InvalidApiKeyError thrown from ensureValidated().
|
|
897
|
+
*/
|
|
898
|
+
declare class TelemetryClient {
|
|
899
|
+
private readonly apiKey;
|
|
900
|
+
private readonly baseUrl;
|
|
901
|
+
private validated;
|
|
902
|
+
private validationPromise;
|
|
903
|
+
private queue;
|
|
904
|
+
private flushTimer;
|
|
905
|
+
private unloadListener;
|
|
906
|
+
constructor(apiKey: string, baseUrl?: string);
|
|
907
|
+
/**
|
|
908
|
+
* Ensures the API key has been validated against the Awarizon API.
|
|
909
|
+
* Idempotent — safe to call on every operation; only hits the network once.
|
|
910
|
+
* Times out after 5 seconds to avoid hanging in degraded network conditions.
|
|
911
|
+
*
|
|
912
|
+
* @throws {InvalidApiKeyError} if the key is invalid, revoked, or unreachable
|
|
913
|
+
*/
|
|
914
|
+
ensureValidated(): Promise<void>;
|
|
915
|
+
/**
|
|
916
|
+
* Queue a usage event. Events are batched and sent periodically.
|
|
917
|
+
* Must only be called after ensureValidated() has resolved.
|
|
918
|
+
*/
|
|
919
|
+
track(event: TelemetryEvent): void;
|
|
920
|
+
/**
|
|
921
|
+
* Flush pending events and stop background timers.
|
|
922
|
+
* Call when tearing down a long-lived SDK instance (e.g. server shutdown).
|
|
923
|
+
*/
|
|
924
|
+
destroy(): Promise<void>;
|
|
925
|
+
private _validate;
|
|
926
|
+
private _startTimers;
|
|
927
|
+
private _stopTimers;
|
|
928
|
+
/**
|
|
929
|
+
* Unified flush. Pass `await = true` for graceful shutdown,
|
|
930
|
+
* `await = false` for fire-and-forget mid-session flushes.
|
|
931
|
+
*/
|
|
932
|
+
private _flush;
|
|
933
|
+
/** Uses sendBeacon for guaranteed delivery on page unload */
|
|
934
|
+
private _flushBeacon;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
export { ApiKeyRequiredError, type AwarizonConfig, AwarizonWeb3, CHAINS, type ContractConfig, type ContractInstance, ContractNotLoadedError, type ContractRegistryEntry, ERC1155_ABI, ERC20_ABI, ERC721_ABI, type Erc1155Contract, type Erc20Contract, type Erc721Contract, type EventUnsubscribe, InvalidApiKeyError, NetworkMismatchError, type PayableOptions, ProviderError, type SDKWalletInfo, TelemetryClient, type TelemetryEvent, type TelemetryEventType, UnsupportedChainError, getSupportedChainIds, resolveChain };
|