viem 0.0.1-alpha.3 → 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.
- package/dist/actions/index.js +3 -3
- package/dist/chains.js +2 -2
- package/dist/{chunk-TLEMV4T3.js → chunk-CI2RMCPH.js} +1 -1
- package/dist/{chunk-WZITKXV3.js → chunk-J7TAHE5G.js} +17 -1
- package/dist/{chunk-YZEQFYZ3.js → chunk-L4ZEGSSO.js} +2 -2
- package/dist/{chunk-SRDTRROA.js → chunk-LM2GVIJG.js} +39 -1
- package/dist/clients/index.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -4
- package/dist/{parseGwei-0f85e8ca.d.ts → parseGwei-f454ca76.d.ts} +28 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +6 -2
- package/package.json +1 -1
package/dist/actions/index.js
CHANGED
@@ -58,9 +58,9 @@ import {
|
|
58
58
|
watchBlockNumber,
|
59
59
|
watchBlocks,
|
60
60
|
watchPendingTransactions
|
61
|
-
} from "../chunk-
|
62
|
-
import "../chunk-
|
63
|
-
import "../chunk-
|
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
@@ -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.
|
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",
|
@@ -213,6 +213,21 @@ var AbiFunctionNotFoundError = class extends BaseError {
|
|
213
213
|
__publicField(this, "name", "AbiFunctionNotFoundError");
|
214
214
|
}
|
215
215
|
};
|
216
|
+
var AbiFunctionOutputsNotFoundError = class extends BaseError {
|
217
|
+
constructor(functionName) {
|
218
|
+
super(
|
219
|
+
[
|
220
|
+
`Function "${functionName}" does not contain any \`outputs\` on ABI.`,
|
221
|
+
"Cannot decode function result without knowing what the parameter types are.",
|
222
|
+
"Make sure you are using the correct ABI and that the function exists on it."
|
223
|
+
].join("\n"),
|
224
|
+
{
|
225
|
+
docsPath: "/docs/contract/decodeFunctionResult"
|
226
|
+
}
|
227
|
+
);
|
228
|
+
__publicField(this, "name", "AbiFunctionOutputsNotFoundError");
|
229
|
+
}
|
230
|
+
};
|
216
231
|
var AbiFunctionSignatureNotFoundError = class extends BaseError {
|
217
232
|
constructor(signature) {
|
218
233
|
super(
|
@@ -949,6 +964,7 @@ export {
|
|
949
964
|
AbiEncodingArrayLengthMismatchError,
|
950
965
|
AbiEncodingLengthMismatchError,
|
951
966
|
AbiFunctionNotFoundError,
|
967
|
+
AbiFunctionOutputsNotFoundError,
|
952
968
|
AbiFunctionSignatureNotFoundError,
|
953
969
|
InvalidAbiEncodingTypeError,
|
954
970
|
InvalidAbiDecodingTypeError,
|
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
getAddress,
|
12
12
|
hexToNumber,
|
13
13
|
numberToHex
|
14
|
-
} from "./chunk-
|
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-
|
25
|
+
} from "./chunk-J7TAHE5G.js";
|
26
26
|
|
27
27
|
// src/actions/public/call.ts
|
28
28
|
async function call(client, {
|
@@ -3,6 +3,7 @@ import {
|
|
3
3
|
AbiEncodingArrayLengthMismatchError,
|
4
4
|
AbiEncodingLengthMismatchError,
|
5
5
|
AbiFunctionNotFoundError,
|
6
|
+
AbiFunctionOutputsNotFoundError,
|
6
7
|
AbiFunctionSignatureNotFoundError,
|
7
8
|
DataLengthTooLongError,
|
8
9
|
DataLengthTooShortError,
|
@@ -16,7 +17,7 @@ import {
|
|
16
17
|
InvalidHexValueError,
|
17
18
|
OffsetOutOfBoundsError,
|
18
19
|
SizeExceedsPaddingSizeError
|
19
|
-
} from "./chunk-
|
20
|
+
} from "./chunk-J7TAHE5G.js";
|
20
21
|
|
21
22
|
// src/utils/data/concat.ts
|
22
23
|
function concat(values) {
|
@@ -943,6 +944,21 @@ function decodeFunctionData({ abi, data }) {
|
|
943
944
|
};
|
944
945
|
}
|
945
946
|
|
947
|
+
// src/utils/abi/decodeFunctionResult.ts
|
948
|
+
function decodeFunctionResult({
|
949
|
+
abi,
|
950
|
+
functionName,
|
951
|
+
data
|
952
|
+
}) {
|
953
|
+
const description = abi.find((x) => "name" in x && x.name === functionName);
|
954
|
+
if (!description)
|
955
|
+
throw new AbiFunctionNotFoundError(functionName);
|
956
|
+
if (!("outputs" in description))
|
957
|
+
throw new AbiFunctionOutputsNotFoundError(functionName);
|
958
|
+
const values = decodeAbi({ data, params: description.outputs });
|
959
|
+
return values.length > 1 ? values : values.length === 1 ? values[0] : void 0;
|
960
|
+
}
|
961
|
+
|
946
962
|
// src/utils/abi/encodeFunctionData.ts
|
947
963
|
function encodeFunctionData({
|
948
964
|
abi,
|
@@ -961,6 +977,26 @@ function encodeFunctionData({
|
|
961
977
|
return concatHex([signature, data ?? "0x"]);
|
962
978
|
}
|
963
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
|
+
|
964
1000
|
// src/constants.ts
|
965
1001
|
var etherUnits = {
|
966
1002
|
gwei: 9,
|
@@ -1193,7 +1229,9 @@ export {
|
|
1193
1229
|
encodeAbi,
|
1194
1230
|
decodeAbi,
|
1195
1231
|
decodeFunctionData,
|
1232
|
+
decodeFunctionResult,
|
1196
1233
|
encodeFunctionData,
|
1234
|
+
encodeFunctionResult,
|
1197
1235
|
etherUnits,
|
1198
1236
|
gweiUnits,
|
1199
1237
|
weiUnits,
|
package/dist/clients/index.js
CHANGED
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
|
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-
|
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-
|
71
|
+
} from "./chunk-CI2RMCPH.js";
|
72
72
|
import {
|
73
73
|
boolToBytes,
|
74
74
|
boolToHex,
|
@@ -80,11 +80,13 @@ import {
|
|
80
80
|
decodeAbi,
|
81
81
|
decodeBytes,
|
82
82
|
decodeFunctionData,
|
83
|
+
decodeFunctionResult,
|
83
84
|
decodeHex,
|
84
85
|
decodeRlp,
|
85
86
|
encodeAbi,
|
86
87
|
encodeBytes,
|
87
88
|
encodeFunctionData,
|
89
|
+
encodeFunctionResult,
|
88
90
|
encodeHex,
|
89
91
|
encodeRlp,
|
90
92
|
etherUnits,
|
@@ -128,7 +130,7 @@ import {
|
|
128
130
|
transactionType,
|
129
131
|
trim,
|
130
132
|
weiUnits
|
131
|
-
} from "./chunk-
|
133
|
+
} from "./chunk-LM2GVIJG.js";
|
132
134
|
import {
|
133
135
|
AbiDecodingDataSizeInvalidError,
|
134
136
|
AbiEncodingArrayLengthMismatchError,
|
@@ -172,7 +174,7 @@ import {
|
|
172
174
|
UrlRequiredError,
|
173
175
|
WaitForTransactionReceiptTimeoutError,
|
174
176
|
WebSocketRequestError
|
175
|
-
} from "./chunk-
|
177
|
+
} from "./chunk-J7TAHE5G.js";
|
176
178
|
export {
|
177
179
|
AbiDecodingDataSizeInvalidError,
|
178
180
|
AbiEncodingArrayLengthMismatchError,
|
@@ -236,12 +238,14 @@ export {
|
|
236
238
|
decodeAbi,
|
237
239
|
decodeBytes,
|
238
240
|
decodeFunctionData,
|
241
|
+
decodeFunctionResult,
|
239
242
|
decodeHex,
|
240
243
|
decodeRlp,
|
241
244
|
dropTransaction,
|
242
245
|
encodeAbi,
|
243
246
|
encodeBytes,
|
244
247
|
encodeFunctionData,
|
248
|
+
encodeFunctionResult,
|
245
249
|
encodeHex,
|
246
250
|
encodeRlp,
|
247
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;
|
@@ -31,6 +47,12 @@ declare function decodeFunctionData({ abi, data }: {
|
|
31
47
|
args: readonly unknown[] | undefined;
|
32
48
|
};
|
33
49
|
|
50
|
+
declare function decodeFunctionResult<TAbi extends Abi = Abi, TFunctionName extends ExtractAbiFunctionNames<TAbi> = any>({ abi, functionName, data, }: {
|
51
|
+
abi: TAbi;
|
52
|
+
functionName: TFunctionName;
|
53
|
+
data: Hex;
|
54
|
+
}): unknown;
|
55
|
+
|
34
56
|
/**
|
35
57
|
* @description Encodes a list of primitive values into an ABI-encoded hex value.
|
36
58
|
*/
|
@@ -44,6 +66,11 @@ declare function encodeFunctionData<TAbi extends Abi = Abi, TFunctionName extend
|
|
44
66
|
functionName: TFunctionName;
|
45
67
|
} & ExtractArgsFromAbi<TAbi, TFunctionName>): `0x${string}`;
|
46
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
|
+
|
47
74
|
declare function getAddress(address: Address): `0x${string}`;
|
48
75
|
|
49
76
|
type GetCreateAddressOptions = {
|
@@ -245,4 +272,4 @@ declare function parseEther(ether: `${number}`, unit?: 'wei' | 'gwei'): bigint;
|
|
245
272
|
|
246
273
|
declare function parseGwei(ether: `${number}`, unit?: 'wei'): bigint;
|
247
274
|
|
248
|
-
export {
|
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 };
|
package/dist/utils/index.d.ts
CHANGED
@@ -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
|
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';
|
package/dist/utils/index.js
CHANGED
@@ -9,11 +9,13 @@ import {
|
|
9
9
|
decodeAbi,
|
10
10
|
decodeBytes,
|
11
11
|
decodeFunctionData,
|
12
|
+
decodeFunctionResult,
|
12
13
|
decodeHex,
|
13
14
|
decodeRlp,
|
14
15
|
encodeAbi,
|
15
16
|
encodeBytes,
|
16
17
|
encodeFunctionData,
|
18
|
+
encodeFunctionResult,
|
17
19
|
encodeHex,
|
18
20
|
encodeRlp,
|
19
21
|
extractFunctionName,
|
@@ -57,11 +59,11 @@ import {
|
|
57
59
|
stringToBytes,
|
58
60
|
stringToHex,
|
59
61
|
trim
|
60
|
-
} from "../chunk-
|
62
|
+
} from "../chunk-LM2GVIJG.js";
|
61
63
|
import {
|
62
64
|
buildRequest,
|
63
65
|
rpc
|
64
|
-
} from "../chunk-
|
66
|
+
} from "../chunk-J7TAHE5G.js";
|
65
67
|
export {
|
66
68
|
boolToBytes,
|
67
69
|
boolToHex,
|
@@ -74,11 +76,13 @@ export {
|
|
74
76
|
decodeAbi,
|
75
77
|
decodeBytes,
|
76
78
|
decodeFunctionData,
|
79
|
+
decodeFunctionResult,
|
77
80
|
decodeHex,
|
78
81
|
decodeRlp,
|
79
82
|
encodeAbi,
|
80
83
|
encodeBytes,
|
81
84
|
encodeFunctionData,
|
85
|
+
encodeFunctionResult,
|
82
86
|
encodeHex,
|
83
87
|
encodeRlp,
|
84
88
|
extractFunctionName,
|