@asyncswap/eth-rpc 0.3.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,56 @@
1
+ # @asyncswap/eth-rpc
2
+
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d2562a2: implemented execution apis methods
8
+
9
+ eth/transation
10
+
11
+ - eth_getTransactionByHash
12
+ - eth_getTransactionByBlockHashAndIndex
13
+ - eth_getTransactionReceipt
14
+
15
+ eth/submit
16
+
17
+ - eth_sendTransaction
18
+ - eth_sendRawTransaction
19
+
20
+ eth/state
21
+
22
+ - eth_getBalance
23
+ - eth_getStorageAt
24
+ - eth_getTransactionCount
25
+ - eth_getCode
26
+ - eth_getProof
27
+
28
+ eth/sign
29
+
30
+ - eth_sign
31
+ - eth_signTransaction
32
+
33
+ eth/filter
34
+
35
+ - eth_newFilter
36
+ - eth_newBlockFilter
37
+ - eth_newPendingTransactionFilter
38
+ - eth_uninstallFilter
39
+ - eth_getFilterChanges
40
+ - eth_getFilterLogs
41
+ - eth_getLogs
42
+
43
+ - dc1718c: refactor of types dir to global types
44
+
45
+ ### Patch Changes
46
+
47
+ - e3ac747: patch
48
+ - a9d1a29: add biome formatting
49
+ - Updated dependencies [dc1718c]
50
+ - Updated dependencies [e15733c]
51
+ - Updated dependencies [e3ac747]
52
+ - Updated dependencies [abddcdc]
53
+ - Updated dependencies [00ba692]
54
+ - Updated dependencies [07dc4e5]
55
+ - Updated dependencies [ded3e6b]
56
+ - @asyncswap/jsonrpc@0.3.0
package/CLAUDE.md ADDED
@@ -0,0 +1,111 @@
1
+ ---
2
+ description: Use Bun instead of Node.js, npm, pnpm, or vite.
3
+ globs: "*.ts, *.tsx, *.html, *.css, *.js, *.jsx, package.json"
4
+ alwaysApply: false
5
+ ---
6
+
7
+ Default to using Bun instead of Node.js.
8
+
9
+ - Use `bun <file>` instead of `node <file>` or `ts-node <file>`
10
+ - Use `bun test` instead of `jest` or `vitest`
11
+ - Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
12
+ - Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
13
+ - Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
14
+ - Bun automatically loads .env, so don't use dotenv.
15
+
16
+ ## APIs
17
+
18
+ - `Bun.serve()` supports WebSockets, HTTPS, and routes. Don't use `express`.
19
+ - `bun:sqlite` for SQLite. Don't use `better-sqlite3`.
20
+ - `Bun.redis` for Redis. Don't use `ioredis`.
21
+ - `Bun.sql` for Postgres. Don't use `pg` or `postgres.js`.
22
+ - `WebSocket` is built-in. Don't use `ws`.
23
+ - Prefer `Bun.file` over `node:fs`'s readFile/writeFile
24
+ - Bun.$`ls` instead of execa.
25
+
26
+ ## Testing
27
+
28
+ Use `bun test` to run tests.
29
+
30
+ ```ts#index.test.ts
31
+ import { test, expect } from "bun:test";
32
+
33
+ test("hello world", () => {
34
+ expect(1).toBe(1);
35
+ });
36
+ ```
37
+
38
+ ## Frontend
39
+
40
+ Use HTML imports with `Bun.serve()`. Don't use `vite`. HTML imports fully support React, CSS, Tailwind.
41
+
42
+ Server:
43
+
44
+ ```ts#index.ts
45
+ import index from "./index.html"
46
+
47
+ Bun.serve({
48
+ routes: {
49
+ "/": index,
50
+ "/api/users/:id": {
51
+ GET: (req) => {
52
+ return new Response(JSON.stringify({ id: req.params.id }));
53
+ },
54
+ },
55
+ },
56
+ // optional websocket support
57
+ websocket: {
58
+ open: (ws) => {
59
+ ws.send("Hello, world!");
60
+ },
61
+ message: (ws, message) => {
62
+ ws.send(message);
63
+ },
64
+ close: (ws) => {
65
+ // handle close
66
+ }
67
+ },
68
+ development: {
69
+ hmr: true,
70
+ console: true,
71
+ }
72
+ })
73
+ ```
74
+
75
+ HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. `<link>` tags can point to stylesheets and Bun's CSS bundler will bundle.
76
+
77
+ ```html#index.html
78
+ <html>
79
+ <body>
80
+ <h1>Hello, world!</h1>
81
+ <script type="module" src="./frontend.tsx"></script>
82
+ </body>
83
+ </html>
84
+ ```
85
+
86
+ With the following `frontend.tsx`:
87
+
88
+ ```tsx#frontend.tsx
89
+ import React from "react";
90
+
91
+ // import .css files directly and it works
92
+ import './index.css';
93
+
94
+ import { createRoot } from "react-dom/client";
95
+
96
+ const root = createRoot(document.body);
97
+
98
+ export default function Frontend() {
99
+ return <h1>Hello, world!</h1>;
100
+ }
101
+
102
+ root.render(<Frontend />);
103
+ ```
104
+
105
+ Then, run index.ts
106
+
107
+ ```sh
108
+ bun --hot ./index.ts
109
+ ```
110
+
111
+ For more information, read the Bun API docs in `node_modules/bun-types/docs/**.md`.
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # eth-rpc
2
+
3
+ ## `@asyncswap/eth-rpc`
4
+
5
+ A complete library for ethereum rpc clients apis.
6
+
7
+ ```sh
8
+ bun add @asyncswap/eth-rpc
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Ethereum Execution Client Api
14
+
15
+ ```ts
16
+ import { EthExecutionClient } from '@asyncswap/eth-rpc';
17
+
18
+ const url = 'http://localhost:8545'
19
+ const eth = new EthExecutionClient(url);
20
+
21
+ const balance = await eth.eth_getBalance(
22
+ "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
23
+ "latest"
24
+ );
25
+ console.log('Balance:', balance);
26
+ ```
27
+
28
+ ### Ethereum Engine Api
29
+
30
+ ```ts
31
+ import { EngineExecutionClient } from "@asyncswap/eth-rpc";
32
+
33
+ const engineUrl = "https://localhost:8551";
34
+ const engine = new EngineExecutionClient(engineUrl, process.env.JWT_TOKEN!);
35
+ const payload = engine.engine_getPayloadV1("0x1");
36
+
37
+ console.log(payload);
38
+ ```
package/example.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { EthExecutionClient } from "./src";
2
+
3
+ const url = "http://localhost:8545";
4
+ const eth = new EthExecutionClient(url);
5
+
6
+ const balance = await eth.eth_getBalance(
7
+ "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
8
+ "latest",
9
+ );
10
+ console.log("Balance:", balance);
11
+ eth.eth_getTransactionCount("0x34", "safe");
12
+
13
+ import { EngineExecutionClient } from "./src";
14
+
15
+ const engineUrl = "https://localhost:8551";
16
+ const engine = new EngineExecutionClient(engineUrl, process.env.JWT_TOKEN!);
17
+ const payload = engine.engine_getPayloadV1("0x1");
18
+
19
+ console.log(payload);
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@asyncswap/eth-rpc",
3
+ "description": "A library for ethereum execution clients apis.",
4
+ "author": "Meek Msaki",
5
+ "version": "0.3.0",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.mjs",
10
+ "types": "dist/index.d.ts",
11
+ "keywords": [
12
+ "eth",
13
+ "rpc",
14
+ "ethereum",
15
+ "engine-api",
16
+ "execution-apis"
17
+ ],
18
+ "homepage": "https://github.com/asyncswap/eth-libs/tree/main/packages/eth-rpc",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/asyncswap/eth-libs.git",
22
+ "directory": "packages/eth-rpc"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/asyncswap/eth-libs/issues"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public",
29
+ "directory": "dist"
30
+ },
31
+ "scripts": {
32
+ "build": "tsc -p tsconfig.json",
33
+ "publish": "bun run build && bun publish --access public",
34
+ "format": "bun biome format --write"
35
+ },
36
+ "devDependencies": {
37
+ "@biomejs/biome": "2.3.11",
38
+ "@types/bun": "latest"
39
+ },
40
+ "peerDependencies": {
41
+ "typescript": "^5"
42
+ },
43
+ "dependencies": {
44
+ "@asyncswap/jsonrpc": "^0.3.0"
45
+ }
46
+ }
@@ -0,0 +1,254 @@
1
+ import { initializeRpcClient, JsonRpcClient } from "@asyncswap/jsonrpc";
2
+
3
+ export class EngineExecutionClient {
4
+ private client: JsonRpcClient;
5
+
6
+ constructor(url: string, jwt_token: string) {
7
+ this.client = initializeRpcClient(url, jwt_token);
8
+ }
9
+
10
+ // eth/transaction
11
+ async eth_sendRawTransaction(transaction: Bytes): Promise<Hash32> {
12
+ return await this.client.call(EngineMethods.eth_sendRawTransaction, [
13
+ transaction,
14
+ ]);
15
+ }
16
+ // eth/state
17
+ async eth_getCode(
18
+ address: Address,
19
+ block: BlockNumberOrTagOrHash,
20
+ ): Promise<Bytes> {
21
+ return await this.client.call(EngineMethods.eth_getCode, [address, block]);
22
+ }
23
+ async eth_getLogs(filter: Filter): Promise<FilterResults> {
24
+ return await this.client.call(EngineMethods.eth_getLogs, [filter]);
25
+ }
26
+ // eth/execute
27
+ async eth_call(
28
+ transaction: GenericTransaction,
29
+ block: BlockNumberOrTagOrHash,
30
+ ): Promise<Bytes> {
31
+ return this.client.call(EngineMethods.eth_call, [transaction, block]);
32
+ }
33
+ // eth/client
34
+ async eth_chainId(): Promise<Uint> {
35
+ return await this.client.call(EngineMethods.eth_chainId, []);
36
+ }
37
+ async eth_syncing(): Promise<SyncingStatus> {
38
+ return await this.client.call(EngineMethods.eth_syncing, []);
39
+ }
40
+ async eth_blockNumber(): Promise<Uint> {
41
+ return await this.client.call(EngineMethods.eth_blockNumber, []);
42
+ }
43
+ // eth/block
44
+ async eth_getBlockByHash(
45
+ blockHash: Hash32,
46
+ hydratedTransactions: boolean,
47
+ ): Promise<NotFound | Block> {
48
+ return await this.client.call(EngineMethods.eth_getBlockByHash, [
49
+ blockHash,
50
+ hydratedTransactions,
51
+ ]);
52
+ }
53
+ async eth_getBlockByNumber(
54
+ block: BlockNumberOrTag,
55
+ hydratedTransactions: boolean,
56
+ ): Promise<NotFound | Block> {
57
+ return await this.client.call(EngineMethods.eth_getBlockByNumber, [
58
+ block,
59
+ hydratedTransactions,
60
+ ]);
61
+ }
62
+ // engine/blob
63
+ async engine_getBlobsV1(
64
+ blobedVersionedHashes: Hash32[],
65
+ ): Promise<BlobAndProofV1[]> {
66
+ return await this.client.call(EngineMethods.engine_getBlobsV1, [
67
+ blobedVersionedHashes,
68
+ ]);
69
+ }
70
+ async engine_getBlobsV2(
71
+ blobedVersionedHashes: Hash32[],
72
+ ): Promise<BlobAndProofV2[]> {
73
+ return await this.client.call(EngineMethods.engine_getBlobsV2, [
74
+ blobedVersionedHashes,
75
+ ]);
76
+ }
77
+ async engine_getBlobsV3(
78
+ blobedVersionedHashes: Hash32[],
79
+ ): Promise<Array<BlobAndProofV2[] | null> | null> {
80
+ return await this.client.call(EngineMethods.engine_getBlobsV3, [
81
+ blobedVersionedHashes,
82
+ ]);
83
+ }
84
+ // engine/capabilities
85
+ async engine_exchangeCapabilities(
86
+ consensusClientMethods: string[],
87
+ ): Promise<string[]> {
88
+ return await this.client.call(EngineMethods.engine_exchangeCapabilities, [
89
+ consensusClientMethods,
90
+ ]);
91
+ }
92
+ // engine/forkchoice
93
+ async engine_forkchoiceUpdatedV1(
94
+ forkchoiceState: ForkchoiceStateV1,
95
+ payloadAttribute: PayloadAttributesV1,
96
+ ): Promise<ForkchoiceUpdatedResponseV1> {
97
+ return await this.client.call(EngineMethods.engine_forkchoiceUpdatedV1, [
98
+ forkchoiceState,
99
+ payloadAttribute,
100
+ ]);
101
+ }
102
+ async engine_forkchoiceUpdatedV2(
103
+ forkchoiceState: ForkchoiceStateV1,
104
+ payloadAttribute: PayloadAttributesV2,
105
+ ): Promise<ForkchoiceUpdatedResponseV1> {
106
+ return await this.client.call(EngineMethods.engine_forkchoiceUpdatedV2, [
107
+ forkchoiceState,
108
+ payloadAttribute,
109
+ ]);
110
+ }
111
+ async engine_forkchoiceUpdatedV3(
112
+ forkchoiceState: ForkchoiceStateV1,
113
+ payloadAttribute: PayloadAttributesV3,
114
+ ): Promise<ForkchoiceUpdatedResponseV1> {
115
+ return await this.client.call(EngineMethods.engine_forkchoiceUpdatedV3, [
116
+ forkchoiceState,
117
+ payloadAttribute,
118
+ ]);
119
+ }
120
+ // engine/payload
121
+ async engine_newPayloadV1(
122
+ executionPayload: ExecutionPayloadV1,
123
+ ): Promise<PayloadStatusV1> {
124
+ return await this.client.call(EngineMethods.engine_newPayloadV1, [
125
+ executionPayload,
126
+ ]);
127
+ }
128
+ async engine_newPayloadV2(
129
+ executionPayload: ExecutionPayloadV1 | ExecutionPayloadV2,
130
+ ): Promise<PayloadStatusNoInvalidBlockHash> {
131
+ return await this.client.call(EngineMethods.engine_newPayloadV2, [
132
+ executionPayload,
133
+ ]);
134
+ }
135
+ async engine_newPayloadV3(
136
+ executionPayload: ExecutionPayloadV3,
137
+ expectedBlobVersionedHashes: Hash32[],
138
+ rootOfTheParentBeaconBlock: Hash32,
139
+ ): Promise<PayloadStatusNoInvalidBlockHash> {
140
+ return await this.client.call(EngineMethods.engine_newPayloadV3, [
141
+ executionPayload,
142
+ expectedBlobVersionedHashes,
143
+ rootOfTheParentBeaconBlock,
144
+ ]);
145
+ }
146
+ async engine_newPayloadV4(
147
+ executionPayload: ExecutionPayloadV3,
148
+ expectedBlobVersionedHashes: Hash32[],
149
+ rootOfTheParentBeaconBlock: Hash32,
150
+ executionRequests: Bytes[],
151
+ ): Promise<PayloadStatusNoInvalidBlockHash> {
152
+ return await this.client.call(EngineMethods.engine_newPayloadV4, [
153
+ executionPayload,
154
+ expectedBlobVersionedHashes,
155
+ rootOfTheParentBeaconBlock,
156
+ executionRequests,
157
+ ]);
158
+ }
159
+ async engine_getPayloadV1(payloadId: Bytes8): Promise<ExecutionPayloadV1> {
160
+ return await this.client.call(EngineMethods.engine_getPayloadV1, [
161
+ payloadId,
162
+ ]);
163
+ }
164
+ async engine_getPayloadV2(payloadId: Bytes8): Promise<{
165
+ executionPayload: ExecutionPayloadV1 | ExecutionPayloadV2;
166
+ blockValue: Uint256;
167
+ }> {
168
+ return await this.client.call(EngineMethods.engine_getPayloadV2, [
169
+ payloadId,
170
+ ]);
171
+ }
172
+ async engine_getPayloadV3(payloadId: Bytes8): Promise<{
173
+ executionPayload: ExecutionPayloadV3;
174
+ blockValue: Uint256;
175
+ blobsBundle: BlobsBundleV1;
176
+ shouldOverrideBuilder: boolean;
177
+ }> {
178
+ return await this.client.call(EngineMethods.engine_getPayloadV3, [
179
+ payloadId,
180
+ ]);
181
+ }
182
+ async engine_getPayloadV4(payloadId: Bytes8): Promise<{
183
+ executionPayload: ExecutionPayloadV3;
184
+ blockValue: Uint256;
185
+ blobsBundle: BlobsBundleV1;
186
+ shouldOverrideBuilder: boolean;
187
+ executionRequests: Bytes[];
188
+ }> {
189
+ return await this.client.call(EngineMethods.engine_getPayloadV4, [
190
+ payloadId,
191
+ ]);
192
+ }
193
+ async engine_getPayloadV5(payloadId: Bytes8): Promise<{
194
+ executionPayload: ExecutionPayloadV3;
195
+ blockValue: Uint256;
196
+ blobsBundle: BlobsBundleV2;
197
+ shouldOverrideBuilder: boolean;
198
+ executionRequests: Bytes[];
199
+ }> {
200
+ return await this.client.call(EngineMethods.engine_getPayloadV5, [
201
+ payloadId,
202
+ ]);
203
+ }
204
+ async engine_getPayloadBodiesByHashV1(
205
+ arrayOfBlockHashes: Hash32[],
206
+ ): Promise<ExecutionPayloadBodyV1[]> {
207
+ return await this.client.call(
208
+ EngineMethods.engine_getPayloadBodiesByHashV1,
209
+ [arrayOfBlockHashes],
210
+ );
211
+ }
212
+ async engine_getPayloadBodiesByRangeV1(
213
+ startingBlockNumber: Uint64,
214
+ numberOfBlocksToReturn: Uint64,
215
+ ): Promise<ExecutionPayloadBodyV1[]> {
216
+ return await this.client.call(
217
+ EngineMethods.engine_getPayloadBodiesByRangeV1,
218
+ [startingBlockNumber, numberOfBlocksToReturn],
219
+ );
220
+ }
221
+ async engine_newPayloadV5(
222
+ executionPayload: ExecutionPayloadV4,
223
+ expectedBlobVersionedHashes: Hash32[],
224
+ parentBeaconBlockRoot: Hash32,
225
+ executionRequests: Bytes[],
226
+ ): Promise<PayloadStatusNoInvalidBlockHash> {
227
+ return await this.client.call(EngineMethods.engine_newPayloadV5, [
228
+ executionPayload,
229
+ expectedBlobVersionedHashes,
230
+ parentBeaconBlockRoot,
231
+ executionRequests,
232
+ ]);
233
+ }
234
+ async engine_getPayloadV6(payloadId: Bytes8): Promise<{
235
+ executionPayload: ExecutionPayloadV4;
236
+ blockValue: Uint256;
237
+ blobsBundle: BlobsBundleV2;
238
+ shouldOverrideBuilder: boolean;
239
+ executionRequests: Bytes[];
240
+ }> {
241
+ return await this.client.call(EngineMethods.engine_getPayloadV6, [
242
+ payloadId,
243
+ ]);
244
+ }
245
+ // engine/transition-configuration
246
+ async engine_exchangeTransitionConfigurationV1(
247
+ consensusClientConfiguration: TransitionConfigurationV1,
248
+ ): Promise<TransitionConfigurationV1> {
249
+ return await this.client.call(
250
+ EngineMethods.engine_exchangeTransitionConfigurationV1,
251
+ [consensusClientConfiguration],
252
+ );
253
+ }
254
+ }