viem 0.0.1-alpha.10 → 0.0.1-alpha.11
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-35OJIFIW.js +2619 -0
- package/dist/{chunk-6GAKRM5P.js → chunk-DY4MSK2M.mjs} +13 -7
- package/dist/chunk-GXCYE2PD.js +258 -0
- package/dist/{chunk-NMN4TFDP.js → chunk-JXGK2LUM.mjs} +1 -1
- package/dist/chunk-PEAG3TIC.js +1084 -0
- package/dist/{chunk-3TSTZHVO.js → chunk-TP542F7H.mjs} +1 -1
- 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 +9 -65
- package/utils/package.json +1 -1
- package/window/package.json +1 -1
@@ -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.11",
|
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",
|
@@ -26,11 +26,14 @@ var package_default = {
|
|
26
26
|
playground: "pnpm --filter playground-dev dev",
|
27
27
|
"playground:benchmark": "pnpm --filter playground-benchmark dev",
|
28
28
|
postinstall: "pnpm dev",
|
29
|
+
postpublish: "pnpm ts-node scripts/restore-package-json.ts",
|
29
30
|
preinstall: "npx only-allow pnpm",
|
31
|
+
prepublishOnly: "pnpm ts-node scripts/generate-package-json.ts",
|
30
32
|
prepare: "npx simple-git-hooks",
|
31
33
|
test: "vitest dev --coverage --no-threads",
|
32
34
|
"test:ci": "CI=true vitest --coverage --no-threads",
|
33
35
|
"test:ui": "vitest dev --ui --no-threads",
|
36
|
+
"ts-node": "node --loader esbuild-register/loader -r esbuild-register",
|
34
37
|
typecheck: "tsc --noEmit"
|
35
38
|
},
|
36
39
|
files: [
|
@@ -45,37 +48,43 @@ var package_default = {
|
|
45
48
|
exports: {
|
46
49
|
".": {
|
47
50
|
types: "./dist/index.d.ts",
|
51
|
+
module: "./dist/index.mjs",
|
48
52
|
default: "./dist/index.js"
|
49
53
|
},
|
50
54
|
"./actions": {
|
51
55
|
types: "./dist/actions/index.d.ts",
|
56
|
+
module: "./dist/actions/index.mjs",
|
52
57
|
default: "./dist/actions/index.js"
|
53
58
|
},
|
54
59
|
"./chains": {
|
55
60
|
types: "./dist/chains.d.ts",
|
61
|
+
module: "./dist/chains.mjs",
|
56
62
|
default: "./dist/chains.js"
|
57
63
|
},
|
58
64
|
"./clients": {
|
59
65
|
types: "./dist/clients/index.d.ts",
|
66
|
+
module: "./dist/clients/index.mjs",
|
60
67
|
default: "./dist/clients/index.js"
|
61
68
|
},
|
62
69
|
"./utils": {
|
63
70
|
types: "./dist/utils/index.d.ts",
|
71
|
+
module: "./dist/utils/index.mjs",
|
64
72
|
default: "./dist/utils/index.js"
|
65
73
|
},
|
66
74
|
"./window": {
|
67
75
|
types: "./dist/window.d.ts",
|
76
|
+
module: "./dist/window.mjs",
|
68
77
|
default: "./dist/window.js"
|
69
78
|
},
|
70
79
|
"./package.json": "./package.json"
|
71
80
|
},
|
72
|
-
type: "module",
|
73
81
|
main: "dist/index.js",
|
82
|
+
module: "dist/index.mjs",
|
74
83
|
types: "dist/index.d.ts",
|
75
84
|
sideEffects: false,
|
76
85
|
dependencies: {
|
77
86
|
"@noble/hashes": "^1.1.2",
|
78
|
-
"@wagmi/chains": "
|
87
|
+
"@wagmi/chains": "0.0.0-20230201210619",
|
79
88
|
abitype: "^0.2.5"
|
80
89
|
},
|
81
90
|
devDependencies: {
|
@@ -119,9 +128,6 @@ var package_default = {
|
|
119
128
|
"wallet",
|
120
129
|
"web3"
|
121
130
|
],
|
122
|
-
engines: {
|
123
|
-
node: ">=18"
|
124
|
-
},
|
125
131
|
"simple-git-hooks": {
|
126
132
|
"pre-commit": "pnpm format & pnpm lint:fix"
|
127
133
|
},
|
@@ -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 _chunk35OJIFIWjs = require('./chunk-35OJIFIW.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, _chunk35OJIFIWjs.UrlRequiredError)();
|
64
|
+
return createTransport(
|
65
|
+
{
|
66
|
+
key,
|
67
|
+
name,
|
68
|
+
async request({ method, params }) {
|
69
|
+
const { result } = await _chunk35OJIFIWjs.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, _chunk35OJIFIWjs.UrlRequiredError)();
|
95
|
+
return createTransport(
|
96
|
+
{
|
97
|
+
key,
|
98
|
+
name,
|
99
|
+
async request({ method, params }) {
|
100
|
+
const socket = await _chunk35OJIFIWjs.getSocket.call(void 0, url_);
|
101
|
+
const { result } = await _chunk35OJIFIWjs.rpc.webSocketAsync(socket, {
|
102
|
+
body: { method, params }
|
103
|
+
});
|
104
|
+
return result;
|
105
|
+
},
|
106
|
+
type: "webSocket"
|
107
|
+
},
|
108
|
+
{
|
109
|
+
getSocket() {
|
110
|
+
return _chunk35OJIFIWjs.getSocket.call(void 0, url_);
|
111
|
+
},
|
112
|
+
async subscribe({ params, onData, onError }) {
|
113
|
+
const socket = await _chunk35OJIFIWjs.getSocket.call(void 0, url_);
|
114
|
+
const { result: subscriptionId } = await new Promise(
|
115
|
+
(resolve, reject) => _chunk35OJIFIWjs.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) => _chunk35OJIFIWjs.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: _chunk35OJIFIWjs.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;
|