viem 0.0.1-alpha.4 → 0.0.1-alpha.5

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-43X52QQL.js";
62
- import "../chunk-ROF2KQ2X.js";
63
- import "../chunk-COHLCIQM.js";
61
+ } from "../chunk-L4ZEGSSO.js";
62
+ import "../chunk-LM2GVIJG.js";
63
+ import "../chunk-J7TAHE5G.js";
64
64
  export {
65
65
  addChain,
66
66
  call,
package/dist/chains.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  formatTransaction,
4
4
  formatTransactionReceipt,
5
5
  formatTransactionRequest
6
- } from "./chunk-ROF2KQ2X.js";
7
- import "./chunk-COHLCIQM.js";
6
+ } from "./chunk-LM2GVIJG.js";
7
+ import "./chunk-J7TAHE5G.js";
8
8
 
9
9
  // src/chains.ts
10
10
  import {
@@ -3,7 +3,7 @@ import {
3
3
  buildRequest,
4
4
  getSocket,
5
5
  rpc
6
- } from "./chunk-COHLCIQM.js";
6
+ } from "./chunk-J7TAHE5G.js";
7
7
 
8
8
  // src/clients/transports/createTransport.ts
9
9
  function createTransport(config, value) {
@@ -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.4",
12
+ version: "0.0.1-alpha.5",
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",
@@ -11,7 +11,7 @@ import {
11
11
  getAddress,
12
12
  hexToNumber,
13
13
  numberToHex
14
- } from "./chunk-ROF2KQ2X.js";
14
+ } from "./chunk-LM2GVIJG.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-COHLCIQM.js";
25
+ } from "./chunk-J7TAHE5G.js";
26
26
 
27
27
  // src/actions/public/call.ts
28
28
  async function call(client, {
@@ -17,7 +17,7 @@ import {
17
17
  InvalidHexValueError,
18
18
  OffsetOutOfBoundsError,
19
19
  SizeExceedsPaddingSizeError
20
- } from "./chunk-COHLCIQM.js";
20
+ } from "./chunk-J7TAHE5G.js";
21
21
 
22
22
  // src/utils/data/concat.ts
23
23
  function concat(values) {
@@ -977,6 +977,26 @@ function encodeFunctionData({
977
977
  return concatHex([signature, data ?? "0x"]);
978
978
  }
979
979
 
980
+ // src/utils/abi/encodeFunctionResult.ts
981
+ function encodeFunctionResult({
982
+ abi,
983
+ functionName,
984
+ result
985
+ }) {
986
+ const description = abi.find((x) => "name" in x && x.name === functionName);
987
+ if (!description)
988
+ throw new AbiFunctionNotFoundError(functionName);
989
+ if (!("outputs" in description))
990
+ throw new AbiFunctionOutputsNotFoundError(functionName);
991
+ let values = Array.isArray(result) ? result : [result];
992
+ if (description.outputs.length === 0 && !values[0])
993
+ values = [];
994
+ const data = encodeAbi({ params: description.outputs, values });
995
+ if (!data)
996
+ return "0x";
997
+ return data;
998
+ }
999
+
980
1000
  // src/constants.ts
981
1001
  var etherUnits = {
982
1002
  gwei: 9,
@@ -1211,6 +1231,7 @@ export {
1211
1231
  decodeFunctionData,
1212
1232
  decodeFunctionResult,
1213
1233
  encodeFunctionData,
1234
+ encodeFunctionResult,
1214
1235
  etherUnits,
1215
1236
  gweiUnits,
1216
1237
  weiUnits,
@@ -8,8 +8,8 @@ import {
8
8
  fallback,
9
9
  http,
10
10
  webSocket
11
- } from "../chunk-ZGVHEFCJ.js";
12
- import "../chunk-COHLCIQM.js";
11
+ } from "../chunk-CI2RMCPH.js";
12
+ import "../chunk-J7TAHE5G.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-b55b0951.js';
4
4
  import { A as Address, H as Hash, B as ByteArray, a as Hex, b as BlockTag } from './rpc-15b85963.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, H as Hash, a 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-15b85963.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 encodeFunctionData, s as encodeHex, t as encodeRlp, A as formatEther, T as formatGwei, U as formatUnit, u as getAddress, v as getContractAddress, x as getCreate2Address, w as getCreateAddress, y as getEventSignature, z as getFunctionSignature, H as hexToBigInt, I as hexToBool, J as hexToBytes, V as hexToNumber, K as hexToString, B as isAddress, C as isAddressEqual, D as isBytes, F as isHex, L as keccak256, M as numberToBytes, W as numberToHex, N as pad, O as padBytes, P as padHex, Q as parseEther, R as parseGwei, S as parseUnit, X as size, Y as slice, Z as sliceBytes, _ as sliceHex, $ as stringToBytes, a0 as stringToHex, a1 as trim } from './parseGwei-a952d720.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 encodeFunctionData, s as encodeFunctionResult, t as encodeHex, u as encodeRlp, B as formatEther, U as formatGwei, V as formatUnit, v as getAddress, w as getContractAddress, y as getCreate2Address, x as getCreateAddress, z as getEventSignature, A as getFunctionSignature, I as hexToBigInt, J as hexToBool, K as hexToBytes, W as hexToNumber, L as hexToString, C as isAddress, D as isAddressEqual, F as isBytes, H as isHex, M as keccak256, N as numberToBytes, X as numberToHex, O as pad, P as padBytes, Q as padHex, R as parseEther, S as parseGwei, T as parseUnit, Y as size, Z as slice, _ as sliceBytes, $ as sliceHex, a0 as stringToBytes, a1 as stringToHex, a2 as trim } from './parseGwei-f454ca76.js';
7
7
  export { F as FormattedBlock, a as FormattedTransaction, b as FormattedTransactionRequest, f as formatBlock, c as formatTransaction, d as formatTransactionRequest } from './transactionRequest-f538ea86.js';
8
8
  import './chains.js';
9
9
  import '@wagmi/chains';
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ import {
57
57
  watchBlockNumber,
58
58
  watchBlocks,
59
59
  watchPendingTransactions
60
- } from "./chunk-43X52QQL.js";
60
+ } from "./chunk-L4ZEGSSO.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-ZGVHEFCJ.js";
71
+ } from "./chunk-CI2RMCPH.js";
72
72
  import {
73
73
  boolToBytes,
74
74
  boolToHex,
@@ -86,6 +86,7 @@ import {
86
86
  encodeAbi,
87
87
  encodeBytes,
88
88
  encodeFunctionData,
89
+ encodeFunctionResult,
89
90
  encodeHex,
90
91
  encodeRlp,
91
92
  etherUnits,
@@ -129,7 +130,7 @@ import {
129
130
  transactionType,
130
131
  trim,
131
132
  weiUnits
132
- } from "./chunk-ROF2KQ2X.js";
133
+ } from "./chunk-LM2GVIJG.js";
133
134
  import {
134
135
  AbiDecodingDataSizeInvalidError,
135
136
  AbiEncodingArrayLengthMismatchError,
@@ -173,7 +174,7 @@ import {
173
174
  UrlRequiredError,
174
175
  WaitForTransactionReceiptTimeoutError,
175
176
  WebSocketRequestError
176
- } from "./chunk-COHLCIQM.js";
177
+ } from "./chunk-J7TAHE5G.js";
177
178
  export {
178
179
  AbiDecodingDataSizeInvalidError,
179
180
  AbiEncodingArrayLengthMismatchError,
@@ -244,6 +245,7 @@ export {
244
245
  encodeAbi,
245
246
  encodeBytes,
246
247
  encodeFunctionData,
248
+ encodeFunctionResult,
247
249
  encodeHex,
248
250
  encodeRlp,
249
251
  estimateGas,
@@ -17,6 +17,22 @@ type ExtractArgsFromAbi<TAbi extends Abi | readonly unknown[], TFunctionName ext
17
17
  } : {
18
18
  /** Arguments to pass contract method */ args: TArgs;
19
19
  };
20
+ type ExtractResultFromAbi<TAbi extends Abi | readonly unknown[], TFunctionName extends string, TAbiFunction extends AbiFunction & {
21
+ type: 'function';
22
+ } = TAbi extends Abi ? ExtractAbiFunction<TAbi, TFunctionName> : AbiFunction & {
23
+ type: 'function';
24
+ }, TArgs = AbiParametersToPrimitiveTypes<TAbiFunction['outputs']>, FailedToParseArgs = ([TArgs] extends [never] ? true : false) | (readonly unknown[] extends TArgs ? true : false)> = true extends FailedToParseArgs ? {
25
+ /**
26
+ * Arguments to pass contract method
27
+ *
28
+ * Use a [const assertion](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions) on {@link abi} for type inference.
29
+ */
30
+ result?: readonly unknown[];
31
+ } : TArgs extends readonly [] ? {
32
+ result?: never;
33
+ } : {
34
+ /** Arguments to pass contract method */ result: TArgs;
35
+ };
20
36
 
21
37
  declare function decodeAbi<TParams extends readonly AbiParameter[]>({ data, params, }: {
22
38
  data: Hex;
@@ -50,6 +66,11 @@ declare function encodeFunctionData<TAbi extends Abi = Abi, TFunctionName extend
50
66
  functionName: TFunctionName;
51
67
  } & ExtractArgsFromAbi<TAbi, TFunctionName>): `0x${string}`;
52
68
 
69
+ declare function encodeFunctionResult<TAbi extends Abi = Abi, TFunctionName extends ExtractAbiFunctionNames<TAbi> = any>({ abi, functionName, result, }: {
70
+ abi: TAbi;
71
+ functionName: TFunctionName;
72
+ } & ExtractResultFromAbi<TAbi, TFunctionName>): `0x${string}`;
73
+
53
74
  declare function getAddress(address: Address): `0x${string}`;
54
75
 
55
76
  type GetCreateAddressOptions = {
@@ -251,4 +272,4 @@ declare function parseEther(ether: `${number}`, unit?: 'wei' | 'gwei'): bigint;
251
272
 
252
273
  declare function parseGwei(ether: `${number}`, unit?: 'wei'): bigint;
253
274
 
254
- export { stringToBytes as $, formatEther as A, isAddress as B, isAddressEqual as C, isBytes as D, EncodeRlpResponse as E, isHex as F, GetContractAddressOptions as G, hexToBigInt as H, hexToBool as I, hexToBytes as J, hexToString as K, keccak256 as L, numberToBytes as M, pad as N, padBytes as O, padHex as P, parseEther as Q, parseGwei as R, parseUnit as S, formatGwei as T, formatUnit as U, hexToNumber as V, numberToHex as W, size as X, slice as Y, sliceBytes as Z, sliceHex as _, GetCreateAddressOptions as a, stringToHex as a0, trim as a1, 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, encodeFunctionData as r, encodeHex as s, encodeRlp as t, getAddress as u, getContractAddress as v, getCreateAddress as w, getCreate2Address as x, getEventSignature as y, getFunctionSignature as z };
275
+ export { sliceHex 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, hexToBigInt as I, hexToBool as J, hexToBytes as K, hexToString as L, keccak256 as M, numberToBytes as N, pad as O, padBytes as P, padHex as Q, parseEther as R, parseGwei as S, parseUnit as T, formatGwei as U, formatUnit as V, hexToNumber as W, numberToHex as X, size as Y, slice as Z, sliceBytes as _, GetCreateAddressOptions as a, stringToBytes as a0, stringToHex as a1, trim as a2, 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, encodeFunctionData as r, encodeFunctionResult as s, encodeHex as t, encodeRlp as u, getAddress as v, getContractAddress as w, getCreateAddress as x, getCreate2Address as y, getEventSignature 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 encodeFunctionData, s as encodeHex, t as encodeRlp, A as formatEther, T as formatGwei, U as formatUnit, u as getAddress, v as getContractAddress, x as getCreate2Address, w as getCreateAddress, y as getEventSignature, z as getFunctionSignature, H as hexToBigInt, I as hexToBool, J as hexToBytes, V as hexToNumber, K as hexToString, B as isAddress, C as isAddressEqual, D as isBytes, F as isHex, L as keccak256, M as numberToBytes, W as numberToHex, N as pad, O as padBytes, P as padHex, Q as parseEther, R as parseGwei, S as parseUnit, X as size, Y as slice, Z as sliceBytes, _ as sliceHex, $ as stringToBytes, a0 as stringToHex, a1 as trim } from '../parseGwei-a952d720.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 decodeFunctionData, m as decodeFunctionResult, n as decodeHex, o as decodeRlp, p as encodeAbi, q as encodeBytes, r as encodeFunctionData, s as encodeFunctionResult, t as encodeHex, u as encodeRlp, B as formatEther, U as formatGwei, V as formatUnit, v as getAddress, w as getContractAddress, y as getCreate2Address, x as getCreateAddress, z as getEventSignature, A as getFunctionSignature, I as hexToBigInt, J as hexToBool, K as hexToBytes, W as hexToNumber, L as hexToString, C as isAddress, D as isAddressEqual, F as isBytes, H as isHex, M as keccak256, N as numberToBytes, X as numberToHex, O as pad, P as padBytes, Q as padHex, R as parseEther, S as parseGwei, T as parseUnit, Y as size, Z as slice, _ as sliceBytes, $ as sliceHex, a0 as stringToBytes, a1 as stringToHex, a2 as trim } from '../parseGwei-f454ca76.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-f538ea86.js';
3
3
  export { r as rpc } from '../rpc-26932bae.js';
4
4
  import 'abitype';
@@ -15,6 +15,7 @@ import {
15
15
  encodeAbi,
16
16
  encodeBytes,
17
17
  encodeFunctionData,
18
+ encodeFunctionResult,
18
19
  encodeHex,
19
20
  encodeRlp,
20
21
  extractFunctionName,
@@ -58,11 +59,11 @@ import {
58
59
  stringToBytes,
59
60
  stringToHex,
60
61
  trim
61
- } from "../chunk-ROF2KQ2X.js";
62
+ } from "../chunk-LM2GVIJG.js";
62
63
  import {
63
64
  buildRequest,
64
65
  rpc
65
- } from "../chunk-COHLCIQM.js";
66
+ } from "../chunk-J7TAHE5G.js";
66
67
  export {
67
68
  boolToBytes,
68
69
  boolToHex,
@@ -81,6 +82,7 @@ export {
81
82
  encodeAbi,
82
83
  encodeBytes,
83
84
  encodeFunctionData,
85
+ encodeFunctionResult,
84
86
  encodeHex,
85
87
  encodeRlp,
86
88
  extractFunctionName,
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.4",
4
+ "version": "0.0.1-alpha.5",
5
5
  "files": [
6
6
  "/actions",
7
7
  "/chains",