viem 0.0.1-alpha.0 → 0.0.1-alpha.1
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/README.md +16 -0
- package/dist/actions/index.d.ts +3 -7
- package/dist/actions/index.js +4 -2
- package/dist/chains.d.ts +2 -2
- package/dist/chains.js +1 -1
- package/dist/{chunk-JSYJDK4W.js → chunk-LLYFXUSV.js} +99 -33
- package/dist/{chunk-OPR6LKYX.js → chunk-OQTFTQTO.js} +43 -17
- package/dist/{chunk-GI67STNV.js → chunk-Z6LRV6XI.js} +534 -25
- package/dist/clients/index.d.ts +2 -2
- package/dist/clients/index.js +6 -4
- package/dist/{createWalletClient-c40fef16.d.ts → createWalletClient-915223f3.d.ts} +5 -5
- package/dist/index.d.ts +5 -4
- package/dist/index.js +17 -5
- package/dist/{parseGwei-a7d0bcb2.d.ts → parseGwei-bbc055e4.d.ts} +60 -9
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +5 -1
- package/dist/{watchAsset-bb30848d.d.ts → watchAsset-04ab8db5.d.ts} +20 -22
- package/dist/{webSocket-14584a7e.d.ts → webSocket-c6e0d26f.d.ts} +25 -14
- package/package.json +61 -10
package/README.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
<p align="center">
|
2
|
+
<picture>
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/wagmi-dev/viem/blob/main/.github/viem-dark.svg">
|
4
|
+
<img alt="wagmi logo" src="https://github.com/wagmi-dev/viem/blob/main/.github/viem-light.svg" width="auto" height="60">
|
5
|
+
</picture>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<p align="center">
|
9
|
+
TypeScript Interface for Ethereum
|
10
|
+
<p>
|
11
|
+
|
12
|
+
<p align="center">
|
13
|
+
<a href="https://codecov.io/github/wagmi-dev/viem" >
|
14
|
+
<img src="https://codecov.io/github/wagmi-dev/viem/branch/main/graph/badge.svg?token=iUTN9R4Qfg"/>
|
15
|
+
</a>
|
16
|
+
</p>
|
package/dist/actions/index.d.ts
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
export { C as CallArgs, a as CallResponse, b as CreateBlockFilterResponse, c as CreatePendingTransactionFilterResponse, D as DropTransactionArgs, E as EstimateGasArgs, d as EstimateGasResponse,
|
2
|
-
import { W as WalletClient } from '../createWalletClient-c40fef16.js';
|
1
|
+
export { C as CallArgs, a as CallResponse, b as CreateBlockFilterResponse, c as CreatePendingTransactionFilterResponse, D as DropTransactionArgs, E as EstimateGasArgs, d as EstimateGasResponse, bf as FormattedTransactionRequest, G as GetBalanceArgs, e as GetBalanceResponse, f as GetBlockArgs, g as GetBlockNumberArgs, h as GetBlockNumberResponse, i as GetBlockResponse, j as GetBlockTransactionCountArgs, k as GetBlockTransactionCountResponse, l as GetFeeHistoryArgs, m as GetFeeHistoryResponse, n as GetFilterChangesArgs, o as GetFilterChangesResponse, p as GetFilterLogsArgs, q as GetFilterLogsResponse, r as GetGasPriceResponse, s as GetPermissionsResponse, t as GetTransactionArgs, u as GetTransactionConfirmationsArgs, v as GetTransactionConfirmationsResponse, w as GetTransactionCountArgs, x as GetTransactionCountResponse, z as GetTransactionReceiptArgs, A as GetTransactionReceiptResponse, y as GetTransactionResponse, I as ImpersonateAccountArgs, B as IncreaseTimeArgs, bg as InvalidGasArgumentsError, M as MineArgs, O as OnBlock, F as OnBlockNumber, H as OnBlockNumberResponse, J as OnBlockResponse, K as OnTransactions, L as OnTransactionsResponse, bc as ReplacementReason, bd as ReplacementResponse, N as RequestPermissionsResponse, R as ResetArgs, P as RevertArgs, S as SendTransactionArgs, Q as SendTransactionResponse, T as SendUnsignedTransactionArgs, U as SendUnsignedTransactionResponse, V as SetBalanceArgs, W as SetBlockGasLimitArgs, $ as SetBlockTimestampIntervalArgs, X as SetCodeArgs, Y as SetCoinbaseArgs, Z as SetIntervalMiningArgs, _ as SetMinGasPriceArgs, a1 as SetNextBlockBaseFeePerGasArgs, a0 as SetNextBlockTimestampArgs, a2 as SetNonceArgs, a3 as SetStorageAtArgs, a4 as SignMessageArgs, a5 as SignMessageResponse, a6 as StopImpersonatingAccountArgs, a7 as SwitchChainArgs, a8 as UninstallFilterArgs, a9 as UninstallFilterResponse, aa as WaitForTransactionReceiptArgs, ab as WaitForTransactionReceiptResponse, be as WaitForTransactionReceiptTimeoutError, ac as WatchAssetArgs, ad as WatchAssetResponse, ae as WatchBlockNumberArgs, af as WatchBlocksArgs, ag as WatchPendingTransactionsArgs, ah as addChain, ai as call, aj as createBlockFilter, ak as createPendingTransactionFilter, am as dropTransaction, al as estimateGas, an as getAccounts, ao as getAutomine, ap as getBalance, aq as getBlock, ar as getBlockNumber, bb as getBlockNumberCache, as as getBlockTransactionCount, at as getChainId, au as getFeeHistory, av as getFilterChanges, aw as getFilterLogs, ax as getGasPrice, ay as getPermissions, az as getTransaction, aA as getTransactionConfirmations, aB as getTransactionCount, aC as getTransactionReceipt, aD as getTxpoolContent, aE as getTxpoolStatus, aF as impersonateAccount, aG as increaseTime, aH as inspectTxpool, aI as mine, aJ as removeBlockTimestampInterval, aL as requestAccounts, aM as requestPermissions, aK as reset, aN as revert, aO as sendTransaction, aP as sendUnsignedTransaction, aQ as setAutomine, aR as setBalance, aS as setBlockGasLimit, aT as setBlockTimestampInterval, aU as setCode, aV as setCoinbase, aW as setIntervalMining, aX as setLoggingEnabled, aY as setMinGasPrice, aZ as setNextBlockBaseFeePerGas, a_ as setNextBlockTimestamp, a$ as setNonce, b0 as setStorageAt, b1 as signMessage, b2 as snapshot, b3 as stopImpersonatingAccount, b4 as switchChain, b5 as uninstallFilter, b6 as waitForTransactionReceipt, b7 as watchAsset, b8 as watchBlockNumber, b9 as watchBlocks, ba as watchPendingTransactions } from '../watchAsset-04ab8db5.js';
|
3
2
|
import '../chains.js';
|
4
3
|
import '../rpc-655c0ba4.js';
|
5
4
|
import '@wagmi/chains';
|
6
5
|
import '../transactionRequest-ade896ac.js';
|
7
|
-
import '../
|
6
|
+
import '../createWalletClient-915223f3.js';
|
8
7
|
import '../eip1193-8f7c22ce.js';
|
9
|
-
|
10
|
-
declare function getAccounts(client: WalletClient): Promise<`0x${string}`[]>;
|
11
|
-
|
12
|
-
export { getAccounts };
|
8
|
+
import '../BaseError-7688f84e.js';
|
package/dist/actions/index.js
CHANGED
@@ -15,6 +15,7 @@ import {
|
|
15
15
|
getChainId,
|
16
16
|
getFeeHistory,
|
17
17
|
getFilterChanges,
|
18
|
+
getFilterLogs,
|
18
19
|
getGasPrice,
|
19
20
|
getPermissions,
|
20
21
|
getTransaction,
|
@@ -57,8 +58,8 @@ import {
|
|
57
58
|
watchBlockNumber,
|
58
59
|
watchBlocks,
|
59
60
|
watchPendingTransactions
|
60
|
-
} from "../chunk-
|
61
|
-
import "../chunk-
|
61
|
+
} from "../chunk-LLYFXUSV.js";
|
62
|
+
import "../chunk-Z6LRV6XI.js";
|
62
63
|
export {
|
63
64
|
addChain,
|
64
65
|
call,
|
@@ -76,6 +77,7 @@ export {
|
|
76
77
|
getChainId,
|
77
78
|
getFeeHistory,
|
78
79
|
getFilterChanges,
|
80
|
+
getFilterLogs,
|
79
81
|
getGasPrice,
|
80
82
|
getPermissions,
|
81
83
|
getTransaction,
|
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 ("type" | "blockHash" | "blockNumber" | "from" | "gas" | "hash" | "input" | "nonce" | "r" | "s" | "to" | "transactionIndex" | "v" | "
|
27
|
+
}>, TExclude extends ("type" | "value" | "blockHash" | "blockNumber" | "from" | "gas" | "hash" | "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> & {
|
@@ -32,7 +32,7 @@ declare const defineTransaction: <TFormat extends Formatter<Partial<RpcTransacti
|
|
32
32
|
}) => Transaction<bigint, number> & ReturnType<TFormat> & { [K in TExclude[number]]: never; };
|
33
33
|
declare const defineTransactionRequest: <TFormat extends Formatter<Partial<TransactionRequest<bigint, number>>, Partial<RpcTransactionRequest> & {
|
34
34
|
[key: string]: unknown;
|
35
|
-
}>, TExclude extends ("data" | "
|
35
|
+
}>, TExclude extends ("data" | "value" | "from" | "gas" | "nonce" | "to" | "gasPrice" | "maxFeePerGas" | "maxPriorityFeePerGas" | "accessList")[] = []>({ exclude, format: formatOverride, }: {
|
36
36
|
exclude?: TExclude | undefined;
|
37
37
|
format?: TFormat | undefined;
|
38
38
|
}) => (data: Partial<TransactionRequest<bigint, number>> & {
|
package/dist/chains.js
CHANGED
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
numberToHex,
|
17
17
|
wait,
|
18
18
|
withCache
|
19
|
-
} from "./chunk-
|
19
|
+
} from "./chunk-Z6LRV6XI.js";
|
20
20
|
|
21
21
|
// src/actions/wallet/addChain.ts
|
22
22
|
async function addChain(client, chain) {
|
@@ -62,17 +62,45 @@ async function requestPermissions(client, permissions) {
|
|
62
62
|
}
|
63
63
|
|
64
64
|
// src/actions/wallet/sendTransaction.ts
|
65
|
-
async function sendTransaction(client, {
|
66
|
-
|
65
|
+
async function sendTransaction(client, {
|
66
|
+
chain,
|
67
|
+
from,
|
68
|
+
accessList,
|
69
|
+
data,
|
70
|
+
gas,
|
71
|
+
gasPrice,
|
72
|
+
maxFeePerGas,
|
73
|
+
maxPriorityFeePerGas,
|
74
|
+
nonce,
|
75
|
+
to,
|
76
|
+
value,
|
77
|
+
...rest
|
78
|
+
}) {
|
79
|
+
if (maxFeePerGas !== void 0 && maxPriorityFeePerGas !== void 0 && maxFeePerGas < maxPriorityFeePerGas)
|
67
80
|
throw new InvalidGasArgumentsError();
|
68
|
-
const request_ = format(
|
69
|
-
|
70
|
-
|
81
|
+
const request_ = format(
|
82
|
+
{
|
83
|
+
from,
|
84
|
+
accessList,
|
85
|
+
data,
|
86
|
+
gas,
|
87
|
+
gasPrice,
|
88
|
+
maxFeePerGas,
|
89
|
+
maxPriorityFeePerGas,
|
90
|
+
nonce,
|
91
|
+
to,
|
92
|
+
value,
|
93
|
+
...rest
|
94
|
+
},
|
95
|
+
{
|
96
|
+
formatter: chain?.formatters?.transactionRequest || formatTransactionRequest
|
97
|
+
}
|
98
|
+
);
|
71
99
|
const hash = await client.request({
|
72
100
|
method: "eth_sendTransaction",
|
73
101
|
params: [request_]
|
74
102
|
});
|
75
|
-
return
|
103
|
+
return hash;
|
76
104
|
}
|
77
105
|
var InvalidGasArgumentsError = class extends BaseError {
|
78
106
|
constructor() {
|
@@ -125,20 +153,50 @@ async function watchAsset(client, params) {
|
|
125
153
|
}
|
126
154
|
|
127
155
|
// src/actions/public/call.ts
|
128
|
-
async function call(client, {
|
129
|
-
|
156
|
+
async function call(client, {
|
157
|
+
blockNumber,
|
158
|
+
blockTag = "latest",
|
159
|
+
chain,
|
160
|
+
from,
|
161
|
+
accessList,
|
162
|
+
data,
|
163
|
+
gas,
|
164
|
+
gasPrice,
|
165
|
+
maxFeePerGas,
|
166
|
+
maxPriorityFeePerGas,
|
167
|
+
nonce,
|
168
|
+
to,
|
169
|
+
value,
|
170
|
+
...rest
|
171
|
+
}) {
|
172
|
+
if (maxFeePerGas !== void 0 && maxPriorityFeePerGas !== void 0 && maxFeePerGas < maxPriorityFeePerGas)
|
130
173
|
throw new InvalidGasArgumentsError();
|
131
174
|
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
132
|
-
const request_ = format(
|
133
|
-
|
134
|
-
|
135
|
-
|
175
|
+
const request_ = format(
|
176
|
+
{
|
177
|
+
from,
|
178
|
+
accessList,
|
179
|
+
data,
|
180
|
+
gas,
|
181
|
+
gasPrice,
|
182
|
+
maxFeePerGas,
|
183
|
+
maxPriorityFeePerGas,
|
184
|
+
nonce,
|
185
|
+
to,
|
186
|
+
value,
|
187
|
+
...rest
|
188
|
+
},
|
189
|
+
{
|
190
|
+
formatter: chain?.formatters?.transactionRequest || formatTransactionRequest
|
191
|
+
}
|
192
|
+
);
|
193
|
+
const response = await client.request({
|
136
194
|
method: "eth_call",
|
137
195
|
params: [request_, blockNumberHex || blockTag]
|
138
196
|
});
|
139
|
-
if (
|
197
|
+
if (response === "0x")
|
140
198
|
return { data: void 0 };
|
141
|
-
return { data };
|
199
|
+
return { data: response };
|
142
200
|
}
|
143
201
|
|
144
202
|
// src/actions/public/createPendingTransactionFilter.ts
|
@@ -161,16 +219,14 @@ async function createBlockFilter(client) {
|
|
161
219
|
async function estimateGas(client, {
|
162
220
|
blockNumber,
|
163
221
|
blockTag = "latest",
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
value
|
173
|
-
}
|
222
|
+
data,
|
223
|
+
from,
|
224
|
+
gas,
|
225
|
+
gasPrice,
|
226
|
+
maxFeePerGas,
|
227
|
+
maxPriorityFeePerGas,
|
228
|
+
to,
|
229
|
+
value
|
174
230
|
}) {
|
175
231
|
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
176
232
|
const parameters = {
|
@@ -314,6 +370,15 @@ async function getFilterChanges(client, { filter }) {
|
|
314
370
|
);
|
315
371
|
}
|
316
372
|
|
373
|
+
// src/actions/public/getFilterLogs.ts
|
374
|
+
async function getFilterLogs(client, { filter }) {
|
375
|
+
const logs = await client.request({
|
376
|
+
method: "eth_getFilterLogs",
|
377
|
+
params: [filter.id]
|
378
|
+
});
|
379
|
+
return logs.map(formatLog);
|
380
|
+
}
|
381
|
+
|
317
382
|
// src/actions/public/getGasPrice.ts
|
318
383
|
async function getGasPrice(client) {
|
319
384
|
const gasPrice = await client.request({
|
@@ -768,14 +833,14 @@ async function getAutomine(client) {
|
|
768
833
|
// src/actions/test/getTxpoolContent.ts
|
769
834
|
async function getTxpoolContent(client) {
|
770
835
|
return await client.request({
|
771
|
-
method:
|
836
|
+
method: "txpool_content"
|
772
837
|
});
|
773
838
|
}
|
774
839
|
|
775
840
|
// src/actions/test/getTxpoolStatus.ts
|
776
841
|
async function getTxpoolStatus(client) {
|
777
842
|
const { pending, queued } = await client.request({
|
778
|
-
method:
|
843
|
+
method: "txpool_status"
|
779
844
|
});
|
780
845
|
return {
|
781
846
|
pending: hexToNumber(pending),
|
@@ -802,7 +867,7 @@ async function increaseTime(client, { seconds }) {
|
|
802
867
|
// src/actions/test/inspectTxpool.ts
|
803
868
|
async function inspectTxpool(client) {
|
804
869
|
return await client.request({
|
805
|
-
method:
|
870
|
+
method: "txpool_inspect"
|
806
871
|
});
|
807
872
|
}
|
808
873
|
|
@@ -832,19 +897,19 @@ async function reset(client, { blockNumber, jsonRpcUrl } = {}) {
|
|
832
897
|
// src/actions/test/revert.ts
|
833
898
|
async function revert(client, { id }) {
|
834
899
|
return await client.request({
|
835
|
-
method:
|
900
|
+
method: "evm_revert",
|
836
901
|
params: [id]
|
837
902
|
});
|
838
903
|
}
|
839
904
|
|
840
905
|
// src/actions/test/sendUnsignedTransaction.ts
|
841
|
-
async function sendUnsignedTransaction(client,
|
906
|
+
async function sendUnsignedTransaction(client, request) {
|
842
907
|
const request_ = formatTransactionRequest(request);
|
843
908
|
const hash = await client.request({
|
844
909
|
method: "eth_sendUnsignedTransaction",
|
845
910
|
params: [request_]
|
846
911
|
});
|
847
|
-
return
|
912
|
+
return hash;
|
848
913
|
}
|
849
914
|
|
850
915
|
// src/actions/test/setAutomine.ts
|
@@ -930,7 +995,7 @@ async function setNextBlockBaseFeePerGas(client, { baseFeePerGas }) {
|
|
930
995
|
// src/actions/test/setNextBlockTimestamp.ts
|
931
996
|
async function setNextBlockTimestamp(client, { timestamp }) {
|
932
997
|
return await client.request({
|
933
|
-
method:
|
998
|
+
method: "evm_setNextBlockTimestamp",
|
934
999
|
params: [numberToHex(timestamp)]
|
935
1000
|
});
|
936
1001
|
}
|
@@ -958,7 +1023,7 @@ async function setStorageAt(client, { address, index, value }) {
|
|
958
1023
|
// src/actions/test/snapshot.ts
|
959
1024
|
async function snapshot(client) {
|
960
1025
|
return await client.request({
|
961
|
-
method:
|
1026
|
+
method: "evm_snapshot"
|
962
1027
|
});
|
963
1028
|
}
|
964
1029
|
|
@@ -992,6 +1057,7 @@ export {
|
|
992
1057
|
getChainId,
|
993
1058
|
getFeeHistory,
|
994
1059
|
getFilterChanges,
|
1060
|
+
getFilterLogs,
|
995
1061
|
getGasPrice,
|
996
1062
|
getTransaction,
|
997
1063
|
getTransactionConfirmations,
|
@@ -3,7 +3,7 @@ import {
|
|
3
3
|
buildRequest,
|
4
4
|
getSocket,
|
5
5
|
rpc
|
6
|
-
} from "./chunk-
|
6
|
+
} from "./chunk-Z6LRV6XI.js";
|
7
7
|
|
8
8
|
// src/clients/transports/createTransport.ts
|
9
9
|
function createTransport(config, value) {
|
@@ -25,26 +25,52 @@ var UrlRequiredError = class extends BaseError {
|
|
25
25
|
}
|
26
26
|
};
|
27
27
|
|
28
|
-
// src/clients/transports/
|
29
|
-
function
|
30
|
-
key = "ethereumProvider",
|
31
|
-
name = "Ethereum Provider",
|
32
|
-
provider
|
33
|
-
}) {
|
28
|
+
// src/clients/transports/custom.ts
|
29
|
+
function custom(provider, { key = "custom", name = "Custom Provider" } = {}) {
|
34
30
|
return () => createTransport({
|
35
31
|
key,
|
36
32
|
name,
|
37
33
|
request: provider.request.bind(provider),
|
38
|
-
type: "
|
34
|
+
type: "custom"
|
39
35
|
});
|
40
36
|
}
|
41
37
|
|
38
|
+
// src/clients/transports/fallback.ts
|
39
|
+
function fallback(transports, { key = "fallback", name = "Fallback" } = {}) {
|
40
|
+
return ({ chain }) => {
|
41
|
+
return createTransport(
|
42
|
+
{
|
43
|
+
key,
|
44
|
+
name,
|
45
|
+
async request({ method, params }) {
|
46
|
+
const fetch = async (i = 0) => {
|
47
|
+
const transport = transports[i]({ chain });
|
48
|
+
try {
|
49
|
+
return await transport.config.request({
|
50
|
+
method,
|
51
|
+
params
|
52
|
+
});
|
53
|
+
} catch (err) {
|
54
|
+
if (i < transports.length - 1)
|
55
|
+
return fetch(i + 1);
|
56
|
+
throw err;
|
57
|
+
}
|
58
|
+
};
|
59
|
+
return fetch();
|
60
|
+
},
|
61
|
+
type: "fallback"
|
62
|
+
},
|
63
|
+
{
|
64
|
+
transports: transports.map(
|
65
|
+
(fn) => fn({ chain })
|
66
|
+
)
|
67
|
+
}
|
68
|
+
);
|
69
|
+
};
|
70
|
+
}
|
71
|
+
|
42
72
|
// src/clients/transports/http.ts
|
43
|
-
function http({
|
44
|
-
key = "http",
|
45
|
-
name = "HTTP JSON-RPC",
|
46
|
-
url
|
47
|
-
} = {}) {
|
73
|
+
function http(url, { key = "http", name = "HTTP JSON-RPC" } = {}) {
|
48
74
|
return ({ chain }) => {
|
49
75
|
const url_ = url || chain?.rpcUrls.default.http[0];
|
50
76
|
if (!url_)
|
@@ -72,10 +98,9 @@ function http({
|
|
72
98
|
}
|
73
99
|
|
74
100
|
// src/clients/transports/webSocket.ts
|
75
|
-
function webSocket({
|
101
|
+
function webSocket(url, {
|
76
102
|
key = "webSocket",
|
77
|
-
name = "WebSocket JSON-RPC"
|
78
|
-
url
|
103
|
+
name = "WebSocket JSON-RPC"
|
79
104
|
} = {}) {
|
80
105
|
return ({ chain }) => {
|
81
106
|
const url_ = url || chain?.rpcUrls.default.webSocket?.[0];
|
@@ -241,7 +266,8 @@ function createWalletClient({
|
|
241
266
|
export {
|
242
267
|
createTransport,
|
243
268
|
UrlRequiredError,
|
244
|
-
|
269
|
+
custom,
|
270
|
+
fallback,
|
245
271
|
http,
|
246
272
|
webSocket,
|
247
273
|
createClient,
|