viem 0.0.1-alpha.10 → 0.0.1-alpha.12
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/actions/package.json +1 -1
- package/chains/package.json +1 -1
- package/clients/package.json +1 -1
- package/dist/actions/index.d.ts +3 -3
- package/dist/actions/index.js +125 -125
- package/dist/actions/index.mjs +125 -0
- package/dist/chains.d.ts +648 -18
- package/dist/chains.js +76 -75
- package/dist/chains.mjs +134 -0
- package/dist/chunk-A3PVAH22.js +2618 -0
- package/dist/chunk-A4O3JKF2.js +258 -0
- package/dist/{chunk-NMN4TFDP.js → chunk-DPSKYDCG.mjs} +1 -1
- package/dist/{chunk-6GAKRM5P.js → chunk-ERPD74AT.mjs} +12 -7
- package/dist/{chunk-3TSTZHVO.js → chunk-PC3JNTPF.mjs} +1 -1
- package/dist/chunk-QO5C5Y2L.js +1084 -0
- package/dist/clients/index.d.ts +3 -3
- package/dist/clients/index.js +23 -23
- package/dist/clients/index.mjs +23 -0
- package/dist/{createWalletClient-d612fe08.d.ts → createWalletClient-3f9fa8b6.d.ts} +1 -1
- package/dist/{eip1193-020a6f13.d.ts → eip1193-c001fcd5.d.ts} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +374 -374
- package/dist/index.mjs +374 -0
- package/dist/utils/index.js +148 -148
- package/dist/utils/index.mjs +148 -0
- package/dist/{watchAsset-bc6373f4.d.ts → watchAsset-43255bfd.d.ts} +2 -2
- package/dist/{webSocket-7f88e9e0.d.ts → webSocket-3385e295.d.ts} +1 -1
- package/dist/window.d.ts +1 -1
- package/dist/window.js +1 -0
- package/dist/window.mjs +0 -0
- package/package.json +14 -65
- package/utils/package.json +1 -1
- package/window/package.json +1 -1
@@ -0,0 +1,258 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
var _chunkA3PVAH22js = require('./chunk-A3PVAH22.js');
|
7
|
+
|
8
|
+
// src/clients/transports/createTransport.ts
|
9
|
+
function createTransport(config, value) {
|
10
|
+
return {
|
11
|
+
config,
|
12
|
+
value
|
13
|
+
};
|
14
|
+
}
|
15
|
+
|
16
|
+
// src/clients/transports/custom.ts
|
17
|
+
function custom(provider, { key = "custom", name = "Custom Provider" } = {}) {
|
18
|
+
return () => createTransport({
|
19
|
+
key,
|
20
|
+
name,
|
21
|
+
request: provider.request.bind(provider),
|
22
|
+
type: "custom"
|
23
|
+
});
|
24
|
+
}
|
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
|
+
|
58
|
+
// src/clients/transports/http.ts
|
59
|
+
function http(url, { key = "http", name = "HTTP JSON-RPC" } = {}) {
|
60
|
+
return ({ chain }) => {
|
61
|
+
const url_ = url || _optionalChain([chain, 'optionalAccess', _ => _.rpcUrls, 'access', _2 => _2.default, 'access', _3 => _3.http, 'access', _4 => _4[0]]);
|
62
|
+
if (!url_)
|
63
|
+
throw new (0, _chunkA3PVAH22js.UrlRequiredError)();
|
64
|
+
return createTransport(
|
65
|
+
{
|
66
|
+
key,
|
67
|
+
name,
|
68
|
+
async request({ method, params }) {
|
69
|
+
const { result } = await _chunkA3PVAH22js.rpc.http(url_, {
|
70
|
+
body: {
|
71
|
+
method,
|
72
|
+
params
|
73
|
+
}
|
74
|
+
});
|
75
|
+
return result;
|
76
|
+
},
|
77
|
+
type: "http"
|
78
|
+
},
|
79
|
+
{
|
80
|
+
url
|
81
|
+
}
|
82
|
+
);
|
83
|
+
};
|
84
|
+
}
|
85
|
+
|
86
|
+
// src/clients/transports/webSocket.ts
|
87
|
+
function webSocket(url, {
|
88
|
+
key = "webSocket",
|
89
|
+
name = "WebSocket JSON-RPC"
|
90
|
+
} = {}) {
|
91
|
+
return ({ chain }) => {
|
92
|
+
const url_ = url || _optionalChain([chain, 'optionalAccess', _5 => _5.rpcUrls, 'access', _6 => _6.default, 'access', _7 => _7.webSocket, 'optionalAccess', _8 => _8[0]]);
|
93
|
+
if (!url_)
|
94
|
+
throw new (0, _chunkA3PVAH22js.UrlRequiredError)();
|
95
|
+
return createTransport(
|
96
|
+
{
|
97
|
+
key,
|
98
|
+
name,
|
99
|
+
async request({ method, params }) {
|
100
|
+
const socket = await _chunkA3PVAH22js.getSocket.call(void 0, url_);
|
101
|
+
const { result } = await _chunkA3PVAH22js.rpc.webSocketAsync(socket, {
|
102
|
+
body: { method, params }
|
103
|
+
});
|
104
|
+
return result;
|
105
|
+
},
|
106
|
+
type: "webSocket"
|
107
|
+
},
|
108
|
+
{
|
109
|
+
getSocket() {
|
110
|
+
return _chunkA3PVAH22js.getSocket.call(void 0, url_);
|
111
|
+
},
|
112
|
+
async subscribe({ params, onData, onError }) {
|
113
|
+
const socket = await _chunkA3PVAH22js.getSocket.call(void 0, url_);
|
114
|
+
const { result: subscriptionId } = await new Promise(
|
115
|
+
(resolve, reject) => _chunkA3PVAH22js.rpc.webSocket(socket, {
|
116
|
+
body: {
|
117
|
+
method: "eth_subscribe",
|
118
|
+
params
|
119
|
+
},
|
120
|
+
onData: (data) => {
|
121
|
+
if (typeof data.id === "number") {
|
122
|
+
resolve(data);
|
123
|
+
return;
|
124
|
+
}
|
125
|
+
onData(data);
|
126
|
+
},
|
127
|
+
onError: (error) => {
|
128
|
+
reject(error);
|
129
|
+
_optionalChain([onError, 'optionalCall', _9 => _9(error)]);
|
130
|
+
}
|
131
|
+
})
|
132
|
+
);
|
133
|
+
return {
|
134
|
+
subscriptionId,
|
135
|
+
async unsubscribe() {
|
136
|
+
return new Promise(
|
137
|
+
(resolve, reject) => _chunkA3PVAH22js.rpc.webSocket(socket, {
|
138
|
+
body: {
|
139
|
+
method: "eth_unsubscribe",
|
140
|
+
params: [subscriptionId]
|
141
|
+
},
|
142
|
+
onData: resolve,
|
143
|
+
onError: reject
|
144
|
+
})
|
145
|
+
);
|
146
|
+
}
|
147
|
+
};
|
148
|
+
}
|
149
|
+
}
|
150
|
+
);
|
151
|
+
};
|
152
|
+
}
|
153
|
+
|
154
|
+
// src/utils/uid.ts
|
155
|
+
var size = 256;
|
156
|
+
var index = size;
|
157
|
+
var buffer;
|
158
|
+
function uid(length = 11) {
|
159
|
+
if (!buffer || index + length > size * 2) {
|
160
|
+
buffer = "";
|
161
|
+
index = 0;
|
162
|
+
for (let i = 0; i < size; i++) {
|
163
|
+
buffer += (256 + Math.random() * 256 | 0).toString(16).substring(1);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
return buffer.substring(index, index++ + length);
|
167
|
+
}
|
168
|
+
|
169
|
+
// src/clients/createClient.ts
|
170
|
+
function createClient({
|
171
|
+
chain,
|
172
|
+
key = "base",
|
173
|
+
name = "Base Client",
|
174
|
+
pollingInterval = 4e3,
|
175
|
+
transport,
|
176
|
+
type = "base"
|
177
|
+
}) {
|
178
|
+
const { config, value } = transport({ chain });
|
179
|
+
return {
|
180
|
+
chain,
|
181
|
+
key,
|
182
|
+
name,
|
183
|
+
pollingInterval,
|
184
|
+
request: _chunkA3PVAH22js.buildRequest.call(void 0, config.request),
|
185
|
+
transport: { ...config, ...value },
|
186
|
+
type,
|
187
|
+
uid: uid()
|
188
|
+
};
|
189
|
+
}
|
190
|
+
|
191
|
+
// src/clients/createPublicClient.ts
|
192
|
+
function createPublicClient({
|
193
|
+
chain,
|
194
|
+
key = "public",
|
195
|
+
name = "Public Client",
|
196
|
+
transport,
|
197
|
+
pollingInterval
|
198
|
+
}) {
|
199
|
+
chain;
|
200
|
+
return createClient({
|
201
|
+
chain,
|
202
|
+
key,
|
203
|
+
name,
|
204
|
+
pollingInterval,
|
205
|
+
transport,
|
206
|
+
type: "publicClient"
|
207
|
+
});
|
208
|
+
}
|
209
|
+
|
210
|
+
// src/clients/createTestClient.ts
|
211
|
+
function createTestClient({
|
212
|
+
chain,
|
213
|
+
key = "test",
|
214
|
+
name = "Test Client",
|
215
|
+
mode,
|
216
|
+
pollingInterval,
|
217
|
+
transport
|
218
|
+
}) {
|
219
|
+
return {
|
220
|
+
...createClient({
|
221
|
+
chain,
|
222
|
+
key,
|
223
|
+
name,
|
224
|
+
pollingInterval,
|
225
|
+
transport,
|
226
|
+
type: "testClient"
|
227
|
+
}),
|
228
|
+
mode
|
229
|
+
};
|
230
|
+
}
|
231
|
+
|
232
|
+
// src/clients/createWalletClient.ts
|
233
|
+
function createWalletClient({
|
234
|
+
transport,
|
235
|
+
key = "wallet",
|
236
|
+
name = "Wallet Client",
|
237
|
+
pollingInterval
|
238
|
+
}) {
|
239
|
+
return createClient({
|
240
|
+
key,
|
241
|
+
name,
|
242
|
+
pollingInterval,
|
243
|
+
transport,
|
244
|
+
type: "walletClient"
|
245
|
+
});
|
246
|
+
}
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
exports.createTransport = createTransport; exports.custom = custom; exports.fallback = fallback; exports.http = http; exports.webSocket = webSocket; exports.createClient = createClient; exports.createPublicClient = createPublicClient; exports.createTestClient = createTestClient; exports.createWalletClient = createWalletClient;
|
@@ -8,8 +8,8 @@ var __publicField = (obj, key, value) => {
|
|
8
8
|
// package.json
|
9
9
|
var package_default = {
|
10
10
|
name: "viem",
|
11
|
-
description: "TypeScript
|
12
|
-
version: "0.0.1-alpha.
|
11
|
+
description: "TypeScript Interface for Ethereum",
|
12
|
+
version: "0.0.1-alpha.12",
|
13
13
|
scripts: {
|
14
14
|
anvil: "source .env && anvil --fork-url $VITE_ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
|
15
15
|
bench: "vitest bench --no-threads",
|
@@ -27,10 +27,12 @@ var package_default = {
|
|
27
27
|
"playground:benchmark": "pnpm --filter playground-benchmark dev",
|
28
28
|
postinstall: "pnpm dev",
|
29
29
|
preinstall: "npx only-allow pnpm",
|
30
|
+
prepublishOnly: "pnpm ts-node scripts/generate-package-json.ts",
|
30
31
|
prepare: "npx simple-git-hooks",
|
31
32
|
test: "vitest dev --coverage --no-threads",
|
32
33
|
"test:ci": "CI=true vitest --coverage --no-threads",
|
33
34
|
"test:ui": "vitest dev --ui --no-threads",
|
35
|
+
"ts-node": "node --loader esbuild-register/loader -r esbuild-register",
|
34
36
|
typecheck: "tsc --noEmit"
|
35
37
|
},
|
36
38
|
files: [
|
@@ -45,37 +47,43 @@ var package_default = {
|
|
45
47
|
exports: {
|
46
48
|
".": {
|
47
49
|
types: "./dist/index.d.ts",
|
50
|
+
module: "./dist/index.mjs",
|
48
51
|
default: "./dist/index.js"
|
49
52
|
},
|
50
53
|
"./actions": {
|
51
54
|
types: "./dist/actions/index.d.ts",
|
55
|
+
module: "./dist/actions/index.mjs",
|
52
56
|
default: "./dist/actions/index.js"
|
53
57
|
},
|
54
58
|
"./chains": {
|
55
59
|
types: "./dist/chains.d.ts",
|
60
|
+
module: "./dist/chains.mjs",
|
56
61
|
default: "./dist/chains.js"
|
57
62
|
},
|
58
63
|
"./clients": {
|
59
64
|
types: "./dist/clients/index.d.ts",
|
65
|
+
module: "./dist/clients/index.mjs",
|
60
66
|
default: "./dist/clients/index.js"
|
61
67
|
},
|
62
68
|
"./utils": {
|
63
69
|
types: "./dist/utils/index.d.ts",
|
70
|
+
module: "./dist/utils/index.mjs",
|
64
71
|
default: "./dist/utils/index.js"
|
65
72
|
},
|
66
73
|
"./window": {
|
67
74
|
types: "./dist/window.d.ts",
|
75
|
+
module: "./dist/window.mjs",
|
68
76
|
default: "./dist/window.js"
|
69
77
|
},
|
70
78
|
"./package.json": "./package.json"
|
71
79
|
},
|
72
|
-
type: "module",
|
73
80
|
main: "dist/index.js",
|
81
|
+
module: "dist/index.mjs",
|
74
82
|
types: "dist/index.d.ts",
|
75
83
|
sideEffects: false,
|
76
84
|
dependencies: {
|
77
85
|
"@noble/hashes": "^1.1.2",
|
78
|
-
"@wagmi/chains": "
|
86
|
+
"@wagmi/chains": "0.0.0-20230201210619",
|
79
87
|
abitype: "^0.2.5"
|
80
88
|
},
|
81
89
|
devDependencies: {
|
@@ -119,9 +127,6 @@ var package_default = {
|
|
119
127
|
"wallet",
|
120
128
|
"web3"
|
121
129
|
],
|
122
|
-
engines: {
|
123
|
-
node: ">=18"
|
124
|
-
},
|
125
130
|
"simple-git-hooks": {
|
126
131
|
"pre-commit": "pnpm format & pnpm lint:fix"
|
127
132
|
},
|