viem 0.0.1-alpha.0 → 0.0.1-alpha.10

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 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>
@@ -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, bb 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 GetGasPriceResponse, q as GetPermissionsResponse, r as GetTransactionArgs, s as GetTransactionConfirmationsArgs, t as GetTransactionConfirmationsResponse, u as GetTransactionCountArgs, v as GetTransactionCountResponse, x as GetTransactionReceiptArgs, y as GetTransactionReceiptResponse, w as GetTransactionResponse, I as ImpersonateAccountArgs, z as IncreaseTimeArgs, bc as InvalidGasArgumentsError, M as MineArgs, O as OnBlock, A as OnBlockNumber, B as OnBlockNumberResponse, F as OnBlockResponse, H as OnTransactions, J as OnTransactionsResponse, b8 as ReplacementReason, b9 as ReplacementResponse, K as RequestPermissionsResponse, R as ResetArgs, L as RevertArgs, S as SendTransactionArgs, N as SendTransactionResponse, P as SendUnsignedTransactionArgs, Q as SendUnsignedTransactionResponse, T as SetBalanceArgs, U as SetBlockGasLimitArgs, Z as SetBlockTimestampIntervalArgs, V as SetCodeArgs, W as SetCoinbaseArgs, X as SetIntervalMiningArgs, Y as SetMinGasPriceArgs, $ as SetNextBlockBaseFeePerGasArgs, _ as SetNextBlockTimestampArgs, a0 as SetNonceArgs, a1 as SetStorageAtArgs, a2 as SignMessageArgs, a3 as SignMessageResponse, a4 as StopImpersonatingAccountArgs, a5 as SwitchChainArgs, a6 as UninstallFilterArgs, a7 as UninstallFilterResponse, a8 as WaitForTransactionReceiptArgs, a9 as WaitForTransactionReceiptResponse, ba as WaitForTransactionReceiptTimeoutError, aa as WatchAssetArgs, ab as WatchAssetResponse, ac as WatchBlockNumberArgs, ad as WatchBlocksArgs, ae as WatchPendingTransactionsArgs, af as addChain, ag as call, ah as createBlockFilter, ai as createPendingTransactionFilter, ak as dropTransaction, aj as estimateGas, al as getAutomine, am as getBalance, an as getBlock, ao as getBlockNumber, b6 as getBlockNumberCache, ap as getBlockTransactionCount, aq as getChainId, ar as getFeeHistory, b7 as getFilterChanges, as as getGasPrice, at as getPermissions, au as getTransaction, av as getTransactionConfirmations, aw as getTransactionCount, ax as getTransactionReceipt, ay as getTxpoolContent, az as getTxpoolStatus, aA as impersonateAccount, aB as increaseTime, aC as inspectTxpool, aD as mine, aE as removeBlockTimestampInterval, aG as requestAccounts, aH as requestPermissions, aF as reset, aI as revert, aJ as sendTransaction, aK as sendUnsignedTransaction, aL as setAutomine, aM as setBalance, aN as setBlockGasLimit, aO as setBlockTimestampInterval, aP as setCode, aQ as setCoinbase, aR as setIntervalMining, aS as setLoggingEnabled, aT as setMinGasPrice, aU as setNextBlockBaseFeePerGas, aV as setNextBlockTimestamp, aW as setNonce, aX as setStorageAt, aY as signMessage, aZ as snapshot, a_ as stopImpersonatingAccount, a$ as switchChain, b0 as uninstallFilter, b1 as waitForTransactionReceipt, b2 as watchAsset, b3 as watchBlockNumber, b4 as watchBlocks, b5 as watchPendingTransactions } from '../watchAsset-bb30848d.js';
2
- import { W as WalletClient } from '../createWalletClient-c40fef16.js';
1
+ export { C as CallArgs, a as CallContractArgs, b as CallContractResponse, c as CallResponse, d as CreateBlockFilterResponse, e as CreatePendingTransactionFilterResponse, D as DropTransactionArgs, E as EstimateGasArgs, f as EstimateGasResponse, bh as FormattedTransactionRequest, G as GetBalanceArgs, g as GetBalanceResponse, h as GetBlockArgs, i as GetBlockNumberArgs, j as GetBlockNumberResponse, k as GetBlockResponse, l as GetBlockTransactionCountArgs, m as GetBlockTransactionCountResponse, n as GetFeeHistoryArgs, o as GetFeeHistoryResponse, p as GetFilterChangesArgs, q as GetFilterChangesResponse, r as GetFilterLogsArgs, s as GetFilterLogsResponse, t as GetGasPriceResponse, u as GetPermissionsResponse, v as GetTransactionArgs, w as GetTransactionConfirmationsArgs, x as GetTransactionConfirmationsResponse, y as GetTransactionCountArgs, z as GetTransactionCountResponse, B as GetTransactionReceiptArgs, F as GetTransactionReceiptResponse, A as GetTransactionResponse, I as ImpersonateAccountArgs, H as IncreaseTimeArgs, M as MineArgs, O as OnBlock, J as OnBlockNumber, K as OnBlockNumberResponse, L as OnBlockResponse, N as OnTransactions, P as OnTransactionsResponse, bf as ReplacementReason, bg as ReplacementResponse, Q as RequestPermissionsResponse, R as ResetArgs, S as RevertArgs, T as SendTransactionArgs, U as SendTransactionResponse, V as SendUnsignedTransactionArgs, W as SendUnsignedTransactionResponse, X as SetBalanceArgs, Y as SetBlockGasLimitArgs, a1 as SetBlockTimestampIntervalArgs, Z as SetCodeArgs, _ as SetCoinbaseArgs, $ as SetIntervalMiningArgs, a0 as SetMinGasPriceArgs, a3 as SetNextBlockBaseFeePerGasArgs, a2 as SetNextBlockTimestampArgs, a4 as SetNonceArgs, a5 as SetStorageAtArgs, a6 as SignMessageArgs, a7 as SignMessageResponse, a8 as StopImpersonatingAccountArgs, a9 as SwitchChainArgs, aa as UninstallFilterArgs, ab as UninstallFilterResponse, ac as WaitForTransactionReceiptArgs, ad as WaitForTransactionReceiptResponse, ae as WatchAssetArgs, af as WatchAssetResponse, ag as WatchBlockNumberArgs, ah as WatchBlocksArgs, ai as WatchPendingTransactionsArgs, aj as addChain, ak as call, al as callContract, am as createBlockFilter, an as createPendingTransactionFilter, ap as dropTransaction, ao as estimateGas, aq as getAccounts, ar as getAutomine, as as getBalance, at as getBlock, au as getBlockNumber, be as getBlockNumberCache, av as getBlockTransactionCount, aw as getChainId, ax as getFeeHistory, ay as getFilterChanges, az as getFilterLogs, aA as getGasPrice, aB as getPermissions, aC as getTransaction, aD as getTransactionConfirmations, aE as getTransactionCount, aF as getTransactionReceipt, aG as getTxpoolContent, aH as getTxpoolStatus, aI as impersonateAccount, aJ as increaseTime, aK as inspectTxpool, aL as mine, aM as removeBlockTimestampInterval, aO as requestAccounts, aP as requestPermissions, aN as reset, aQ as revert, aR as sendTransaction, aS as sendUnsignedTransaction, aT as setAutomine, aU as setBalance, aV as setBlockGasLimit, aW as setBlockTimestampInterval, aX as setCode, aY as setCoinbase, aZ as setIntervalMining, a_ as setLoggingEnabled, a$ as setMinGasPrice, b0 as setNextBlockBaseFeePerGas, b1 as setNextBlockTimestamp, b2 as setNonce, b3 as setStorageAt, b4 as signMessage, b5 as snapshot, b6 as stopImpersonatingAccount, b7 as switchChain, b8 as uninstallFilter, b9 as waitForTransactionReceipt, ba as watchAsset, bb as watchBlockNumber, bc as watchBlocks, bd as watchPendingTransactions } from '../watchAsset-bc6373f4.js';
2
+ import 'abitype';
3
3
  import '../chains.js';
4
- import '../rpc-655c0ba4.js';
4
+ import '../rpc-b77c5aee.js';
5
5
  import '@wagmi/chains';
6
- import '../transactionRequest-ade896ac.js';
7
- import '../BaseError-7688f84e.js';
8
- import '../eip1193-8f7c22ce.js';
9
-
10
- declare function getAccounts(client: WalletClient): Promise<`0x${string}`[]>;
11
-
12
- export { getAccounts };
6
+ import '../transactionRequest-08d30731.js';
7
+ import '../createWalletClient-d612fe08.js';
8
+ import '../eip1193-020a6f13.js';
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  addChain,
3
3
  call,
4
+ callContract,
4
5
  createBlockFilter,
5
6
  createPendingTransactionFilter,
6
7
  dropTransaction,
@@ -15,6 +16,7 @@ import {
15
16
  getChainId,
16
17
  getFeeHistory,
17
18
  getFilterChanges,
19
+ getFilterLogs,
18
20
  getGasPrice,
19
21
  getPermissions,
20
22
  getTransaction,
@@ -57,11 +59,12 @@ import {
57
59
  watchBlockNumber,
58
60
  watchBlocks,
59
61
  watchPendingTransactions
60
- } from "../chunk-JSYJDK4W.js";
61
- import "../chunk-GI67STNV.js";
62
+ } from "../chunk-NMN4TFDP.js";
63
+ import "../chunk-6GAKRM5P.js";
62
64
  export {
63
65
  addChain,
64
66
  call,
67
+ callContract,
65
68
  createBlockFilter,
66
69
  createPendingTransactionFilter,
67
70
  dropTransaction,
@@ -76,6 +79,7 @@ export {
76
79
  getChainId,
77
80
  getFeeHistory,
78
81
  getFilterChanges,
82
+ getFilterLogs,
79
83
  getGasPrice,
80
84
  getPermissions,
81
85
  getTransaction,
package/dist/chains.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { R as RpcBlock, B as Block, q as RpcTransaction, D as Transaction, r as RpcTransactionReceipt, T as TransactionReceipt, v as TransactionRequest, s as RpcTransactionRequest, N as TransactionType, H as Hex } from './rpc-655c0ba4.js';
1
+ import { R as RpcBlock, d as Block, q as RpcTransaction, D as Transaction, r as RpcTransactionReceipt, T as TransactionReceipt, v as TransactionRequest, s as RpcTransactionRequest, N as TransactionType, H as Hex } from './rpc-b77c5aee.js';
2
2
  import { Chain as Chain$1 } from '@wagmi/chains';
3
3
 
4
4
  type Formatter<TSource = any, TTarget = any> = (value: TSource & {
@@ -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" | "value" | "gasPrice" | "maxFeePerGas" | "maxPriorityFeePerGas" | "accessList")[] = []>({ exclude, format: formatOverride, }: {
27
+ }>, TExclude extends ("type" | "gas" | "value" | "gasPrice" | "maxFeePerGas" | "maxPriorityFeePerGas" | "blockHash" | "blockNumber" | "hash" | "from" | "input" | "nonce" | "r" | "s" | "to" | "transactionIndex" | "v" | "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" | "from" | "gas" | "nonce" | "to" | "value" | "gasPrice" | "maxFeePerGas" | "maxPriorityFeePerGas" | "accessList")[] = []>({ exclude, format: formatOverride, }: {
35
+ }>, TExclude extends ("gas" | "value" | "gasPrice" | "maxFeePerGas" | "maxPriorityFeePerGas" | "data" | "from" | "nonce" | "to" | "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
@@ -3,7 +3,7 @@ import {
3
3
  formatTransaction,
4
4
  formatTransactionReceipt,
5
5
  formatTransactionRequest
6
- } from "./chunk-GI67STNV.js";
6
+ } from "./chunk-6GAKRM5P.js";
7
7
 
8
8
  // src/chains.ts
9
9
  import {
@@ -1,9 +1,9 @@
1
1
  import {
2
- BaseError,
2
+ UrlRequiredError,
3
3
  buildRequest,
4
4
  getSocket,
5
5
  rpc
6
- } from "./chunk-GI67STNV.js";
6
+ } from "./chunk-6GAKRM5P.js";
7
7
 
8
8
  // src/clients/transports/createTransport.ts
9
9
  function createTransport(config, value) {
@@ -13,38 +13,50 @@ function createTransport(config, value) {
13
13
  };
14
14
  }
15
15
 
16
- // src/clients/transports/errors.ts
17
- var UrlRequiredError = class extends BaseError {
18
- constructor() {
19
- super(
20
- "No URL was provided to the Transport. Please provide a valid RPC URL to the Transport.",
21
- {
22
- docsPath: "/TODO"
23
- }
24
- );
25
- }
26
- };
27
-
28
- // src/clients/transports/ethereumProvider.ts
29
- function ethereumProvider({
30
- key = "ethereumProvider",
31
- name = "Ethereum Provider",
32
- provider
33
- }) {
16
+ // src/clients/transports/custom.ts
17
+ function custom(provider, { key = "custom", name = "Custom Provider" } = {}) {
34
18
  return () => createTransport({
35
19
  key,
36
20
  name,
37
21
  request: provider.request.bind(provider),
38
- type: "ethereumProvider"
22
+ type: "custom"
39
23
  });
40
24
  }
41
25
 
26
+ // src/clients/transports/fallback.ts
27
+ function fallback(transports, { key = "fallback", name = "Fallback" } = {}) {
28
+ return ({ chain }) => createTransport(
29
+ {
30
+ key,
31
+ name,
32
+ async request({ method, params }) {
33
+ const fetch = async (i = 0) => {
34
+ const transport = transports[i]({ chain });
35
+ try {
36
+ return await transport.config.request({
37
+ method,
38
+ params
39
+ });
40
+ } catch (err) {
41
+ if (i < transports.length - 1)
42
+ return fetch(i + 1);
43
+ throw err;
44
+ }
45
+ };
46
+ return fetch();
47
+ },
48
+ type: "fallback"
49
+ },
50
+ {
51
+ transports: transports.map(
52
+ (fn) => fn({ chain })
53
+ )
54
+ }
55
+ );
56
+ }
57
+
42
58
  // src/clients/transports/http.ts
43
- function http({
44
- key = "http",
45
- name = "HTTP JSON-RPC",
46
- url
47
- } = {}) {
59
+ function http(url, { key = "http", name = "HTTP JSON-RPC" } = {}) {
48
60
  return ({ chain }) => {
49
61
  const url_ = url || chain?.rpcUrls.default.http[0];
50
62
  if (!url_)
@@ -72,10 +84,9 @@ function http({
72
84
  }
73
85
 
74
86
  // src/clients/transports/webSocket.ts
75
- function webSocket({
87
+ function webSocket(url, {
76
88
  key = "webSocket",
77
- name = "WebSocket JSON-RPC",
78
- url
89
+ name = "WebSocket JSON-RPC"
79
90
  } = {}) {
80
91
  return ({ chain }) => {
81
92
  const url_ = url || chain?.rpcUrls.default.webSocket?.[0];
@@ -186,16 +197,14 @@ function createPublicClient({
186
197
  pollingInterval
187
198
  }) {
188
199
  chain;
189
- return {
190
- ...createClient({
191
- chain,
192
- key,
193
- name,
194
- pollingInterval,
195
- transport,
196
- type: "publicClient"
197
- })
198
- };
200
+ return createClient({
201
+ chain,
202
+ key,
203
+ name,
204
+ pollingInterval,
205
+ transport,
206
+ type: "publicClient"
207
+ });
199
208
  }
200
209
 
201
210
  // src/clients/createTestClient.ts
@@ -227,21 +236,19 @@ function createWalletClient({
227
236
  name = "Wallet Client",
228
237
  pollingInterval
229
238
  }) {
230
- return {
231
- ...createClient({
232
- key,
233
- name,
234
- pollingInterval,
235
- transport,
236
- type: "walletClient"
237
- })
238
- };
239
+ return createClient({
240
+ key,
241
+ name,
242
+ pollingInterval,
243
+ transport,
244
+ type: "walletClient"
245
+ });
239
246
  }
240
247
 
241
248
  export {
242
249
  createTransport,
243
- UrlRequiredError,
244
- ethereumProvider,
250
+ custom,
251
+ fallback,
245
252
  http,
246
253
  webSocket,
247
254
  createClient,