@trezo/evm 0.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/LICENSE +21 -0
- package/README.md +264 -0
- package/dist/chunk-I6Z24RI3.mjs +26 -0
- package/dist/connectkit.provider-6R2D3NSB.mjs +63 -0
- package/dist/index.d.mts +281 -0
- package/dist/index.d.ts +281 -0
- package/dist/index.js +665 -0
- package/dist/index.mjs +439 -0
- package/dist/reown.provider-QWD2VLQQ.mjs +80 -0
- package/package.json +47 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { Abi, ExtractAbiFunctionNames, AbiParametersToPrimitiveTypes, ExtractAbiFunction, Address, ExtractAbiEventNames, ExtractAbiEvent } from 'abitype';
|
|
2
|
+
export { Abi, AbiParameterToPrimitiveType, AbiParametersToPrimitiveTypes, ExtractAbiEvent, ExtractAbiEventNames, ExtractAbiFunction, ExtractAbiFunctionNames } from 'abitype';
|
|
3
|
+
import * as Chains from 'viem/chains';
|
|
4
|
+
import { ethers } from 'ethers';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
type EvmAbiType = Abi;
|
|
8
|
+
type EvmAbiFunctionArgsTuple<TAbi extends Abi, FnName extends ExtractAbiFunctionNames<TAbi>> = AbiParametersToPrimitiveTypes<ExtractAbiFunction<TAbi, FnName>["inputs"]>;
|
|
9
|
+
type EvmAbiFunctionReturn<TAbi extends EvmAbiType, FnName extends ExtractAbiFunctionNames<TAbi>> = ExtractAbiFunction<TAbi, FnName>["outputs"] extends readonly [] ? void : AbiParametersToPrimitiveTypes<ExtractAbiFunction<TAbi, FnName>["outputs"]>[0];
|
|
10
|
+
|
|
11
|
+
type ConnectkitConfig = {
|
|
12
|
+
projectId: string;
|
|
13
|
+
metadata: {
|
|
14
|
+
appName: string;
|
|
15
|
+
appIcon?: string;
|
|
16
|
+
appDescription?: string;
|
|
17
|
+
appUrl?: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type ReownConfig = {
|
|
22
|
+
projectId: string;
|
|
23
|
+
ssr?: boolean;
|
|
24
|
+
metadata: {
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
url: string;
|
|
28
|
+
icons: string[];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* ---------------------------------------------------------------------------
|
|
34
|
+
* ⚠️ AUTO-GENERATED FILE — DO NOT EDIT MANUALLY
|
|
35
|
+
* ---------------------------------------------------------------------------
|
|
36
|
+
*
|
|
37
|
+
* Generated by:
|
|
38
|
+
* scripts/genokit.ts
|
|
39
|
+
*
|
|
40
|
+
* Any manual changes will be overwritten.
|
|
41
|
+
*
|
|
42
|
+
* To update kits:
|
|
43
|
+
* 1. Add/remove files in src/kits/
|
|
44
|
+
* 2. Run:
|
|
45
|
+
* pnpm tsx scripts/genokit.ts
|
|
46
|
+
*
|
|
47
|
+
* ---------------------------------------------------------------------------
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
type EvmKitConfigType = {
|
|
51
|
+
name: "connectkit";
|
|
52
|
+
config: ConnectkitConfig;
|
|
53
|
+
} | {
|
|
54
|
+
name: "reown";
|
|
55
|
+
config: ReownConfig;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
declare const EvmChains: typeof Chains;
|
|
59
|
+
type EvmAddressType = Address;
|
|
60
|
+
type EvmChainsType = typeof EvmChains;
|
|
61
|
+
type EvmConfigType<TAbi extends EvmAbiType> = {
|
|
62
|
+
abi: TAbi;
|
|
63
|
+
address: EvmAddressType;
|
|
64
|
+
chains: [Chains.Chain, ...Chains.Chain[]];
|
|
65
|
+
rpcUrl?: string;
|
|
66
|
+
kit: EvmKitConfigType;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
type EvmStoreType<TAbi extends EvmAbiType> = {
|
|
70
|
+
wallet: {
|
|
71
|
+
isConnected: boolean;
|
|
72
|
+
isConnecting: boolean;
|
|
73
|
+
address?: EvmAddressType;
|
|
74
|
+
chainId?: number;
|
|
75
|
+
error?: Error;
|
|
76
|
+
};
|
|
77
|
+
provider: {
|
|
78
|
+
isAvailable: boolean;
|
|
79
|
+
error?: Error;
|
|
80
|
+
};
|
|
81
|
+
_signer?: ethers.Signer;
|
|
82
|
+
_provider?: ethers.Provider;
|
|
83
|
+
_contract?: ethers.Contract;
|
|
84
|
+
_abi?: TAbi;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
declare function create<TAbi extends EvmAbiType>(config: EvmConfigType<TAbi>): {
|
|
88
|
+
(): {
|
|
89
|
+
call: {
|
|
90
|
+
queryFn: <FnName extends ExtractAbiFunctionNames<TAbi, "view" | "pure">>(functionName: FnName, args: EvmAbiFunctionArgsTuple<TAbi, FnName>) => Promise<{
|
|
91
|
+
data?: EvmAbiFunctionReturn<TAbi, FnName>;
|
|
92
|
+
error?: Error;
|
|
93
|
+
}>;
|
|
94
|
+
mutateFn: <FnName extends ExtractAbiFunctionNames<TAbi, "nonpayable" | "payable">>(functionName: FnName, args: EvmAbiFunctionArgsTuple<TAbi, FnName>) => Promise<{
|
|
95
|
+
data?: {
|
|
96
|
+
hash: string;
|
|
97
|
+
};
|
|
98
|
+
error?: Error;
|
|
99
|
+
}>;
|
|
100
|
+
listenFn: <EventName extends ExtractAbiEventNames<TAbi>>(eventName: EventName, listener: (...args: AbiParametersToPrimitiveTypes<ExtractAbiEvent<TAbi, EventName>["inputs"]>) => void) => (() => void);
|
|
101
|
+
};
|
|
102
|
+
web3Provider: {
|
|
103
|
+
isAvailable: boolean;
|
|
104
|
+
error?: Error;
|
|
105
|
+
};
|
|
106
|
+
wallet: {
|
|
107
|
+
account: {
|
|
108
|
+
isConnected: boolean;
|
|
109
|
+
isConnecting: boolean;
|
|
110
|
+
address?: EvmAddressType;
|
|
111
|
+
chainId?: number;
|
|
112
|
+
error?: Error;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
call: {
|
|
117
|
+
queryFn: <FnName extends ExtractAbiFunctionNames<TAbi, "view" | "pure">>(functionName: FnName, args: EvmAbiFunctionArgsTuple<TAbi, FnName>) => Promise<{
|
|
118
|
+
data?: EvmAbiFunctionReturn<TAbi, FnName>;
|
|
119
|
+
error?: Error;
|
|
120
|
+
}>;
|
|
121
|
+
mutateFn: <FnName extends ExtractAbiFunctionNames<TAbi, "nonpayable" | "payable">>(functionName: FnName, args: EvmAbiFunctionArgsTuple<TAbi, FnName>) => Promise<{
|
|
122
|
+
data?: {
|
|
123
|
+
hash: string;
|
|
124
|
+
};
|
|
125
|
+
error?: Error;
|
|
126
|
+
}>;
|
|
127
|
+
listenFn: <EventName extends ExtractAbiEventNames<TAbi>>(eventName: EventName, listener: (...args: AbiParametersToPrimitiveTypes<ExtractAbiEvent<TAbi, EventName>["inputs"]>) => void) => (() => void);
|
|
128
|
+
};
|
|
129
|
+
getState: () => EvmStoreType<TAbi>;
|
|
130
|
+
subscribe: (onStoreChange: () => void) => () => void;
|
|
131
|
+
Provider: React.FC<{
|
|
132
|
+
children: React.ReactNode;
|
|
133
|
+
}>;
|
|
134
|
+
ConnectButton: React.FC<{
|
|
135
|
+
label?: string;
|
|
136
|
+
showBalance?: boolean;
|
|
137
|
+
showAvatar?: boolean;
|
|
138
|
+
children?: (props: any) => React.ReactNode;
|
|
139
|
+
}>;
|
|
140
|
+
} & {
|
|
141
|
+
call: {
|
|
142
|
+
queryFn: <FnName extends ExtractAbiFunctionNames<TAbi, "view" | "pure">>(functionName: FnName, args: EvmAbiFunctionArgsTuple<TAbi, FnName>) => Promise<{
|
|
143
|
+
data?: EvmAbiFunctionReturn<TAbi, FnName>;
|
|
144
|
+
error?: Error;
|
|
145
|
+
}>;
|
|
146
|
+
mutateFn: <FnName extends ExtractAbiFunctionNames<TAbi, "nonpayable" | "payable">>(functionName: FnName, args: EvmAbiFunctionArgsTuple<TAbi, FnName>) => Promise<{
|
|
147
|
+
data?: {
|
|
148
|
+
hash: string;
|
|
149
|
+
};
|
|
150
|
+
error?: Error;
|
|
151
|
+
}>;
|
|
152
|
+
listenFn: <EventName extends ExtractAbiEventNames<TAbi>>(eventName: EventName, listener: (...args: AbiParametersToPrimitiveTypes<ExtractAbiEvent<TAbi, EventName>["inputs"]>) => void) => (() => void);
|
|
153
|
+
};
|
|
154
|
+
getState: () => EvmStoreType<TAbi>;
|
|
155
|
+
subscribe: (onStoreChange: () => void) => () => void;
|
|
156
|
+
Provider: React.FC<{
|
|
157
|
+
children: React.ReactNode;
|
|
158
|
+
}>;
|
|
159
|
+
ConnectButton: React.FC<{
|
|
160
|
+
label?: string;
|
|
161
|
+
showBalance?: boolean;
|
|
162
|
+
showAvatar?: boolean;
|
|
163
|
+
children?: (props: any) => React.ReactNode;
|
|
164
|
+
}>;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Throws an Error with a specified message.
|
|
169
|
+
*
|
|
170
|
+
* This utility can be used to enforce required parameters or invalid states.
|
|
171
|
+
*
|
|
172
|
+
* @param message - Optional custom error message. Defaults to `"An unexpected error occurred"`.
|
|
173
|
+
*
|
|
174
|
+
* @throws Always throws an `Error` with the provided message.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* throwError("Invalid contract address");
|
|
178
|
+
* // Throws Error: "Invalid contract address"
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* throwError();
|
|
182
|
+
* // Throws Error: "An unexpected error occurred"
|
|
183
|
+
*/
|
|
184
|
+
declare function throwError(message?: string): never;
|
|
185
|
+
/**
|
|
186
|
+
* mapEthersError
|
|
187
|
+
* ------------------------------------------------------------
|
|
188
|
+
* Converts low-level Ethers.js / RPC / wallet errors into
|
|
189
|
+
* human-readable messages suitable for UI display.
|
|
190
|
+
*
|
|
191
|
+
* Ethereum libraries such as ethers.js emit structured errors
|
|
192
|
+
* that include a `code` property. These codes represent
|
|
193
|
+
* categories such as:
|
|
194
|
+
*
|
|
195
|
+
* - Blockchain execution errors
|
|
196
|
+
* - Wallet interaction errors
|
|
197
|
+
* - RPC/network failures
|
|
198
|
+
* - Argument validation problems
|
|
199
|
+
*
|
|
200
|
+
* This utility normalizes those errors into friendly messages.
|
|
201
|
+
*
|
|
202
|
+
* References:
|
|
203
|
+
* https://docs.ethers.org/v6/api/utils/errors/
|
|
204
|
+
*/
|
|
205
|
+
declare const mapEthersError: (error: any) => string;
|
|
206
|
+
|
|
207
|
+
interface PollConfig {
|
|
208
|
+
provider: ethers.Provider;
|
|
209
|
+
contract: ethers.Contract;
|
|
210
|
+
eventName: string;
|
|
211
|
+
intervalMs?: number;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Manually polls for logs when eth_newFilter is unavailable
|
|
215
|
+
*/
|
|
216
|
+
declare const createEventPoller: ({ provider, contract, eventName, intervalMs }: PollConfig, listener: (...args: any[]) => void) => () => void;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Converts a value from Wei to Ether.
|
|
220
|
+
*
|
|
221
|
+
* Uses `ethers.formatEther` to format the smallest Ethereum unit (Wei)
|
|
222
|
+
* into a human-readable Ether value.
|
|
223
|
+
*
|
|
224
|
+
* @param num - The value in Wei.
|
|
225
|
+
*
|
|
226
|
+
* @returns A string representing the value converted to Ether.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* fromWei(1000000000000000000)
|
|
230
|
+
* // "1.0"
|
|
231
|
+
*/
|
|
232
|
+
declare const fromWei: (value: bigint | string | number, decimals?: number) => string;
|
|
233
|
+
/**
|
|
234
|
+
* Converts a value from Ether to Wei.
|
|
235
|
+
*
|
|
236
|
+
* Uses `ethers.parseEther` to convert a human-readable Ether value
|
|
237
|
+
* into Wei, the smallest Ethereum unit.
|
|
238
|
+
*
|
|
239
|
+
* @param num - The Ether value to convert.
|
|
240
|
+
*
|
|
241
|
+
* @returns A bigint representing the value in Wei.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* toWei(1)
|
|
245
|
+
* // 1000000000000000000n
|
|
246
|
+
*/
|
|
247
|
+
declare const toWei: (value: string, decimals?: number) => bigint;
|
|
248
|
+
/**
|
|
249
|
+
* Formats an Ethereum address into a shortened, human-readable string.
|
|
250
|
+
*
|
|
251
|
+
* Keeps the first 4 characters of the address and a specified number of characters at the end.
|
|
252
|
+
* The middle (or end) can be replaced with a custom separator. Supported separators
|
|
253
|
+
* are `"..."`, `"-"`, `">"`, `"→"`.
|
|
254
|
+
*
|
|
255
|
+
* @param address - The full Ethereum address to format.
|
|
256
|
+
* @param options - Optional formatting options:
|
|
257
|
+
* - `endChars` - Number of characters to keep at the end (default `6`).
|
|
258
|
+
* - `separator` - String to place between start and end. Suggestions: `"..." | "-" | ">" | "→"` (default `"..."`).
|
|
259
|
+
* - `position` - `"middle"` (default) or `"end"`. `"end"` appends the separator after the start characters.
|
|
260
|
+
*
|
|
261
|
+
* @returns The formatted address string.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* formatAddress("0x742d35Cc6634C0532925a3b844Bc454e4438f44e")
|
|
265
|
+
* // "0x74d3...38f44e"
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* formatAddress("0x742d35Cc6634C0532925a3b844Bc454e4438f44e", { endChars: 4, separator: "→" })
|
|
269
|
+
* // "0x74d3→f44e"
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* formatAddress("0x742d35Cc6634C0532925a3b844Bc454e4438f44e", { endChars: 0, separator: "...", position: "end" })
|
|
273
|
+
* // "0x74d3..."
|
|
274
|
+
*/
|
|
275
|
+
declare function formatAddress(address: string, options?: {
|
|
276
|
+
endChars?: number;
|
|
277
|
+
separator?: "..." | "-" | ">" | "→";
|
|
278
|
+
position?: "middle" | "end";
|
|
279
|
+
}): string;
|
|
280
|
+
|
|
281
|
+
export { type EvmAbiFunctionArgsTuple, type EvmAbiFunctionReturn, type EvmAbiType, type EvmAddressType, EvmChains, type EvmChainsType, type EvmConfigType, type EvmStoreType, create, createEventPoller, formatAddress, fromWei, mapEthersError, throwError, toWei };
|