viem 0.0.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.
@@ -0,0 +1,8 @@
1
+ export { C as Client, a as ClientConfig, P as PublicClient, b as PublicClientConfig, T as TestClient, c as TestClientConfig, d as Transport, e as TransportConfig, W as WalletClient, f as WalletClientConfig, g as createClient, h as createPublicClient, i as createTestClient, j as createTransport, k as createWalletClient } from '../createWalletClient-915223f3.js';
2
+ export { C as CustomTransport, a as CustomTransportConfig, F as FallbackTransport, b as FallbackTransportConfig, H as HttpTransport, c as HttpTransportConfig, U as UrlRequiredError, W as WebSocketTransport, d as WebSocketTransportConfig, e as custom, f as fallback, h as http, w as webSocket } from '../webSocket-c6e0d26f.js';
3
+ import '../chains.js';
4
+ import '../rpc-655c0ba4.js';
5
+ import '@wagmi/chains';
6
+ import '../eip1193-8f7c22ce.js';
7
+ import '../BaseError-7688f84e.js';
8
+ import '../rpc-3c0e3985.js';
@@ -0,0 +1,25 @@
1
+ import {
2
+ UrlRequiredError,
3
+ createClient,
4
+ createPublicClient,
5
+ createTestClient,
6
+ createTransport,
7
+ createWalletClient,
8
+ custom,
9
+ fallback,
10
+ http,
11
+ webSocket
12
+ } from "../chunk-OQTFTQTO.js";
13
+ import "../chunk-Z6LRV6XI.js";
14
+ export {
15
+ UrlRequiredError,
16
+ createClient,
17
+ createPublicClient,
18
+ createTestClient,
19
+ createTransport,
20
+ createWalletClient,
21
+ custom,
22
+ fallback,
23
+ http,
24
+ webSocket
25
+ };
@@ -0,0 +1,130 @@
1
+ import { Chain } from './chains.js';
2
+ import { R as Requests, P as PublicRequests, T as TestRequests, S as SignableRequests, b as WalletRequests } from './eip1193-8f7c22ce.js';
3
+
4
+ type BaseRpcRequests = {
5
+ request(...args: any): Promise<any>;
6
+ };
7
+ type TransportConfig<TType extends string = string, TRequests extends BaseRpcRequests['request'] = Requests['request']> = {
8
+ /** The name of the transport. */
9
+ name: string;
10
+ /** The key of the transport. */
11
+ key: string;
12
+ /** The JSON-RPC request function that matches the EIP-1193 request spec. */
13
+ request: TRequests;
14
+ /** The type of the transport. */
15
+ type: TType;
16
+ };
17
+ type Transport<TType extends string = string, TRpcAttributes = Record<string, any>> = <TChain extends Chain = Chain>({ chain, }: {
18
+ chain?: TChain;
19
+ }) => {
20
+ config: TransportConfig<TType>;
21
+ value?: TRpcAttributes;
22
+ };
23
+ /**
24
+ * @description Creates an transport intended to be used with a client.
25
+ */
26
+ declare function createTransport<TType extends string = string, TRpcAttributes = any>(config: TransportConfig<TType>, value?: TRpcAttributes): ReturnType<Transport<TType, TRpcAttributes>>;
27
+
28
+ type Client<TTransport extends Transport = Transport, TChain extends Chain = Chain, TRequests extends BaseRpcRequests = Requests> = {
29
+ /** Chain for the client. */
30
+ chain?: TChain;
31
+ /** A key for the client. */
32
+ key: string;
33
+ /** A name for the client. */
34
+ name: string;
35
+ /** Frequency (in ms) for polling enabled actions & events. Defaults to 4_000 milliseconds. */
36
+ pollingInterval: number;
37
+ /** Request function wrapped with friendly error handling */
38
+ request: TRequests['request'];
39
+ /** The RPC transport (http, webSocket, custom, etc) */
40
+ transport: ReturnType<TTransport>['config'] & ReturnType<TTransport>['value'];
41
+ /** The type of client. */
42
+ type: string;
43
+ /** A unique ID for the client. */
44
+ uid: string;
45
+ };
46
+ type ClientConfig<TTransport extends Transport = Transport, TChain extends Chain = Chain, TRequests extends BaseRpcRequests = Requests> = Partial<Pick<Client<TTransport, TChain, TRequests>, 'chain' | 'key' | 'name' | 'pollingInterval' | 'type'>> & {
47
+ transport: TTransport;
48
+ };
49
+ /**
50
+ * @description Creates a base RPC client with the given transport.
51
+ *
52
+ * - Intended to be used as a base for other RPC clients.
53
+ * - Has access to _all_ EIP-1474 RPC methods.
54
+ *
55
+ * @example
56
+ * import { mainnet } from 'viem/chains'
57
+ * import { createClient, http } from 'viem/clients'
58
+ * const client = createClient(http({ chain: mainnet }))
59
+ */
60
+ declare function createClient<TTransport extends Transport, TChain extends Chain, TRequests extends BaseRpcRequests>({ chain, key, name, pollingInterval, transport, type, }: ClientConfig<TTransport, TChain, TRequests>): Client<TTransport, TChain, TRequests>;
61
+
62
+ type PublicClientConfig<TTransport extends Transport = Transport, TChain extends Chain = Chain> = Pick<ClientConfig<TTransport, TChain>, 'chain' | 'key' | 'name' | 'pollingInterval' | 'transport'>;
63
+ type PublicClient<TTransport extends Transport = Transport, TChain extends Chain = Chain> = Client<TTransport, TChain, PublicRequests>;
64
+ /**
65
+ * @description Creates a public client with a given transport.
66
+ *
67
+ * - Only has access to "public" EIP-1474 RPC methods (ie. `eth_blockNumber`, etc).
68
+ *
69
+ * @example
70
+ * import { mainnet } from 'viem/chains'
71
+ * import { createPublicClient, http } from 'viem/clients'
72
+ * const client = createPublicClient(http({ chain: mainnet }))
73
+ */
74
+ declare function createPublicClient<TTransport extends Transport, TChain extends Chain>({ chain, key, name, transport, pollingInterval, }: PublicClientConfig<TTransport, TChain>): PublicClient<TTransport, TChain>;
75
+
76
+ type TestClientModes = 'anvil' | 'hardhat';
77
+ type TestClientConfig<TTransport extends Transport = Transport, TChain extends Chain = Chain, TMode extends TestClientModes = TestClientModes> = {
78
+ chain?: ClientConfig<TTransport, TChain>['chain'];
79
+ /** The key of the client. */
80
+ key?: ClientConfig['key'];
81
+ /** Mode of the test client. Available: "anvil" | "hardhat" */
82
+ mode: TMode;
83
+ /** The name of the client. */
84
+ name?: ClientConfig['name'];
85
+ /** Frequency (in ms) for polling enabled actions & events. Defaults to 4_000 milliseconds. */
86
+ pollingInterval?: ClientConfig['pollingInterval'];
87
+ transport: ClientConfig<TTransport, TChain>['transport'];
88
+ };
89
+ type TestClient<TTransport extends Transport = Transport, TChain extends Chain = Chain, TMode extends TestClientModes = TestClientModes> = Client<TTransport, TChain, TestRequests<TMode>> & {
90
+ mode: TMode;
91
+ };
92
+ /**
93
+ * @description Creates a test client with a given transport.
94
+ *
95
+ * - Only has access to "test" RPC methods (ie. `anvil_setBalance`,
96
+ * `evm_mine`, etc).
97
+ *
98
+ * @example
99
+ * import { createTestClient, http } from 'viem'
100
+ * import { local } from 'viem/chains'
101
+ * const client = createTestClient({ chain: local, mode: 'anvil', transport: http() })
102
+ */
103
+ declare function createTestClient<TTransport extends Transport, TChain extends Chain, TMode extends TestClientModes>({ chain, key, name, mode, pollingInterval, transport, }: TestClientConfig<TTransport, TChain, TMode>): TestClient<TTransport, TChain, TMode>;
104
+
105
+ type WalletClientConfig<TTransport extends Transport = Transport, TChain extends Chain = Chain> = {
106
+ chain?: ClientConfig<TTransport, TChain>['chain'];
107
+ /** The key of the Wallet Client. */
108
+ key?: ClientConfig['key'];
109
+ /** The name of the Wallet Client. */
110
+ name?: ClientConfig['name'];
111
+ /** Frequency (in ms) for polling enabled actions & events. Defaults to 4_000 milliseconds. */
112
+ pollingInterval?: ClientConfig['pollingInterval'];
113
+ transport: ClientConfig<TTransport, TChain>['transport'];
114
+ };
115
+ type WalletClient<TTransport extends Transport = Transport, TChain extends Chain = Chain> = Client<TTransport, TChain, SignableRequests & WalletRequests>;
116
+ /**
117
+ * @description Creates a wallet client with a given transport.
118
+ *
119
+ * - Only has access to "wallet" & "signable" EIP-1474 RPC methods
120
+ * (ie. `eth_sendTransaction`, `eth_requestAccounts`, etc).
121
+ *
122
+ * @example
123
+ * import { createWalletClient, custom } from 'viem'
124
+ * const client = createWalletClient(
125
+ * custom(window.ethereum)
126
+ * )
127
+ */
128
+ declare function createWalletClient<TTransport extends Transport, TChain extends Chain>({ transport, key, name, pollingInterval, }: WalletClientConfig<TTransport, TChain>): WalletClient<TTransport, TChain>;
129
+
130
+ export { BaseRpcRequests as B, Client as C, PublicClient as P, TestClient as T, WalletClient as W, ClientConfig as a, PublicClientConfig as b, TestClientConfig as c, Transport as d, TransportConfig as e, WalletClientConfig as f, createClient as g, createPublicClient as h, createTestClient as i, createTransport as j, createWalletClient as k };