viem 0.0.1-alpha.6 → 0.0.1-alpha.8

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.
@@ -58,9 +58,9 @@ import {
58
58
  watchBlockNumber,
59
59
  watchBlocks,
60
60
  watchPendingTransactions
61
- } from "../chunk-WOXHZO4H.js";
62
- import "../chunk-JND4MCSB.js";
63
- import "../chunk-LZSCKQVJ.js";
61
+ } from "../chunk-N6PIT2C5.js";
62
+ import "../chunk-4Z43OTO6.js";
63
+ import "../chunk-ALVD6MNU.js";
64
64
  export {
65
65
  addChain,
66
66
  call,
package/dist/chains.d.ts CHANGED
@@ -24,7 +24,7 @@ declare const defineBlock: <TFormat extends Formatter<Partial<RpcBlock>, Partial
24
24
  }) => Block<bigint, Transaction<bigint, number>> & ReturnType<TFormat> & { [K in TExclude[number]]: never; };
25
25
  declare const defineTransaction: <TFormat extends Formatter<Partial<RpcTransaction>, Partial<Transaction<bigint, number>> & {
26
26
  [key: string]: unknown;
27
- }>, TExclude extends ("gas" | "type" | "blockHash" | "blockNumber" | "hash" | "value" | "from" | "input" | "nonce" | "r" | "s" | "to" | "transactionIndex" | "v" | "gasPrice" | "maxFeePerGas" | "maxPriorityFeePerGas" | "accessList")[] = []>({ exclude, format: formatOverride, }: {
27
+ }>, TExclude extends ("type" | "gas" | "blockHash" | "blockNumber" | "hash" | "value" | "from" | "input" | "nonce" | "r" | "s" | "to" | "transactionIndex" | "v" | "gasPrice" | "maxFeePerGas" | "maxPriorityFeePerGas" | "accessList")[] = []>({ exclude, format: formatOverride, }: {
28
28
  exclude?: TExclude | undefined;
29
29
  format?: TFormat | undefined;
30
30
  }) => (data: Partial<RpcTransaction> & {
package/dist/chains.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  formatTransaction,
4
4
  formatTransactionReceipt,
5
5
  formatTransactionRequest
6
- } from "./chunk-JND4MCSB.js";
7
- import "./chunk-LZSCKQVJ.js";
6
+ } from "./chunk-4Z43OTO6.js";
7
+ import "./chunk-ALVD6MNU.js";
8
8
 
9
9
  // src/chains.ts
10
10
  import {
@@ -4,11 +4,16 @@ import {
4
4
  AbiDecodingDataSizeInvalidError,
5
5
  AbiEncodingArrayLengthMismatchError,
6
6
  AbiEncodingLengthMismatchError,
7
+ AbiErrorInputsNotFoundError,
8
+ AbiErrorNotFoundError,
9
+ AbiErrorSignatureNotFoundError,
10
+ AbiEventNotFoundError,
7
11
  AbiFunctionNotFoundError,
8
12
  AbiFunctionOutputsNotFoundError,
9
13
  AbiFunctionSignatureNotFoundError,
10
14
  DataLengthTooLongError,
11
15
  DataLengthTooShortError,
16
+ FilterTypeNotSupportedError,
12
17
  InvalidAbiDecodingTypeError,
13
18
  InvalidAbiEncodingTypeError,
14
19
  InvalidAddressError,
@@ -19,7 +24,7 @@ import {
19
24
  InvalidHexValueError,
20
25
  OffsetOutOfBoundsError,
21
26
  SizeExceedsPaddingSizeError
22
- } from "./chunk-LZSCKQVJ.js";
27
+ } from "./chunk-ALVD6MNU.js";
23
28
 
24
29
  // src/utils/data/concat.ts
25
30
  function concat(values) {
@@ -555,7 +560,7 @@ function encodeAbi({
555
560
  const preparedParams = prepareParams({ params, values });
556
561
  const data = encodeParams(preparedParams);
557
562
  if (data.length === 0)
558
- return void 0;
563
+ return "0x";
559
564
  return data;
560
565
  }
561
566
  function prepareParams({
@@ -932,6 +937,20 @@ function getParam(param) {
932
937
  return param.type;
933
938
  }
934
939
 
940
+ // src/utils/abi/decodeErrorResult.ts
941
+ function decodeErrorResult({ abi, data }) {
942
+ const signature = slice(data, 0, 4);
943
+ const description = abi.find(
944
+ (x) => signature === getFunctionSignature(getDefinition(x))
945
+ );
946
+ if (!description)
947
+ throw new AbiErrorSignatureNotFoundError(signature);
948
+ return {
949
+ errorName: description.name,
950
+ args: "inputs" in description && description.inputs && description.inputs.length > 0 ? decodeAbi({ data: slice(data, 4), params: description.inputs }) : void 0
951
+ };
952
+ }
953
+
935
954
  // src/utils/abi/decodeFunctionData.ts
936
955
  function decodeFunctionData({ abi, data }) {
937
956
  const signature = slice(data, 0, 4);
@@ -983,6 +1002,59 @@ function encodeDeployData({
983
1002
  return concatHex([bytecode, data]);
984
1003
  }
985
1004
 
1005
+ // src/utils/abi/encodeErrorResult.ts
1006
+ function encodeErrorResult({
1007
+ abi,
1008
+ errorName,
1009
+ args
1010
+ }) {
1011
+ const description = abi.find((x) => "name" in x && x.name === errorName);
1012
+ if (!description)
1013
+ throw new AbiErrorNotFoundError(errorName);
1014
+ const definition = getDefinition(description);
1015
+ const signature = getFunctionSignature(definition);
1016
+ let data = "0x";
1017
+ if (args && args.length > 0) {
1018
+ if (!("inputs" in description && description.inputs))
1019
+ throw new AbiErrorInputsNotFoundError(errorName);
1020
+ data = encodeAbi({ params: description.inputs, values: args });
1021
+ }
1022
+ return concatHex([signature, data]);
1023
+ }
1024
+
1025
+ // src/utils/abi/encodeEventTopics.ts
1026
+ function encodeEventTopics({
1027
+ abi,
1028
+ eventName,
1029
+ args
1030
+ }) {
1031
+ const description = abi.find((x) => "name" in x && x.name === eventName);
1032
+ if (!description)
1033
+ throw new AbiEventNotFoundError(eventName);
1034
+ const definition = getDefinition(description);
1035
+ const signature = getEventSignature(definition);
1036
+ let topics = [];
1037
+ if (args && "inputs" in description) {
1038
+ const args_ = Array.isArray(args) ? args : description.inputs?.map((x) => args[x.name]) ?? [];
1039
+ topics = description.inputs?.filter((param) => "indexed" in param && param.indexed).map(
1040
+ (param, i) => Array.isArray(args_[i]) ? args_[i].map(
1041
+ (_, j) => encodeArg({ param, value: args_[i][j] })
1042
+ ) : args_[i] ? encodeArg({ param, value: args_[i] }) : null
1043
+ ) ?? [];
1044
+ }
1045
+ return [signature, ...topics];
1046
+ }
1047
+ function encodeArg({
1048
+ param,
1049
+ value
1050
+ }) {
1051
+ if (param.type === "string" || param.type === "bytes")
1052
+ return keccak256(encodeBytes(value));
1053
+ if (param.type === "tuple" || param.type.match(/^(.*)\[(\d+)?\]$/))
1054
+ throw new FilterTypeNotSupportedError(param.type);
1055
+ return encodeAbi({ params: [param], values: [value] });
1056
+ }
1057
+
986
1058
  // src/utils/abi/encodeFunctionData.ts
987
1059
  function encodeFunctionData({
988
1060
  abi,
@@ -1015,10 +1087,7 @@ function encodeFunctionResult({
1015
1087
  let values = Array.isArray(result) ? result : [result];
1016
1088
  if (description.outputs.length === 0 && !values[0])
1017
1089
  values = [];
1018
- const data = encodeAbi({ params: description.outputs, values });
1019
- if (!data)
1020
- return "0x";
1021
- return data;
1090
+ return encodeAbi({ params: description.outputs, values });
1022
1091
  }
1023
1092
 
1024
1093
  // src/constants.ts
@@ -1252,9 +1321,12 @@ export {
1252
1321
  isAddressEqual,
1253
1322
  encodeAbi,
1254
1323
  decodeAbi,
1324
+ decodeErrorResult,
1255
1325
  decodeFunctionData,
1256
1326
  decodeFunctionResult,
1257
1327
  encodeDeployData,
1328
+ encodeErrorResult,
1329
+ encodeEventTopics,
1258
1330
  encodeFunctionData,
1259
1331
  encodeFunctionResult,
1260
1332
  etherUnits,
@@ -9,7 +9,7 @@ var __publicField = (obj, key, value) => {
9
9
  var package_default = {
10
10
  name: "viem",
11
11
  description: "TypeScript (& JavaScript) Interface for Ethereum",
12
- version: "0.0.1-alpha.6",
12
+ version: "0.0.1-alpha.8",
13
13
  scripts: {
14
14
  anvil: "source .env && anvil --fork-url $ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
15
15
  bench: "vitest bench --no-threads",
@@ -227,6 +227,64 @@ var AbiEncodingLengthMismatchError = class extends BaseError {
227
227
  __publicField(this, "name", "AbiEncodingLengthMismatchError");
228
228
  }
229
229
  };
230
+ var AbiErrorInputsNotFoundError = class extends BaseError {
231
+ constructor(errorName) {
232
+ super(
233
+ [
234
+ `Arguments (\`args\`) were provided to "${errorName}", but "${errorName}" on the ABI does not contain any parameters (\`inputs\`).`,
235
+ "Cannot encode error result without knowing what the parameter types are.",
236
+ "Make sure you are using the correct ABI and that the inputs exist on it."
237
+ ].join("\n"),
238
+ {
239
+ docsPath: "/docs/contract/encodeErrorResult"
240
+ }
241
+ );
242
+ __publicField(this, "name", "AbiErrorInputsNotFoundError");
243
+ }
244
+ };
245
+ var AbiErrorNotFoundError = class extends BaseError {
246
+ constructor(errorName) {
247
+ super(
248
+ [
249
+ `Error "${errorName}" not found on ABI.`,
250
+ "Make sure you are using the correct ABI and that the error exists on it."
251
+ ].join("\n"),
252
+ {
253
+ docsPath: "/docs/contract/encodeErrorResult"
254
+ }
255
+ );
256
+ __publicField(this, "name", "AbiErrorNotFoundError");
257
+ }
258
+ };
259
+ var AbiErrorSignatureNotFoundError = class extends BaseError {
260
+ constructor(signature) {
261
+ super(
262
+ [
263
+ `Encoded error signature "${signature}" not found on ABI.`,
264
+ "Make sure you are using the correct ABI and that the error exists on it.",
265
+ `You can look up the signature "${signature}" here: https://sig.eth.samczsun.com/.`
266
+ ].join("\n"),
267
+ {
268
+ docsPath: "/docs/contract/decodeErrorResult"
269
+ }
270
+ );
271
+ __publicField(this, "name", "AbiErrorSignatureNotFoundError");
272
+ }
273
+ };
274
+ var AbiEventNotFoundError = class extends BaseError {
275
+ constructor(eventName) {
276
+ super(
277
+ [
278
+ `Event "${eventName}" not found on ABI.`,
279
+ "Make sure you are using the correct ABI and that the event exists on it."
280
+ ].join("\n"),
281
+ {
282
+ docsPath: "/docs/contract/encodeEventTopics"
283
+ }
284
+ );
285
+ __publicField(this, "name", "AbiEventNotFoundError");
286
+ }
287
+ };
230
288
  var AbiFunctionNotFoundError = class extends BaseError {
231
289
  constructor(functionName) {
232
290
  super(
@@ -404,6 +462,14 @@ var OffsetOutOfBoundsError = class extends BaseError {
404
462
  }
405
463
  };
406
464
 
465
+ // src/errors/log.ts
466
+ var FilterTypeNotSupportedError = class extends BaseError {
467
+ constructor(type) {
468
+ super(`Filter type "${type}" is not supported.`);
469
+ __publicField(this, "name", "FilterTypeNotSupportedError");
470
+ }
471
+ };
472
+
407
473
  // src/errors/request.ts
408
474
  var RequestError = class extends BaseError {
409
475
  constructor(err, { docsPath, humanMessage }) {
@@ -993,6 +1059,10 @@ export {
993
1059
  AbiDecodingDataSizeInvalidError,
994
1060
  AbiEncodingArrayLengthMismatchError,
995
1061
  AbiEncodingLengthMismatchError,
1062
+ AbiErrorInputsNotFoundError,
1063
+ AbiErrorNotFoundError,
1064
+ AbiErrorSignatureNotFoundError,
1065
+ AbiEventNotFoundError,
996
1066
  AbiFunctionNotFoundError,
997
1067
  AbiFunctionOutputsNotFoundError,
998
1068
  AbiFunctionSignatureNotFoundError,
@@ -1009,6 +1079,7 @@ export {
1009
1079
  InvalidHexBooleanError,
1010
1080
  InvalidHexValueError,
1011
1081
  OffsetOutOfBoundsError,
1082
+ FilterTypeNotSupportedError,
1012
1083
  RequestError,
1013
1084
  RpcRequestError,
1014
1085
  ParseRpcError,
@@ -3,7 +3,7 @@ import {
3
3
  buildRequest,
4
4
  getSocket,
5
5
  rpc
6
- } from "./chunk-LZSCKQVJ.js";
6
+ } from "./chunk-ALVD6MNU.js";
7
7
 
8
8
  // src/clients/transports/createTransport.ts
9
9
  function createTransport(config, value) {
@@ -11,7 +11,7 @@ import {
11
11
  getAddress,
12
12
  hexToNumber,
13
13
  numberToHex
14
- } from "./chunk-JND4MCSB.js";
14
+ } from "./chunk-4Z43OTO6.js";
15
15
  import {
16
16
  BaseError,
17
17
  BlockNotFoundError,
@@ -22,7 +22,7 @@ import {
22
22
  getCache,
23
23
  wait,
24
24
  withCache
25
- } from "./chunk-LZSCKQVJ.js";
25
+ } from "./chunk-ALVD6MNU.js";
26
26
 
27
27
  // src/actions/public/call.ts
28
28
  async function call(client, {
@@ -8,8 +8,8 @@ import {
8
8
  fallback,
9
9
  http,
10
10
  webSocket
11
- } from "../chunk-2ISXYVSQ.js";
12
- import "../chunk-LZSCKQVJ.js";
11
+ } from "../chunk-BIQ5KSX5.js";
12
+ import "../chunk-ALVD6MNU.js";
13
13
  export {
14
14
  createClient,
15
15
  createPublicClient,
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { C as Client, a as ClientConfig, P as PublicClient, b as PublicClientCon
3
3
  export { C as CustomTransport, a as CustomTransportConfig, F as FallbackTransport, b as FallbackTransportConfig, H as HttpTransport, c as HttpTransportConfig, W as WebSocketTransport, d as WebSocketTransportConfig, e as custom, f as fallback, h as http, w as webSocket } from './webSocket-f4abf66c.js';
4
4
  import { H as Hex, A as Address, a as Hash, B as ByteArray, b as BlockTag } from './rpc-b77c5aee.js';
5
5
  export { c as AccessList, A as Address, d as Block, f as BlockIdentifier, h as BlockNumber, b as BlockTag, B as ByteArray, F as FeeHistory, i as FeeValues, j as FeeValuesEIP1559, k as FeeValuesLegacy, a as Hash, H as Hex, L as Log, R as RpcBlock, l as RpcBlockIdentifier, m as RpcBlockNumber, n as RpcFeeHistory, o as RpcFeeValues, p as RpcLog, q as RpcTransaction, r as RpcTransactionReceipt, s as RpcTransactionRequest, u as RpcUncle, D as Transaction, E as TransactionBase, G as TransactionEIP1559, I as TransactionEIP2930, J as TransactionLegacy, T as TransactionReceipt, v as TransactionRequest, x as TransactionRequestBase, y as TransactionRequestEIP1559, z as TransactionRequestEIP2930, C as TransactionRequestLegacy, U as Uncle, e as etherUnits, g as gweiUnits, t as transactionType, w as weiUnits } from './rpc-b77c5aee.js';
6
- export { E as EncodeRlpResponse, G as GetContractAddressOptions, b as GetCreate2AddressOptions, a as GetCreateAddressOptions, e as boolToBytes, f as boolToHex, g as bytesToBigint, h as bytesToBool, c as bytesToHex, i as bytesToNumber, d as bytesToString, j as decodeAbi, k as decodeBytes, l as decodeFunctionData, m as decodeFunctionResult, n as decodeHex, o as decodeRlp, p as encodeAbi, q as encodeBytes, r as encodeDeployData, s as encodeFunctionData, t as encodeFunctionResult, u as encodeHex, v as encodeRlp, C as formatEther, V as formatGwei, W as formatUnit, w as getAddress, x as getContractAddress, z as getCreate2Address, y as getCreateAddress, A as getEventSignature, B as getFunctionSignature, J as hexToBigInt, K as hexToBool, L as hexToBytes, X as hexToNumber, M as hexToString, D as isAddress, F as isAddressEqual, H as isBytes, I as isHex, N as keccak256, O as numberToBytes, Y as numberToHex, P as pad, Q as padBytes, R as padHex, S as parseEther, T as parseGwei, U as parseUnit, Z as size, _ as slice, $ as sliceBytes, a0 as sliceHex, a1 as stringToBytes, a2 as stringToHex, a3 as trim } from './parseGwei-0c9cad8a.js';
6
+ export { E as EncodeRlpResponse, G as GetContractAddressOptions, b as GetCreate2AddressOptions, a as GetCreateAddressOptions, e as boolToBytes, f as boolToHex, g as bytesToBigint, h as bytesToBool, c as bytesToHex, i as bytesToNumber, d as bytesToString, j as decodeAbi, k as decodeBytes, l as decodeErrorResult, m as decodeFunctionData, n as decodeFunctionResult, o as decodeHex, p as decodeRlp, q as encodeAbi, r as encodeBytes, s as encodeDeployData, t as encodeErrorResult, u as encodeEventTopics, v as encodeFunctionData, w as encodeFunctionResult, x as encodeHex, y as encodeRlp, H as formatEther, Y as formatGwei, Z as formatUnit, z as getAddress, A as getContractAddress, C as getCreate2Address, B as getCreateAddress, D as getEventSignature, F as getFunctionSignature, M as hexToBigInt, N as hexToBool, O as hexToBytes, _ as hexToNumber, P as hexToString, I as isAddress, J as isAddressEqual, K as isBytes, L as isHex, Q as keccak256, R as numberToBytes, $ as numberToHex, S as pad, T as padBytes, U as padHex, V as parseEther, W as parseGwei, X as parseUnit, a0 as size, a1 as slice, a2 as sliceBytes, a3 as sliceHex, a4 as stringToBytes, a5 as stringToHex, a6 as trim } from './parseGwei-14f716fc.js';
7
7
  export { F as FormattedBlock, a as FormattedTransaction, b as FormattedTransactionRequest, f as formatBlock, c as formatTransaction, d as formatTransactionRequest } from './transactionRequest-3e463099.js';
8
8
  import './chains.js';
9
9
  import '@wagmi/chains';
@@ -55,6 +55,22 @@ declare class AbiEncodingLengthMismatchError extends BaseError {
55
55
  givenLength: number;
56
56
  });
57
57
  }
58
+ declare class AbiErrorInputsNotFoundError extends BaseError {
59
+ name: string;
60
+ constructor(errorName: string);
61
+ }
62
+ declare class AbiErrorNotFoundError extends BaseError {
63
+ name: string;
64
+ constructor(errorName: string);
65
+ }
66
+ declare class AbiErrorSignatureNotFoundError extends BaseError {
67
+ name: string;
68
+ constructor(signature: Hex);
69
+ }
70
+ declare class AbiEventNotFoundError extends BaseError {
71
+ name: string;
72
+ constructor(eventName: string);
73
+ }
58
74
  declare class AbiFunctionNotFoundError extends BaseError {
59
75
  name: string;
60
76
  constructor(functionName: string);
@@ -142,6 +158,11 @@ declare class OffsetOutOfBoundsError extends BaseError {
142
158
  });
143
159
  }
144
160
 
161
+ declare class FilterTypeNotSupportedError extends BaseError {
162
+ name: string;
163
+ constructor(type: string);
164
+ }
165
+
145
166
  declare class HttpRequestError extends BaseError {
146
167
  name: string;
147
168
  status: number;
@@ -297,4 +318,4 @@ declare class UrlRequiredError extends BaseError {
297
318
  constructor();
298
319
  }
299
320
 
300
- export { AbiConstructorNotFoundError, AbiConstructorParamsNotFoundError, AbiDecodingDataSizeInvalidError, AbiEncodingArrayLengthMismatchError, AbiEncodingLengthMismatchError, AbiFunctionNotFoundError, AbiFunctionOutputsNotFoundError, AbiFunctionSignatureNotFoundError, BaseError, BlockNotFoundError, DataLengthTooLongError, DataLengthTooShortError, HttpRequestError, InternalRpcError, InvalidAbiDecodingTypeError, InvalidAbiEncodingTypeError, InvalidAddressError, InvalidArrayError, InvalidBytesBooleanError, InvalidDefinitionTypeError, InvalidGasArgumentsError, InvalidHexBooleanError, InvalidHexValueError, InvalidInputRpcError, InvalidParamsRpcError, InvalidRequestRpcError, JsonRpcVersionUnsupportedError, LimitExceededRpcError, MethodNotFoundRpcError, MethodNotSupportedRpcError, OffsetOutOfBoundsError, ParseRpcError, RequestError, ResourceNotFoundRpcError, ResourceUnavailableRpcError, RpcError, RpcRequestError, SizeExceedsPaddingSizeError, TimeoutError, TransactionNotFoundError, TransactionReceiptNotFoundError, TransactionRejectedRpcError, UnknownRpcError, UrlRequiredError, WaitForTransactionReceiptTimeoutError, WebSocketRequestError };
321
+ export { AbiConstructorNotFoundError, AbiConstructorParamsNotFoundError, AbiDecodingDataSizeInvalidError, AbiEncodingArrayLengthMismatchError, AbiEncodingLengthMismatchError, AbiErrorInputsNotFoundError, AbiErrorNotFoundError, AbiErrorSignatureNotFoundError, AbiEventNotFoundError, AbiFunctionNotFoundError, AbiFunctionOutputsNotFoundError, AbiFunctionSignatureNotFoundError, BaseError, BlockNotFoundError, DataLengthTooLongError, DataLengthTooShortError, FilterTypeNotSupportedError, HttpRequestError, InternalRpcError, InvalidAbiDecodingTypeError, InvalidAbiEncodingTypeError, InvalidAddressError, InvalidArrayError, InvalidBytesBooleanError, InvalidDefinitionTypeError, InvalidGasArgumentsError, InvalidHexBooleanError, InvalidHexValueError, InvalidInputRpcError, InvalidParamsRpcError, InvalidRequestRpcError, JsonRpcVersionUnsupportedError, LimitExceededRpcError, MethodNotFoundRpcError, MethodNotSupportedRpcError, OffsetOutOfBoundsError, ParseRpcError, RequestError, ResourceNotFoundRpcError, ResourceUnavailableRpcError, RpcError, RpcRequestError, SizeExceedsPaddingSizeError, TimeoutError, TransactionNotFoundError, TransactionReceiptNotFoundError, TransactionRejectedRpcError, UnknownRpcError, UrlRequiredError, WaitForTransactionReceiptTimeoutError, WebSocketRequestError };
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ import {
57
57
  watchBlockNumber,
58
58
  watchBlocks,
59
59
  watchPendingTransactions
60
- } from "./chunk-WOXHZO4H.js";
60
+ } from "./chunk-N6PIT2C5.js";
61
61
  import {
62
62
  createClient,
63
63
  createPublicClient,
@@ -68,7 +68,7 @@ import {
68
68
  fallback,
69
69
  http,
70
70
  webSocket
71
- } from "./chunk-2ISXYVSQ.js";
71
+ } from "./chunk-BIQ5KSX5.js";
72
72
  import {
73
73
  boolToBytes,
74
74
  boolToHex,
@@ -79,6 +79,7 @@ import {
79
79
  bytesToString,
80
80
  decodeAbi,
81
81
  decodeBytes,
82
+ decodeErrorResult,
82
83
  decodeFunctionData,
83
84
  decodeFunctionResult,
84
85
  decodeHex,
@@ -86,6 +87,8 @@ import {
86
87
  encodeAbi,
87
88
  encodeBytes,
88
89
  encodeDeployData,
90
+ encodeErrorResult,
91
+ encodeEventTopics,
89
92
  encodeFunctionData,
90
93
  encodeFunctionResult,
91
94
  encodeHex,
@@ -131,13 +134,17 @@ import {
131
134
  transactionType,
132
135
  trim,
133
136
  weiUnits
134
- } from "./chunk-JND4MCSB.js";
137
+ } from "./chunk-4Z43OTO6.js";
135
138
  import {
136
139
  AbiConstructorNotFoundError,
137
140
  AbiConstructorParamsNotFoundError,
138
141
  AbiDecodingDataSizeInvalidError,
139
142
  AbiEncodingArrayLengthMismatchError,
140
143
  AbiEncodingLengthMismatchError,
144
+ AbiErrorInputsNotFoundError,
145
+ AbiErrorNotFoundError,
146
+ AbiErrorSignatureNotFoundError,
147
+ AbiEventNotFoundError,
141
148
  AbiFunctionNotFoundError,
142
149
  AbiFunctionOutputsNotFoundError,
143
150
  AbiFunctionSignatureNotFoundError,
@@ -145,6 +152,7 @@ import {
145
152
  BlockNotFoundError,
146
153
  DataLengthTooLongError,
147
154
  DataLengthTooShortError,
155
+ FilterTypeNotSupportedError,
148
156
  HttpRequestError,
149
157
  InternalRpcError,
150
158
  InvalidAbiDecodingTypeError,
@@ -179,13 +187,17 @@ import {
179
187
  UrlRequiredError,
180
188
  WaitForTransactionReceiptTimeoutError,
181
189
  WebSocketRequestError
182
- } from "./chunk-LZSCKQVJ.js";
190
+ } from "./chunk-ALVD6MNU.js";
183
191
  export {
184
192
  AbiConstructorNotFoundError,
185
193
  AbiConstructorParamsNotFoundError,
186
194
  AbiDecodingDataSizeInvalidError,
187
195
  AbiEncodingArrayLengthMismatchError,
188
196
  AbiEncodingLengthMismatchError,
197
+ AbiErrorInputsNotFoundError,
198
+ AbiErrorNotFoundError,
199
+ AbiErrorSignatureNotFoundError,
200
+ AbiEventNotFoundError,
189
201
  AbiFunctionNotFoundError,
190
202
  AbiFunctionOutputsNotFoundError,
191
203
  AbiFunctionSignatureNotFoundError,
@@ -193,6 +205,7 @@ export {
193
205
  BlockNotFoundError,
194
206
  DataLengthTooLongError,
195
207
  DataLengthTooShortError,
208
+ FilterTypeNotSupportedError,
196
209
  HttpRequestError,
197
210
  InternalRpcError,
198
211
  InvalidAbiDecodingTypeError,
@@ -246,6 +259,7 @@ export {
246
259
  custom,
247
260
  decodeAbi,
248
261
  decodeBytes,
262
+ decodeErrorResult,
249
263
  decodeFunctionData,
250
264
  decodeFunctionResult,
251
265
  decodeHex,
@@ -254,6 +268,8 @@ export {
254
268
  encodeAbi,
255
269
  encodeBytes,
256
270
  encodeDeployData,
271
+ encodeErrorResult,
272
+ encodeEventTopics,
257
273
  encodeFunctionData,
258
274
  encodeFunctionResult,
259
275
  encodeHex,
@@ -1,6 +1,18 @@
1
- import { Abi, AbiFunction, ExtractAbiFunction, AbiParametersToPrimitiveTypes, AbiParameter, ExtractAbiFunctionNames } from 'abitype';
1
+ import { Abi, AbiFunction, ExtractAbiFunction, AbiParametersToPrimitiveTypes, AbiError, ExtractAbiError, AbiEvent, ExtractAbiEvent, AbiParameter, AbiParameterToPrimitiveType, ExtractAbiFunctionNames, ExtractAbiErrorNames, ExtractAbiEventNames } from 'abitype';
2
2
  import { H as Hex, A as Address, B as ByteArray } from './rpc-b77c5aee.js';
3
3
 
4
+ type AbiEventParametersToPrimitiveTypes<TAbiParameters extends readonly AbiParameter[], TBase = TAbiParameters[0] extends {
5
+ name: string;
6
+ } ? {} : []> = TAbiParameters extends readonly [infer Head, ...infer Tail] ? Head extends {
7
+ indexed: true;
8
+ } ? Head extends AbiParameter ? Head extends {
9
+ name: infer Name;
10
+ } ? Name extends string ? {
11
+ [name in Name]?: AbiParameterToPrimitiveType<Head> | AbiParameterToPrimitiveType<Head>[] | null;
12
+ } & (Tail extends readonly [] ? {} : Tail extends readonly AbiParameter[] ? AbiEventParametersToPrimitiveTypes<Tail> : {}) : never : [
13
+ (AbiParameterToPrimitiveType<Head> | AbiParameterToPrimitiveType<Head>[] | null),
14
+ ...(Tail extends readonly [] ? [] : Tail extends readonly AbiParameter[] ? AbiEventParametersToPrimitiveTypes<Tail> : [])
15
+ ] : TBase : TBase : TBase;
4
16
  type ExtractArgsFromAbi<TAbi extends Abi | readonly unknown[], TFunctionName extends string, TAbiFunction extends AbiFunction & {
5
17
  type: 'function';
6
18
  } = TAbi extends Abi ? ExtractAbiFunction<TAbi, TFunctionName> : AbiFunction & {
@@ -35,6 +47,18 @@ type ExtractConstructorArgsFromAbi<TAbi extends Abi | readonly unknown[], TAbiFu
35
47
  } : {
36
48
  /** Arguments to pass contract method */ args: TArgs;
37
49
  };
50
+ type ExtractErrorArgsFromAbi<TAbi extends Abi | readonly unknown[], TErrorName extends string, TAbiError extends AbiError = TAbi extends Abi ? ExtractAbiError<TAbi, TErrorName> : AbiError, TArgs = AbiParametersToPrimitiveTypes<TAbiError['inputs']>, FailedToParseArgs = ([TArgs] extends [never] ? true : false) | (readonly unknown[] extends TArgs ? true : false)> = true extends FailedToParseArgs ? {
51
+ /**
52
+ * Arguments to pass contract method
53
+ *
54
+ * Use a [const assertion](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions) on {@link abi} for type inference.
55
+ */
56
+ args?: readonly unknown[];
57
+ } : TArgs extends readonly [] ? {
58
+ args?: never;
59
+ } : {
60
+ /** Arguments to pass contract method */ args: TArgs;
61
+ };
38
62
  type ExtractResultFromAbi<TAbi extends Abi | readonly unknown[], TFunctionName extends string, TAbiFunction extends AbiFunction & {
39
63
  type: 'function';
40
64
  } = TAbi extends Abi ? ExtractAbiFunction<TAbi, TFunctionName> : AbiFunction & {
@@ -51,12 +75,36 @@ type ExtractResultFromAbi<TAbi extends Abi | readonly unknown[], TFunctionName e
51
75
  } : {
52
76
  /** Arguments to pass contract method */ result: TArgs;
53
77
  };
78
+ type ExtractEventArgsFromAbi<TAbi extends Abi | readonly unknown[], TFunctionName extends string, TAbiEvent extends AbiEvent & {
79
+ type: 'event';
80
+ } = TAbi extends Abi ? ExtractAbiEvent<TAbi, TFunctionName> : AbiEvent & {
81
+ type: 'event';
82
+ }, TArgs = AbiEventParametersToPrimitiveTypes<TAbiEvent['inputs']>, FailedToParseArgs = ([TArgs] extends [never] ? true : false) | (readonly unknown[] extends TArgs ? true : false)> = true extends FailedToParseArgs ? {
83
+ /**
84
+ * Arguments to pass contract method
85
+ *
86
+ * Use a [const assertion](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions) on {@link abi} for type inference.
87
+ */
88
+ args?: readonly unknown[];
89
+ } : TArgs extends readonly [] ? {
90
+ args?: never;
91
+ } : {
92
+ args?: TArgs;
93
+ };
54
94
 
55
95
  declare function decodeAbi<TParams extends readonly AbiParameter[]>({ data, params, }: {
56
96
  data: Hex;
57
97
  params: TParams;
58
98
  }): AbiParametersToPrimitiveTypes<TParams>;
59
99
 
100
+ declare function decodeErrorResult({ abi, data }: {
101
+ abi: Abi;
102
+ data: Hex;
103
+ }): {
104
+ errorName: string;
105
+ args: readonly unknown[] | undefined;
106
+ };
107
+
60
108
  declare function decodeFunctionData({ abi, data }: {
61
109
  abi: Abi;
62
110
  data: Hex;
@@ -77,13 +125,23 @@ declare function decodeFunctionResult<TAbi extends Abi = Abi, TFunctionName exte
77
125
  declare function encodeAbi<TParams extends readonly AbiParameter[]>({ params, values, }: {
78
126
  params: TParams;
79
127
  values: AbiParametersToPrimitiveTypes<TParams>;
80
- }): `0x${string}` | undefined;
128
+ }): `0x${string}`;
81
129
 
82
130
  declare function encodeDeployData<TAbi extends Abi = Abi>({ abi, args, bytecode, }: {
83
131
  abi: TAbi;
84
132
  bytecode: Hex;
85
133
  } & ExtractConstructorArgsFromAbi<TAbi>): `0x${string}`;
86
134
 
135
+ declare function encodeErrorResult<TAbi extends Abi = Abi, TErrorName extends ExtractAbiErrorNames<TAbi> = any>({ abi, errorName, args, }: {
136
+ abi: TAbi;
137
+ errorName: TErrorName;
138
+ } & ExtractErrorArgsFromAbi<TAbi, TErrorName>): `0x${string}`;
139
+
140
+ declare function encodeEventTopics<TAbi extends Abi = Abi, TEventName extends ExtractAbiEventNames<TAbi> = any>({ abi, eventName, args, }: {
141
+ abi: TAbi;
142
+ eventName: TEventName;
143
+ } & ExtractEventArgsFromAbi<TAbi, TEventName>): `0x${string}`[];
144
+
87
145
  declare function encodeFunctionData<TAbi extends Abi = Abi, TFunctionName extends ExtractAbiFunctionNames<TAbi> = any>({ abi, args, functionName, }: {
88
146
  abi: TAbi;
89
147
  functionName: TFunctionName;
@@ -295,4 +353,4 @@ declare function parseEther(ether: `${number}`, unit?: 'wei' | 'gwei'): bigint;
295
353
 
296
354
  declare function parseGwei(ether: `${number}`, unit?: 'wei'): bigint;
297
355
 
298
- export { sliceBytes as $, getEventSignature as A, getFunctionSignature as B, formatEther as C, isAddress as D, EncodeRlpResponse as E, isAddressEqual as F, GetContractAddressOptions as G, isBytes as H, isHex as I, hexToBigInt as J, hexToBool as K, hexToBytes as L, hexToString as M, keccak256 as N, numberToBytes as O, pad as P, padBytes as Q, padHex as R, parseEther as S, parseGwei as T, parseUnit as U, formatGwei as V, formatUnit as W, hexToNumber as X, numberToHex as Y, size as Z, slice as _, GetCreateAddressOptions as a, sliceHex as a0, stringToBytes as a1, stringToHex as a2, trim as a3, GetCreate2AddressOptions as b, bytesToHex as c, bytesToString as d, boolToBytes as e, boolToHex as f, bytesToBigint as g, bytesToBool as h, bytesToNumber as i, decodeAbi as j, decodeBytes as k, decodeFunctionData as l, decodeFunctionResult as m, decodeHex as n, decodeRlp as o, encodeAbi as p, encodeBytes as q, encodeDeployData as r, encodeFunctionData as s, encodeFunctionResult as t, encodeHex as u, encodeRlp as v, getAddress as w, getContractAddress as x, getCreateAddress as y, getCreate2Address as z };
356
+ export { numberToHex as $, getContractAddress as A, getCreateAddress as B, getCreate2Address as C, getEventSignature as D, EncodeRlpResponse as E, getFunctionSignature as F, GetContractAddressOptions as G, formatEther as H, isAddress as I, isAddressEqual as J, isBytes as K, isHex as L, hexToBigInt as M, hexToBool as N, hexToBytes as O, hexToString as P, keccak256 as Q, numberToBytes as R, pad as S, padBytes as T, padHex as U, parseEther as V, parseGwei as W, parseUnit as X, formatGwei as Y, formatUnit as Z, hexToNumber as _, GetCreateAddressOptions as a, size as a0, slice as a1, sliceBytes as a2, sliceHex as a3, stringToBytes as a4, stringToHex as a5, trim as a6, GetCreate2AddressOptions as b, bytesToHex as c, bytesToString as d, boolToBytes as e, boolToHex as f, bytesToBigint as g, bytesToBool as h, bytesToNumber as i, decodeAbi as j, decodeBytes as k, decodeErrorResult as l, decodeFunctionData as m, decodeFunctionResult as n, decodeHex as o, decodeRlp as p, encodeAbi as q, encodeBytes as r, encodeDeployData as s, encodeErrorResult as t, encodeEventTopics as u, encodeFunctionData as v, encodeFunctionResult as w, encodeHex as x, encodeRlp as y, getAddress as z };
@@ -1,4 +1,4 @@
1
- export { E as EncodeRlpResponse, G as GetContractAddressOptions, b as GetCreate2AddressOptions, a as GetCreateAddressOptions, e as boolToBytes, f as boolToHex, g as bytesToBigint, h as bytesToBool, c as bytesToHex, i as bytesToNumber, d as bytesToString, j as decodeAbi, k as decodeBytes, l as decodeFunctionData, m as decodeFunctionResult, n as decodeHex, o as decodeRlp, p as encodeAbi, q as encodeBytes, r as encodeDeployData, s as encodeFunctionData, t as encodeFunctionResult, u as encodeHex, v as encodeRlp, C as formatEther, V as formatGwei, W as formatUnit, w as getAddress, x as getContractAddress, z as getCreate2Address, y as getCreateAddress, A as getEventSignature, B as getFunctionSignature, J as hexToBigInt, K as hexToBool, L as hexToBytes, X as hexToNumber, M as hexToString, D as isAddress, F as isAddressEqual, H as isBytes, I as isHex, N as keccak256, O as numberToBytes, Y as numberToHex, P as pad, Q as padBytes, R as padHex, S as parseEther, T as parseGwei, U as parseUnit, Z as size, _ as slice, $ as sliceBytes, a0 as sliceHex, a1 as stringToBytes, a2 as stringToHex, a3 as trim } from '../parseGwei-0c9cad8a.js';
1
+ export { E as EncodeRlpResponse, G as GetContractAddressOptions, b as GetCreate2AddressOptions, a as GetCreateAddressOptions, e as boolToBytes, f as boolToHex, g as bytesToBigint, h as bytesToBool, c as bytesToHex, i as bytesToNumber, d as bytesToString, j as decodeAbi, k as decodeBytes, l as decodeErrorResult, m as decodeFunctionData, n as decodeFunctionResult, o as decodeHex, p as decodeRlp, q as encodeAbi, r as encodeBytes, s as encodeDeployData, t as encodeErrorResult, u as encodeEventTopics, v as encodeFunctionData, w as encodeFunctionResult, x as encodeHex, y as encodeRlp, H as formatEther, Y as formatGwei, Z as formatUnit, z as getAddress, A as getContractAddress, C as getCreate2Address, B as getCreateAddress, D as getEventSignature, F as getFunctionSignature, M as hexToBigInt, N as hexToBool, O as hexToBytes, _ as hexToNumber, P as hexToString, I as isAddress, J as isAddressEqual, K as isBytes, L as isHex, Q as keccak256, R as numberToBytes, $ as numberToHex, S as pad, T as padBytes, U as padHex, V as parseEther, W as parseGwei, X as parseUnit, a0 as size, a1 as slice, a2 as sliceBytes, a3 as sliceHex, a4 as stringToBytes, a5 as stringToHex, a6 as trim } from '../parseGwei-14f716fc.js';
2
2
  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-3e463099.js';
3
3
  export { r as rpc } from '../rpc-26932bae.js';
4
4
  import 'abitype';
@@ -8,6 +8,7 @@ import {
8
8
  bytesToString,
9
9
  decodeAbi,
10
10
  decodeBytes,
11
+ decodeErrorResult,
11
12
  decodeFunctionData,
12
13
  decodeFunctionResult,
13
14
  decodeHex,
@@ -15,6 +16,8 @@ import {
15
16
  encodeAbi,
16
17
  encodeBytes,
17
18
  encodeDeployData,
19
+ encodeErrorResult,
20
+ encodeEventTopics,
18
21
  encodeFunctionData,
19
22
  encodeFunctionResult,
20
23
  encodeHex,
@@ -60,11 +63,11 @@ import {
60
63
  stringToBytes,
61
64
  stringToHex,
62
65
  trim
63
- } from "../chunk-JND4MCSB.js";
66
+ } from "../chunk-4Z43OTO6.js";
64
67
  import {
65
68
  buildRequest,
66
69
  rpc
67
- } from "../chunk-LZSCKQVJ.js";
70
+ } from "../chunk-ALVD6MNU.js";
68
71
  export {
69
72
  boolToBytes,
70
73
  boolToHex,
@@ -76,6 +79,7 @@ export {
76
79
  bytesToString,
77
80
  decodeAbi,
78
81
  decodeBytes,
82
+ decodeErrorResult,
79
83
  decodeFunctionData,
80
84
  decodeFunctionResult,
81
85
  decodeHex,
@@ -83,6 +87,8 @@ export {
83
87
  encodeAbi,
84
88
  encodeBytes,
85
89
  encodeDeployData,
90
+ encodeErrorResult,
91
+ encodeEventTopics,
86
92
  encodeFunctionData,
87
93
  encodeFunctionResult,
88
94
  encodeHex,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript (& JavaScript) Interface for Ethereum",
4
- "version": "0.0.1-alpha.6",
4
+ "version": "0.0.1-alpha.8",
5
5
  "files": [
6
6
  "/actions",
7
7
  "/chains",