viem 0.0.1-alpha.0 → 0.0.1-alpha.2

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.
@@ -1,7 +1,74 @@
1
- import { A as Address, f as ByteArray, H as Hex } from './rpc-655c0ba4.js';
1
+ import { Abi, AbiFunction, ExtractAbiFunction, AbiParametersToPrimitiveTypes, AbiParameter, ExtractAbiFunctionNames } from 'abitype';
2
+ import { H as Hex, A as Address, f as ByteArray } from './rpc-655c0ba4.js';
2
3
  import { B as BaseError } from './BaseError-7688f84e.js';
3
4
  import { R as RpcError } from './rpc-3c0e3985.js';
4
5
 
6
+ type ExtractArgsFromAbi<TAbi extends Abi | readonly unknown[], TFunctionName extends string, TAbiFunction extends AbiFunction & {
7
+ type: 'function';
8
+ } = TAbi extends Abi ? ExtractAbiFunction<TAbi, TFunctionName> : AbiFunction & {
9
+ type: 'function';
10
+ }, TArgs = AbiParametersToPrimitiveTypes<TAbiFunction['inputs']>, FailedToParseArgs = ([TArgs] extends [never] ? true : false) | (readonly unknown[] extends TArgs ? true : false)> = true extends FailedToParseArgs ? {
11
+ /**
12
+ * Arguments to pass contract method
13
+ *
14
+ * Use a [const assertion](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions) on {@link abi} for type inference.
15
+ */
16
+ args?: readonly unknown[];
17
+ } : TArgs extends readonly [] ? {
18
+ args?: never;
19
+ } : {
20
+ /** Arguments to pass contract method */ args: TArgs;
21
+ };
22
+
23
+ declare function decodeAbi<TParams extends readonly AbiParameter[]>({ data, params, }: {
24
+ data: Hex;
25
+ params: TParams;
26
+ }): AbiParametersToPrimitiveTypes<TParams>;
27
+ declare class AbiDecodingDataSizeInvalidError extends BaseError {
28
+ name: string;
29
+ constructor(size: number);
30
+ }
31
+ declare class InvalidAbiDecodingTypeError extends BaseError {
32
+ name: string;
33
+ constructor(type: string);
34
+ }
35
+
36
+ /**
37
+ * @description Encodes a list of primitive values into an ABI-encoded hex value.
38
+ */
39
+ declare function encodeAbi<TParams extends readonly AbiParameter[]>({ params, values, }: {
40
+ params: TParams;
41
+ values: AbiParametersToPrimitiveTypes<TParams>;
42
+ }): `0x${string}` | undefined;
43
+ declare class AbiEncodingArrayLengthMismatchError extends BaseError {
44
+ name: string;
45
+ constructor({ expectedLength, givenLength, type, }: {
46
+ expectedLength: number;
47
+ givenLength: number;
48
+ type: string;
49
+ });
50
+ }
51
+ declare class AbiEncodingLengthMismatchError extends BaseError {
52
+ name: string;
53
+ constructor({ expectedLength, givenLength, }: {
54
+ expectedLength: number;
55
+ givenLength: number;
56
+ });
57
+ }
58
+ declare class InvalidAbiEncodingTypeError extends BaseError {
59
+ name: string;
60
+ constructor(type: string);
61
+ }
62
+ declare class InvalidArrayError extends BaseError {
63
+ name: string;
64
+ constructor(value: unknown);
65
+ }
66
+
67
+ declare function encodeFunctionParams<TAbi extends Abi = Abi, TFunctionName extends ExtractAbiFunctionNames<TAbi> = any>({ abi, args, functionName, }: {
68
+ abi: TAbi;
69
+ functionName: TFunctionName;
70
+ } & ExtractArgsFromAbi<TAbi, TFunctionName>): `0x${string}`;
71
+
5
72
  declare function getAddress(address: Address): `0x${string}`;
6
73
 
7
74
  type GetCreateAddressOptions = {
@@ -109,14 +176,16 @@ type PadOptions = {
109
176
  dir?: 'left' | 'right';
110
177
  size?: number;
111
178
  };
112
- declare function pad(hexOrBytes: Hex | ByteArray, { dir, size }?: PadOptions): `0x${string}` | Uint8Array;
179
+ type PadResult<TValue extends ByteArray | Hex> = TValue extends Hex ? Hex : ByteArray;
180
+ declare function pad<TValue extends ByteArray | Hex>(hexOrBytes: TValue, { dir, size }?: PadOptions): PadResult<TValue>;
113
181
  declare function padHex(hex_: Hex, { dir, size }?: PadOptions): `0x${string}`;
114
182
  declare function padBytes(bytes: ByteArray, { dir, size }?: PadOptions): Uint8Array;
115
183
 
116
184
  type TrimOptions = {
117
185
  dir?: 'left' | 'right';
118
186
  };
119
- declare function trim(hexOrBytes: Hex | ByteArray, { dir }?: TrimOptions): string | Uint8Array;
187
+ type TrimResult<TValue extends ByteArray | Hex> = TValue extends Hex ? Hex : ByteArray;
188
+ declare function trim<TValue extends ByteArray | Hex>(hexOrBytes: TValue, { dir }?: TrimOptions): TrimResult<TValue>;
120
189
 
121
190
  /**
122
191
  * @description Retrieves the size of the value (in bytes).
@@ -164,7 +233,7 @@ declare function bytesToHex(value: ByteArray): Hex;
164
233
  * @description Encodes a string, number, bigint, or ByteArray into a hex string
165
234
  */
166
235
  declare function encodeHex(value: string | number | bigint | boolean | ByteArray): Hex;
167
- type NumberToHexOpts = {
236
+ type NumberToHexOpts$1 = {
168
237
  signed?: boolean;
169
238
  size: number;
170
239
  } | {
@@ -174,7 +243,7 @@ type NumberToHexOpts = {
174
243
  /**
175
244
  * @description Encodes a number or bigint into a hex string
176
245
  */
177
- declare function numberToHex(value_: number | bigint, opts?: NumberToHexOpts): Hex;
246
+ declare function numberToHex(value_: number | bigint, opts?: NumberToHexOpts$1): Hex;
178
247
  /**
179
248
  * @description Encodes a UTF-8 string into a hex string
180
249
  */
@@ -193,7 +262,7 @@ declare function hexToBytes(hex_: Hex): ByteArray;
193
262
  /**
194
263
  * @description Encodes a number into a byte array.
195
264
  */
196
- declare function numberToBytes(value: bigint | number, opts?: NumberToHexOpts): Uint8Array;
265
+ declare function numberToBytes(value: bigint | number, opts?: NumberToHexOpts$1): Uint8Array;
197
266
  /**
198
267
  * @description Encodes a UTF-8 string into a byte array.
199
268
  */
@@ -232,18 +301,22 @@ type DecodeHexResponse<TTo> = TTo extends 'string' ? string : TTo extends 'bigin
232
301
  * @description Decodes a hex string into a string, number, bigint, boolean, or bytes32 array.
233
302
  */
234
303
  declare function decodeHex<TTo extends 'string' | 'bigint' | 'number' | 'bytes' | 'boolean'>(hex: Hex, to: TTo): DecodeHexResponse<TTo>;
304
+ type HexToBigIntOpts = {
305
+ signed?: boolean;
306
+ };
235
307
  /**
236
308
  * @description Decodes a hex string into a bigint.
237
309
  */
238
- declare function hexToBigInt(hex: Hex): bigint;
310
+ declare function hexToBigInt(hex: Hex, opts?: HexToBigIntOpts): bigint;
239
311
  /**
240
312
  * @description Decodes a hex string into a boolean.
241
313
  */
242
314
  declare function hexToBool(hex: Hex): boolean;
315
+ type NumberToHexOpts = HexToBigIntOpts;
243
316
  /**
244
317
  * @description Decodes a hex string into a number.
245
318
  */
246
- declare function hexToNumber(hex: Hex): number;
319
+ declare function hexToNumber(hex: Hex, opts?: NumberToHexOpts): number;
247
320
  /**
248
321
  * @description Decodes a hex string into a UTF-8 string.
249
322
  */
@@ -254,7 +327,7 @@ declare function decodeRlp<TTo extends 'bytes' | 'hex'>(value: ByteArray | Hex,
254
327
 
255
328
  declare const getEventSignature: (event: `${string}(${string})`) => `0x${string}`;
256
329
 
257
- declare const getFunctionSignature: (fn: string) => string;
330
+ declare const getFunctionSignature: (fn: string) => `0x${string}`;
258
331
 
259
332
  type To = 'hex' | 'bytes';
260
333
  type Keccak256Hash<TTo extends To> = TTo extends 'bytes' ? ByteArray : TTo extends 'hex' ? Hex : never;
@@ -272,4 +345,4 @@ declare function parseEther(ether: `${number}`, unit?: 'wei' | 'gwei'): bigint;
272
345
 
273
346
  declare function parseGwei(ether: `${number}`, unit?: 'wei'): bigint;
274
347
 
275
- export { formatGwei as $, getFunctionSignature as A, formatEther as B, isAddress as C, isAddressEqual as D, EncodeRlpResponse as E, isBytes as F, GetContractAddressOptions as G, isHex as H, InternalRpcError as I, JsonRpcVersionUnsupportedError as J, hexToBigInt as K, LimitExceededRpcError as L, MethodNotFoundRpcError as M, hexToBool as N, hexToBytes as O, ParseRpcError as P, hexToString as Q, ResourceNotFoundRpcError as R, keccak256 as S, TransactionRejectedRpcError as T, numberToBytes as U, pad as V, padBytes as W, padHex as X, parseEther as Y, parseGwei as Z, parseUnit as _, GetCreateAddressOptions as a, formatUnit as a0, hexToNumber as a1, numberToHex as a2, size as a3, slice as a4, sliceBytes as a5, sliceHex as a6, stringToBytes as a7, stringToHex as a8, trim as a9, buildRequest as aa, GetCreate2AddressOptions as b, InvalidInputRpcError as c, InvalidParamsRpcError as d, InvalidRequestRpcError as e, MethodNotSupportedRpcError as f, ResourceUnavailableRpcError as g, RpcRequestError as h, bytesToHex as i, bytesToString as j, boolToBytes as k, boolToHex as l, bytesToBigint as m, bytesToBool as n, bytesToNumber as o, decodeBytes as p, decodeHex as q, decodeRlp as r, encodeBytes as s, encodeHex as t, encodeRlp as u, getAddress as v, getContractAddress as w, getCreateAddress as x, getCreate2Address as y, getEventSignature as z };
348
+ export { hexToString as $, AbiDecodingDataSizeInvalidError as A, encodeFunctionParams as B, encodeHex as C, encodeRlp as D, EncodeRlpResponse as E, getAddress as F, GetContractAddressOptions as G, getContractAddress as H, InvalidAbiDecodingTypeError as I, JsonRpcVersionUnsupportedError as J, getCreateAddress as K, LimitExceededRpcError as L, MethodNotFoundRpcError as M, getCreate2Address as N, getEventSignature as O, ParseRpcError as P, getFunctionSignature as Q, ResourceNotFoundRpcError as R, formatEther as S, TransactionRejectedRpcError as T, isAddress as U, isAddressEqual as V, isBytes as W, isHex as X, hexToBigInt as Y, hexToBool as Z, hexToBytes as _, AbiEncodingArrayLengthMismatchError as a, keccak256 as a0, numberToBytes as a1, pad as a2, padBytes as a3, padHex as a4, parseEther as a5, parseGwei as a6, parseUnit as a7, formatGwei as a8, formatUnit as a9, hexToNumber as aa, numberToHex as ab, size as ac, slice as ad, sliceBytes as ae, sliceHex as af, stringToBytes as ag, stringToHex as ah, trim as ai, buildRequest as aj, AbiEncodingLengthMismatchError as b, GetCreateAddressOptions as c, GetCreate2AddressOptions as d, InvalidAbiEncodingTypeError as e, InvalidArrayError as f, InternalRpcError as g, InvalidInputRpcError as h, InvalidParamsRpcError as i, InvalidRequestRpcError as j, MethodNotSupportedRpcError as k, ResourceUnavailableRpcError as l, RpcRequestError as m, bytesToHex as n, bytesToString as o, boolToBytes as p, boolToHex as q, bytesToBigint as r, bytesToBool as s, bytesToNumber as t, decodeAbi as u, decodeBytes as v, decodeHex as w, decodeRlp as x, encodeAbi as y, encodeBytes as z };
@@ -1,7 +1,8 @@
1
- export { E as EncodeRlpResponse, G as GetContractAddressOptions, b as GetCreate2AddressOptions, a as GetCreateAddressOptions, I as InternalRpcError, c as InvalidInputRpcError, d as InvalidParamsRpcError, e as InvalidRequestRpcError, J as JsonRpcVersionUnsupportedError, L as LimitExceededRpcError, M as MethodNotFoundRpcError, f as MethodNotSupportedRpcError, P as ParseRpcError, R as ResourceNotFoundRpcError, g as ResourceUnavailableRpcError, h as RpcRequestError, T as TransactionRejectedRpcError, k as boolToBytes, l as boolToHex, aa as buildRequest, m as bytesToBigint, n as bytesToBool, i as bytesToHex, o as bytesToNumber, j as bytesToString, p as decodeBytes, q as decodeHex, r as decodeRlp, s as encodeBytes, t as encodeHex, u as encodeRlp, B as formatEther, $ as formatGwei, a0 as formatUnit, v as getAddress, w as getContractAddress, y as getCreate2Address, x as getCreateAddress, z as getEventSignature, A as getFunctionSignature, K as hexToBigInt, N as hexToBool, O as hexToBytes, a1 as hexToNumber, Q as hexToString, C as isAddress, D as isAddressEqual, F as isBytes, H as isHex, S as keccak256, U as numberToBytes, a2 as numberToHex, V as pad, W as padBytes, X as padHex, Y as parseEther, Z as parseGwei, _ as parseUnit, a3 as size, a4 as slice, a5 as sliceBytes, a6 as sliceHex, a7 as stringToBytes, a8 as stringToHex, a9 as trim } from '../parseGwei-a7d0bcb2.js';
1
+ export { A as AbiDecodingDataSizeInvalidError, a as AbiEncodingArrayLengthMismatchError, b as AbiEncodingLengthMismatchError, E as EncodeRlpResponse, G as GetContractAddressOptions, d as GetCreate2AddressOptions, c as GetCreateAddressOptions, g as InternalRpcError, I as InvalidAbiDecodingTypeError, e as InvalidAbiEncodingTypeError, f as InvalidArrayError, h as InvalidInputRpcError, i as InvalidParamsRpcError, j as InvalidRequestRpcError, J as JsonRpcVersionUnsupportedError, L as LimitExceededRpcError, M as MethodNotFoundRpcError, k as MethodNotSupportedRpcError, P as ParseRpcError, R as ResourceNotFoundRpcError, l as ResourceUnavailableRpcError, m as RpcRequestError, T as TransactionRejectedRpcError, p as boolToBytes, q as boolToHex, aj as buildRequest, r as bytesToBigint, s as bytesToBool, n as bytesToHex, t as bytesToNumber, o as bytesToString, u as decodeAbi, v as decodeBytes, w as decodeHex, x as decodeRlp, y as encodeAbi, z as encodeBytes, B as encodeFunctionParams, C as encodeHex, D as encodeRlp, S as formatEther, a8 as formatGwei, a9 as formatUnit, F as getAddress, H as getContractAddress, N as getCreate2Address, K as getCreateAddress, O as getEventSignature, Q as getFunctionSignature, Y as hexToBigInt, Z as hexToBool, _ as hexToBytes, aa as hexToNumber, $ as hexToString, U as isAddress, V as isAddressEqual, W as isBytes, X as isHex, a0 as keccak256, a1 as numberToBytes, ab as numberToHex, a2 as pad, a3 as padBytes, a4 as padHex, a5 as parseEther, a6 as parseGwei, a7 as parseUnit, ac as size, ad as slice, ae as sliceBytes, af as sliceHex, ag as stringToBytes, ah as stringToHex, ai as trim } from '../parseGwei-fd7a0f7d.js';
2
2
  export { B as BaseError } from '../BaseError-7688f84e.js';
3
3
  export { B as BlockFormatter, E as ExtractFormatter, e as Formatted, F as FormattedBlock, a as FormattedTransaction, h as FormattedTransactionReceipt, b as FormattedTransactionRequest, g as TransactionFormatter, i as TransactionReceiptFormatter, T as TransactionRequestFormatter, j as format, f as formatBlock, c as formatTransaction, d as formatTransactionRequest } from '../transactionRequest-ade896ac.js';
4
4
  export { H as HttpRequestError, R as RpcError, T as TimeoutError, r as rpc } from '../rpc-3c0e3985.js';
5
+ import 'abitype';
5
6
  import '../rpc-655c0ba4.js';
6
7
  import '../chains.js';
7
8
  import '@wagmi/chains';
@@ -24,10 +24,13 @@ import {
24
24
  bytesToHex,
25
25
  bytesToNumber,
26
26
  bytesToString,
27
+ decodeAbi,
27
28
  decodeBytes,
28
29
  decodeHex,
29
30
  decodeRlp,
31
+ encodeAbi,
30
32
  encodeBytes,
33
+ encodeFunctionParams,
31
34
  encodeHex,
32
35
  encodeRlp,
33
36
  extractFunctionName,
@@ -72,7 +75,7 @@ import {
72
75
  stringToBytes,
73
76
  stringToHex,
74
77
  trim
75
- } from "../chunk-GI67STNV.js";
78
+ } from "../chunk-3EOU525X.js";
76
79
  export {
77
80
  BaseError,
78
81
  HttpRequestError,
@@ -99,10 +102,13 @@ export {
99
102
  bytesToHex,
100
103
  bytesToNumber,
101
104
  bytesToString,
105
+ decodeAbi,
102
106
  decodeBytes,
103
107
  decodeHex,
104
108
  decodeRlp,
109
+ encodeAbi,
105
110
  encodeBytes,
111
+ encodeFunctionParams,
106
112
  encodeHex,
107
113
  encodeRlp,
108
114
  extractFunctionName,
@@ -1,7 +1,7 @@
1
1
  import { Chain, Formatter } from './chains.js';
2
2
  import { H as Hex, d as BlockTag, M as MergeIntersectionProperties, v as TransactionRequest, K as EstimateGasParameters, A as Address, k as Hash, F as FeeHistory, L as Log, r as RpcTransactionReceipt, T as TransactionReceipt, N as TransactionType, D as Transaction, q as RpcTransaction, Q as Quantity, f as ByteArray } from './rpc-655c0ba4.js';
3
3
  import { T as TransactionRequestFormatter, e as Formatted, F as FormattedBlock, B as BlockFormatter, a as FormattedTransaction, g as TransactionFormatter, h as FormattedTransactionReceipt, i as TransactionReceiptFormatter, E as ExtractFormatter } from './transactionRequest-ade896ac.js';
4
- import { P as PublicClient, T as TestClient, W as WalletClient } from './createWalletClient-c40fef16.js';
4
+ import { P as PublicClient, T as TestClient, W as WalletClient } from './createWalletClient-915223f3.js';
5
5
  import { B as BaseError } from './BaseError-7688f84e.js';
6
6
  import { W as WalletPermission, a as WatchAssetParams } from './eip1193-8f7c22ce.js';
7
7
 
@@ -12,9 +12,8 @@ type Filter<TFilterType extends FilterType = 'event'> = {
12
12
  };
13
13
 
14
14
  type FormattedCall<TFormatter extends Formatter | undefined = Formatter> = MergeIntersectionProperties<Formatted<TFormatter, TransactionRequest, true>, TransactionRequest>;
15
- type CallArgs<TChain extends Chain = Chain> = {
15
+ type CallArgs<TChain extends Chain = Chain> = FormattedCall<TransactionRequestFormatter<TChain>> & {
16
16
  chain?: TChain;
17
- request: FormattedCall<TransactionRequestFormatter<TChain>>;
18
17
  } & ({
19
18
  /** The balance of the account at a block number. */
20
19
  blockNumber?: bigint;
@@ -27,7 +26,7 @@ type CallArgs<TChain extends Chain = Chain> = {
27
26
  type CallResponse = {
28
27
  data: Hex | undefined;
29
28
  };
30
- declare function call<TChain extends Chain>(client: PublicClient, { blockNumber, blockTag, chain, request }: CallArgs<TChain>): Promise<CallResponse>;
29
+ declare function call<TChain extends Chain>(client: PublicClient, { blockNumber, blockTag, chain, from, accessList, data, gas, gasPrice, maxFeePerGas, maxPriorityFeePerGas, nonce, to, value, ...rest }: CallArgs<TChain>): Promise<CallResponse>;
31
30
 
32
31
  type CreatePendingTransactionFilterResponse = Filter<'transaction'>;
33
32
  declare function createPendingTransactionFilter(client: PublicClient): Promise<CreatePendingTransactionFilterResponse>;
@@ -35,9 +34,7 @@ declare function createPendingTransactionFilter(client: PublicClient): Promise<C
35
34
  type CreateBlockFilterResponse = Filter<'block'>;
36
35
  declare function createBlockFilter(client: PublicClient): Promise<CreateBlockFilterResponse>;
37
36
 
38
- type EstimateGasArgs = {
39
- request: EstimateGasParameters;
40
- } & ({
37
+ type EstimateGasArgs = EstimateGasParameters & ({
41
38
  /** The balance of the account at a block number. */
42
39
  blockNumber?: bigint;
43
40
  blockTag?: never;
@@ -50,7 +47,7 @@ type EstimateGasResponse = bigint;
50
47
  /**
51
48
  * @description Estimates the gas necessary to complete a transaction without submitting it to the network.
52
49
  */
53
- declare function estimateGas(client: PublicClient, { blockNumber, blockTag, request: { data, from, gas, gasPrice, maxFeePerGas, maxPriorityFeePerGas, to, value, }, }: EstimateGasArgs): Promise<EstimateGasResponse>;
50
+ declare function estimateGas(client: PublicClient, { blockNumber, blockTag, data, from, gas, gasPrice, maxFeePerGas, maxPriorityFeePerGas, to, value, }: EstimateGasArgs): Promise<EstimateGasResponse>;
54
51
 
55
52
  type GetBalanceArgs = {
56
53
  /** The address of the account. */
@@ -167,6 +164,12 @@ type GetFilterChangesArgs<TFilterType extends FilterType> = {
167
164
  type GetFilterChangesResponse<TFilterType extends FilterType> = TFilterType extends 'event' ? Log[] : Hash[];
168
165
  declare function getFilterChanges<TFilterType extends FilterType>(client: PublicClient, { filter }: GetFilterChangesArgs<TFilterType>): Promise<GetFilterChangesResponse<TFilterType>>;
169
166
 
167
+ type GetFilterLogsArgs = {
168
+ filter: Filter<'event'>;
169
+ };
170
+ type GetFilterLogsResponse = Log[];
171
+ declare function getFilterLogs<TFilterType extends FilterType>(client: PublicClient, { filter }: GetFilterLogsArgs): Promise<GetFilterLogsResponse>;
172
+
170
173
  type GetGasPriceResponse = bigint;
171
174
  /**
172
175
  * @description Returns the current price of gas (in wei).
@@ -391,13 +394,9 @@ type RevertArgs = {
391
394
  };
392
395
  declare function revert(client: TestClient, { id }: RevertArgs): Promise<void>;
393
396
 
394
- type SendUnsignedTransactionArgs = {
395
- request: TransactionRequest;
396
- };
397
- type SendUnsignedTransactionResponse = {
398
- hash: `0x${string}`;
399
- };
400
- declare function sendUnsignedTransaction(client: TestClient, { request }: SendUnsignedTransactionArgs): Promise<SendUnsignedTransactionResponse>;
397
+ type SendUnsignedTransactionArgs = TransactionRequest;
398
+ type SendUnsignedTransactionResponse = Hash;
399
+ declare function sendUnsignedTransaction(client: TestClient, request: SendUnsignedTransactionArgs): Promise<SendUnsignedTransactionResponse>;
401
400
 
402
401
  declare function setAutomine(client: TestClient, enabled: boolean): Promise<void>;
403
402
 
@@ -489,6 +488,8 @@ declare function stopImpersonatingAccount(client: TestClient, { address }: StopI
489
488
 
490
489
  declare function addChain(client: WalletClient, chain: Chain): Promise<void>;
491
490
 
491
+ declare function getAccounts(client: WalletClient): Promise<`0x${string}`[]>;
492
+
492
493
  type GetPermissionsResponse = WalletPermission[];
493
494
  declare function getPermissions(client: WalletClient): Promise<WalletPermission[]>;
494
495
 
@@ -503,14 +504,11 @@ type RequestPermissionsResponse = WalletPermission[];
503
504
  declare function requestPermissions(client: WalletClient, permissions: RequestPermissionsArgs): Promise<WalletPermission[]>;
504
505
 
505
506
  type FormattedTransactionRequest<TFormatter extends Formatter | undefined = Formatter> = MergeIntersectionProperties<Formatted<TFormatter, TransactionRequest, true>, TransactionRequest>;
506
- type SendTransactionArgs<TChain extends Chain = Chain> = {
507
+ type SendTransactionArgs<TChain extends Chain = Chain> = FormattedTransactionRequest<TransactionRequestFormatter<TChain>> & {
507
508
  chain?: TChain;
508
- request: FormattedTransactionRequest<TransactionRequestFormatter<TChain>>;
509
- };
510
- type SendTransactionResponse = {
511
- hash: `0x${string}`;
512
509
  };
513
- declare function sendTransaction<TChain extends Chain>(client: WalletClient, { chain, request }: SendTransactionArgs<TChain>): Promise<SendTransactionResponse>;
510
+ type SendTransactionResponse = Hash;
511
+ declare function sendTransaction<TChain extends Chain>(client: WalletClient, { chain, from, accessList, data, gas, gasPrice, maxFeePerGas, maxPriorityFeePerGas, nonce, to, value, ...rest }: SendTransactionArgs<TChain>): Promise<SendTransactionResponse>;
514
512
  declare class InvalidGasArgumentsError extends BaseError {
515
513
  name: string;
516
514
  constructor();
@@ -532,4 +530,4 @@ type WatchAssetArgs = WatchAssetParams;
532
530
  type WatchAssetResponse = boolean;
533
531
  declare function watchAsset(client: WalletClient, params: WatchAssetParams): Promise<WatchAssetResponse>;
534
532
 
535
- export { SetNextBlockBaseFeePerGasArgs as $, OnBlockNumber as A, OnBlockNumberResponse as B, CallArgs as C, DropTransactionArgs as D, EstimateGasArgs as E, OnBlockResponse as F, GetBalanceArgs as G, OnTransactions as H, ImpersonateAccountArgs as I, OnTransactionsResponse as J, RequestPermissionsResponse as K, RevertArgs as L, MineArgs as M, SendTransactionResponse as N, OnBlock as O, SendUnsignedTransactionArgs as P, SendUnsignedTransactionResponse as Q, ResetArgs as R, SendTransactionArgs as S, SetBalanceArgs as T, SetBlockGasLimitArgs as U, SetCodeArgs as V, SetCoinbaseArgs as W, SetIntervalMiningArgs as X, SetMinGasPriceArgs as Y, SetBlockTimestampIntervalArgs as Z, SetNextBlockTimestampArgs as _, CallResponse as a, switchChain as a$, SetNonceArgs as a0, SetStorageAtArgs as a1, SignMessageArgs as a2, SignMessageResponse as a3, StopImpersonatingAccountArgs as a4, SwitchChainArgs as a5, UninstallFilterArgs as a6, UninstallFilterResponse as a7, WaitForTransactionReceiptArgs as a8, WaitForTransactionReceiptResponse as a9, impersonateAccount as aA, increaseTime as aB, inspectTxpool as aC, mine as aD, removeBlockTimestampInterval as aE, reset as aF, requestAccounts as aG, requestPermissions as aH, revert as aI, sendTransaction as aJ, sendUnsignedTransaction as aK, setAutomine as aL, setBalance as aM, setBlockGasLimit as aN, setBlockTimestampInterval as aO, setCode as aP, setCoinbase as aQ, setIntervalMining as aR, setLoggingEnabled as aS, setMinGasPrice as aT, setNextBlockBaseFeePerGas as aU, setNextBlockTimestamp as aV, setNonce as aW, setStorageAt as aX, signMessage as aY, snapshot as aZ, stopImpersonatingAccount as a_, WatchAssetArgs as aa, WatchAssetResponse as ab, WatchBlockNumberArgs as ac, WatchBlocksArgs as ad, WatchPendingTransactionsArgs as ae, addChain as af, call as ag, createBlockFilter as ah, createPendingTransactionFilter as ai, estimateGas as aj, dropTransaction as ak, getAutomine as al, getBalance as am, getBlock as an, getBlockNumber as ao, getBlockTransactionCount as ap, getChainId as aq, getFeeHistory as ar, getGasPrice as as, getPermissions as at, getTransaction as au, getTransactionConfirmations as av, getTransactionCount as aw, getTransactionReceipt as ax, getTxpoolContent as ay, getTxpoolStatus as az, CreateBlockFilterResponse as b, uninstallFilter as b0, waitForTransactionReceipt as b1, watchAsset as b2, watchBlockNumber as b3, watchBlocks as b4, watchPendingTransactions as b5, getBlockNumberCache as b6, getFilterChanges as b7, ReplacementReason as b8, ReplacementResponse as b9, WaitForTransactionReceiptTimeoutError as ba, FormattedTransactionRequest as bb, InvalidGasArgumentsError as bc, CreatePendingTransactionFilterResponse as c, EstimateGasResponse as d, GetBalanceResponse as e, GetBlockArgs as f, GetBlockNumberArgs as g, GetBlockNumberResponse as h, GetBlockResponse as i, GetBlockTransactionCountArgs as j, GetBlockTransactionCountResponse as k, GetFeeHistoryArgs as l, GetFeeHistoryResponse as m, GetFilterChangesArgs as n, GetFilterChangesResponse as o, GetGasPriceResponse as p, GetPermissionsResponse as q, GetTransactionArgs as r, GetTransactionConfirmationsArgs as s, GetTransactionConfirmationsResponse as t, GetTransactionCountArgs as u, GetTransactionCountResponse as v, GetTransactionResponse as w, GetTransactionReceiptArgs as x, GetTransactionReceiptResponse as y, IncreaseTimeArgs as z };
533
+ export { SetBlockTimestampIntervalArgs as $, GetTransactionReceiptResponse as A, IncreaseTimeArgs as B, CallArgs as C, DropTransactionArgs as D, EstimateGasArgs as E, OnBlockNumber as F, GetBalanceArgs as G, OnBlockNumberResponse as H, ImpersonateAccountArgs as I, OnBlockResponse as J, OnTransactions as K, OnTransactionsResponse as L, MineArgs as M, RequestPermissionsResponse as N, OnBlock as O, RevertArgs as P, SendTransactionResponse as Q, ResetArgs as R, SendTransactionArgs as S, SendUnsignedTransactionArgs as T, SendUnsignedTransactionResponse as U, SetBalanceArgs as V, SetBlockGasLimitArgs as W, SetCodeArgs as X, SetCoinbaseArgs as Y, SetIntervalMiningArgs as Z, SetMinGasPriceArgs as _, CallResponse as a, setNonce as a$, SetNextBlockTimestampArgs as a0, SetNextBlockBaseFeePerGasArgs as a1, SetNonceArgs as a2, SetStorageAtArgs as a3, SignMessageArgs as a4, SignMessageResponse as a5, StopImpersonatingAccountArgs as a6, SwitchChainArgs as a7, UninstallFilterArgs as a8, UninstallFilterResponse as a9, getTransactionConfirmations as aA, getTransactionCount as aB, getTransactionReceipt as aC, getTxpoolContent as aD, getTxpoolStatus as aE, impersonateAccount as aF, increaseTime as aG, inspectTxpool as aH, mine as aI, removeBlockTimestampInterval as aJ, reset as aK, requestAccounts as aL, requestPermissions as aM, revert as aN, sendTransaction as aO, sendUnsignedTransaction as aP, setAutomine as aQ, setBalance as aR, setBlockGasLimit as aS, setBlockTimestampInterval as aT, setCode as aU, setCoinbase as aV, setIntervalMining as aW, setLoggingEnabled as aX, setMinGasPrice as aY, setNextBlockBaseFeePerGas as aZ, setNextBlockTimestamp as a_, WaitForTransactionReceiptArgs as aa, WaitForTransactionReceiptResponse as ab, WatchAssetArgs as ac, WatchAssetResponse as ad, WatchBlockNumberArgs as ae, WatchBlocksArgs as af, WatchPendingTransactionsArgs as ag, addChain as ah, call as ai, createBlockFilter as aj, createPendingTransactionFilter as ak, estimateGas as al, dropTransaction as am, getAccounts as an, getAutomine as ao, getBalance as ap, getBlock as aq, getBlockNumber as ar, getBlockTransactionCount as as, getChainId as at, getFeeHistory as au, getFilterChanges as av, getFilterLogs as aw, getGasPrice as ax, getPermissions as ay, getTransaction as az, CreateBlockFilterResponse as b, setStorageAt as b0, signMessage as b1, snapshot as b2, stopImpersonatingAccount as b3, switchChain as b4, uninstallFilter as b5, waitForTransactionReceipt as b6, watchAsset as b7, watchBlockNumber as b8, watchBlocks as b9, watchPendingTransactions as ba, getBlockNumberCache as bb, ReplacementReason as bc, ReplacementResponse as bd, WaitForTransactionReceiptTimeoutError as be, FormattedTransactionRequest as bf, InvalidGasArgumentsError as bg, CreatePendingTransactionFilterResponse as c, EstimateGasResponse as d, GetBalanceResponse as e, GetBlockArgs as f, GetBlockNumberArgs as g, GetBlockNumberResponse as h, GetBlockResponse as i, GetBlockTransactionCountArgs as j, GetBlockTransactionCountResponse as k, GetFeeHistoryArgs as l, GetFeeHistoryResponse as m, GetFilterChangesArgs as n, GetFilterChangesResponse as o, GetFilterLogsArgs as p, GetFilterLogsResponse as q, GetGasPriceResponse as r, GetPermissionsResponse as s, GetTransactionArgs as t, GetTransactionConfirmationsArgs as u, GetTransactionConfirmationsResponse as v, GetTransactionCountArgs as w, GetTransactionCountResponse as x, GetTransactionResponse as y, GetTransactionReceiptArgs as z };
@@ -1,5 +1,5 @@
1
1
  import { B as BaseError } from './BaseError-7688f84e.js';
2
- import { e as TransportConfig, d as Transport, B as BaseRpcRequests } from './createWalletClient-c40fef16.js';
2
+ import { e as TransportConfig, d as Transport, B as BaseRpcRequests } from './createWalletClient-915223f3.js';
3
3
  import { k as Hash } from './rpc-655c0ba4.js';
4
4
  import { a as RpcResponse } from './rpc-3c0e3985.js';
5
5
 
@@ -10,27 +10,36 @@ declare class UrlRequiredError extends BaseError {
10
10
  type EthereumProvider = {
11
11
  request: BaseRpcRequests['request'];
12
12
  };
13
- type EthereumProviderTransportConfig<TProvider> = {
13
+ type CustomTransportConfig = {
14
14
  /** The key of the transport. */
15
15
  key?: TransportConfig['key'];
16
16
  /** The name of the transport. */
17
17
  name?: TransportConfig['name'];
18
- /** An EIP-1193 or equivalent provider with a "request" function. */
19
- provider: TProvider;
20
18
  };
21
- type EthereumProviderTransport = Transport<'ethereumProvider', EthereumProvider['request']>;
19
+ type CustomTransport = Transport<'custom', EthereumProvider['request']>;
22
20
  /**
23
- * @description Creates a transport based on an EIP-1193 provider (eg. `window.ethereum`).
21
+ * @description Creates a custom transport given an EIP-1193 compliant `request` attribute.
24
22
  */
25
- declare function ethereumProvider<TProvider extends EthereumProvider>({ key, name, provider, }: EthereumProviderTransportConfig<TProvider>): EthereumProviderTransport;
23
+ declare function custom<TProvider extends EthereumProvider>(
24
+ /** An Ethereum provider with an EIP-1193 "request" attribute. */
25
+ provider: TProvider, { key, name }?: CustomTransportConfig): CustomTransport;
26
+
27
+ type FallbackTransportConfig = {
28
+ /** The key of the Fallback transport. */
29
+ key?: TransportConfig['key'];
30
+ /** The name of the Fallback transport. */
31
+ name?: TransportConfig['name'];
32
+ };
33
+ type FallbackTransport = Transport<'fallback', {
34
+ transports: Transport[];
35
+ }>;
36
+ declare function fallback(transports: Transport[], { key, name }?: FallbackTransportConfig): FallbackTransport;
26
37
 
27
38
  type HttpTransportConfig = {
28
39
  /** The key of the HTTP transport. */
29
40
  key?: TransportConfig['key'];
30
41
  /** The name of the HTTP transport. */
31
42
  name?: TransportConfig['name'];
32
- /** URL of the JSON-RPC API. Defaults to the chain's public RPC URL. */
33
- url?: string;
34
43
  };
35
44
  type HttpTransport = Transport<'http', {
36
45
  url?: string;
@@ -38,7 +47,9 @@ type HttpTransport = Transport<'http', {
38
47
  /**
39
48
  * @description Creates a HTTP transport that connects to a JSON-RPC API.
40
49
  */
41
- declare function http({ key, name, url, }?: HttpTransportConfig): HttpTransport;
50
+ declare function http(
51
+ /** URL of the JSON-RPC API. Defaults to the chain's public RPC URL. */
52
+ url?: string, { key, name }?: HttpTransportConfig): HttpTransport;
42
53
 
43
54
  type WebSocketTransportSubscribeArgs = {
44
55
  onData: (data: RpcResponse) => void;
@@ -62,8 +73,6 @@ type WebSocketTransportConfig = {
62
73
  key?: TransportConfig['key'];
63
74
  /** The name of the WebSocket transport. */
64
75
  name?: TransportConfig['name'];
65
- /** URL of the JSON-RPC API. Defaults to the chain's public RPC URL. */
66
- url?: string;
67
76
  };
68
77
  type WebSocketTransport = Transport<'webSocket', {
69
78
  getSocket(): Promise<WebSocket>;
@@ -72,6 +81,8 @@ type WebSocketTransport = Transport<'webSocket', {
72
81
  /**
73
82
  * @description Creates a WebSocket transport that connects to a JSON-RPC API.
74
83
  */
75
- declare function webSocket({ key, name, url, }?: WebSocketTransportConfig): WebSocketTransport;
84
+ declare function webSocket(
85
+ /** URL of the JSON-RPC API. Defaults to the chain's public RPC URL. */
86
+ url?: string, { key, name, }?: WebSocketTransportConfig): WebSocketTransport;
76
87
 
77
- export { EthereumProviderTransport as E, HttpTransport as H, UrlRequiredError as U, WebSocketTransport as W, EthereumProviderTransportConfig as a, HttpTransportConfig as b, WebSocketTransportConfig as c, ethereumProvider as e, http as h, webSocket as w };
88
+ export { CustomTransport as C, FallbackTransport as F, HttpTransport as H, UrlRequiredError as U, WebSocketTransport as W, CustomTransportConfig as a, FallbackTransportConfig as b, HttpTransportConfig as c, WebSocketTransportConfig as d, custom as e, fallback as f, http as h, webSocket as w };
package/package.json CHANGED
@@ -1,12 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript (& JavaScript) Interface for Ethereum",
4
- "version": "0.0.1-alpha.0",
5
- "dependencies": {
6
- "@noble/hashes": "^1.1.2",
7
- "@wagmi/chains": "^0.1.0",
8
- "abitype": "^0.2.5"
9
- },
4
+ "version": "0.0.1-alpha.2",
10
5
  "files": [
11
6
  "/actions",
12
7
  "/chains",
@@ -47,10 +42,45 @@
47
42
  "main": "dist/index.js",
48
43
  "types": "dist/index.d.ts",
49
44
  "sideEffects": false,
50
- "license": "WAGMIT",
45
+ "dependencies": {
46
+ "@noble/hashes": "^1.1.2",
47
+ "@wagmi/chains": "^0.1.0",
48
+ "abitype": "^0.2.5"
49
+ },
50
+ "devDependencies": {
51
+ "@actions/core": "^1.10.0",
52
+ "@actions/github": "^5.1.1",
53
+ "@changesets/changelog-github": "^0.4.5",
54
+ "@changesets/cli": "^2.23.2",
55
+ "@testing-library/jest-dom": "^5.16.5",
56
+ "@types/dedent": "^0.7.0",
57
+ "@types/fs-extra": "^9.0.13",
58
+ "@types/node": "^17.0.45",
59
+ "@vitest/coverage-c8": "^0.24.3",
60
+ "@vitest/ui": "^0.19.1",
61
+ "bundlewatch": "^0.3.3",
62
+ "dedent": "^0.7.0",
63
+ "esbuild": "^0.16.12",
64
+ "esbuild-register": "^3.4.2",
65
+ "essential-eth": "^0.6.2",
66
+ "ethers": "^5.7.2",
67
+ "execa": "^6.1.0",
68
+ "fs-extra": "^10.1.0",
69
+ "jsdom": "^20.0.0",
70
+ "rome": "^11.0.0",
71
+ "simple-git-hooks": "^2.8.1",
72
+ "tsup": "^6.5.0",
73
+ "typescript": "^4.9.3",
74
+ "vite": "^3.0.4",
75
+ "vitest": "^0.25.2",
76
+ "web3": "^1.8.1"
77
+ },
78
+ "license": "MIT",
51
79
  "repository": "wagmi-dev/viem",
52
- "author": "moxey.eth",
53
- "ethereum": "moxey.eth",
80
+ "authors": [
81
+ "awkweb.eth",
82
+ "jxom.eth"
83
+ ],
54
84
  "keywords": [
55
85
  "eth",
56
86
  "ethereum",
@@ -58,8 +88,29 @@
58
88
  "wallet",
59
89
  "web3"
60
90
  ],
91
+ "simple-git-hooks": {
92
+ "pre-commit": "pnpm format & pnpm lint:fix"
93
+ },
61
94
  "scripts": {
95
+ "anvil": "source .env && anvil --fork-url $ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
96
+ "bench": "vitest bench --no-threads",
97
+ "bench:ci": "CI=true vitest bench --no-threads",
62
98
  "build": "tsup",
63
- "dev": "DEV=true tsup"
99
+ "changeset": "changeset",
100
+ "changeset:release": "pnpm build && changeset publish",
101
+ "changeset:version": "changeset version && pnpm install --lockfile-only",
102
+ "dev": "DEV=true tsup",
103
+ "dev:docs": "pnpm -r --filter site dev",
104
+ "format": "rome format src/ test/ --write",
105
+ "lint": "rome check .",
106
+ "lint:fix": "pnpm lint --apply-suggested",
107
+ "playground": "pnpm --filter playground-dev dev",
108
+ "playground:benchmark": "pnpm --filter playground-benchmark dev",
109
+ "postinstall": "pnpm dev",
110
+ "preinstall": "npx only-allow pnpm",
111
+ "test": "vitest dev --coverage --no-threads",
112
+ "test:ci": "CI=true vitest --coverage --no-threads",
113
+ "test:ui": "vitest dev --ui --no-threads",
114
+ "typecheck": "tsc --noEmit"
64
115
  }
65
116
  }