@asyncswap/eth-rpc 0.4.1 → 0.4.3

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 CHANGED
@@ -1,12 +1,28 @@
1
1
  # @asyncswap/eth-rpc
2
2
 
3
- ## 0.5.1
3
+ ## 0.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 7ae86a0: new refactor on methods as data
8
+ - Updated dependencies [40a79dc]
9
+ - @asyncswap/jsonrpc@0.4.3
10
+
11
+ ## 0.4.2
12
+
13
+ ### Patch Changes
14
+
15
+ - 9512db5: update documentation
16
+ - Updated dependencies [9512db5]
17
+ - @asyncswap/jsonrpc@0.4.2
18
+
19
+ ## 0.4.1
4
20
 
5
21
  ### Patch Changes
6
22
 
7
23
  - 2598f09: updates docs
8
24
 
9
- ## 0.5.0
25
+ ## 0.4.0
10
26
 
11
27
  ### Minor Changes
12
28
 
package/README.md CHANGED
@@ -1,18 +1,18 @@
1
1
  # eth-rpc
2
2
 
3
- ## `@asyncswap/eth-rpc`
3
+ A comprehensive TypeScript client for Ethereum execution and engine APIs.
4
4
 
5
- A complete library for ethereum rpc clients apis.
5
+ ## Installation
6
6
 
7
- ```sh
7
+ ```bash
8
8
  bun add @asyncswap/eth-rpc
9
9
  ```
10
10
 
11
- ## Usage
11
+ ## Quick Start
12
12
 
13
- ### Ethereum Execution Client Api
13
+ ### Execution API Client
14
14
 
15
- ```ts
15
+ ```typescript
16
16
  import { EthExecutionClient } from '@asyncswap/eth-rpc';
17
17
 
18
18
  const url = 'http://localhost:8545'
@@ -24,7 +24,20 @@ const balance = await eth.eth_getBalance(
24
24
  );
25
25
  console.log("Balance:", balance);
26
26
  eth.eth_getTransactionCount("0x34", "safe");
27
+ ```
28
+
29
+ ### Flashbots Client API
30
+
31
+ ```ts
32
+ import { FlashbotsClient } from "@asyncswap/eth-rpc";
27
33
 
34
+ const rpc = "https://relay.flashbots.net";
35
+ const client = new FlashbotsClient(rpc);
36
+ ```
37
+
38
+ ### Engine API Client
39
+
40
+ ```typescript
28
41
  import { EngineExecutionClient } from '@asyncswap/eth-rpc';
29
42
 
30
43
  const engineUrl = 'https://localhost:8551';
@@ -33,115 +46,33 @@ const payload = engine.engine_getPayloadV1("0x1");
33
46
 
34
47
  console.log(payload);
35
48
 
36
- import { EthFlashbotsClient } from '@asyncswap/eth-rpc';
49
+ import { FlashbotsClient } from '@asyncswap/eth-rpc';
37
50
 
38
51
  const rpc = 'https://relay.flashbots.net';
39
- const client = new EthFlashbotsClient(rpc);
52
+ const client = new FlashbotsClient(rpc);
40
53
  ```
41
54
 
42
- ### Client RPC Methods implemented
43
-
44
- - [x] eth/transaction
45
- - [x] eth_getTransactionByHash
46
- - [x] eth_getTransactionByBlockHashAndIndex
47
- - [x] eth_getTransactionReceipt
48
- - [x] eth/submit
49
- - [x] eth_sendTransaction
50
- - [x] eth_sendRawTransaction
51
- - [x] eth/state
52
- - [x] eth_getBalance
53
- - [x] eth_getStorageAt
54
- - [x] eth_getTransactionCount
55
- - [x] eth_getCode
56
- - [x] eth_getProof
57
- - [x] eth/sign
58
- - [x] eth_sign
59
- - [x] eth_signTransaction
60
- - [x] eth/filter
61
- - [x] eth_newFilter
62
- - [x] eth_newBlockFilter
63
- - [x] eth_newPendingTransactionFilter
64
- - [x] eth_uninstallFilter
65
- - [x] eth_getFilterChanges
66
- - [x] eth_getFilterLogs
67
- - [x] eth_getLogs
68
- - [x] eth/feeMarket
69
- - [x] eth_gasPrice
70
- - [x] eth_blobBaseFee
71
- - [x] eth_maxPriorityFeePerGas
72
- - [x] eth_feeHistory
73
- - [x] eth/execute
74
- - [x] eth_call
75
- - [x] eth_estimateGas
76
- - [x] eth_createAccessList
77
- - [x] eth_simulateV1
78
- - [x] eth/client
79
- - [x] eth_chainId
80
- - [x] eth_syncing
81
- - [x] eth_coinbase
82
- - [x] eth_accounts
83
- - [x] eth_blockNumber
84
- - [x] net_version
85
- - [x] eth/block
86
- - [x] eth_getBlockByHash
87
- - [x] eth_getBlockByNumber
88
- - [x] eth_getBlockTransactionCountByHash
89
- - [x] eth_getBlockTransactionCountByNumber
90
- - [x] eth_getUncleCountByBlockHash
91
- - [x] eth_getUncleCountByBlockNumber
92
- - [x] eth_getBlockReceipts
93
- - [x] debug
94
- - [x] debug_getRawHeader = "debug_getRawHeader",
95
- - [x] debug_getRawBlock = "debug_getRawBlock",
96
- - [x] debug_getRawTransaction = "debug_getRawTransaction",
97
- - [x] debug_getRawReceipts = "debug_getRawReceipts",
98
- - [x] debug_getBadBlocks = "debug_getBadBlocks",
99
-
100
- ### Builtin flashbots MEV rpc methods
101
-
102
- - [x] eth_sendBundle
103
- - [x] mev_sendBundle
104
- - [x] eth_callBundle
105
- - [x] eth_cancelBundle
106
- - [x] mev_simBundle
107
- - [x] eth_sendPrivateTransaction
108
- - [x] eth_sendPrivateRawTransaction
109
- - [x] eth_cancelPrivateTransaction
110
- - [x] flashbots_getFeeRefundTotalsByRecipient
111
- - [x] flashbots_getFeeRefundsByRecipient
112
- - [x] flashbots_getFeeRefundsByBundle
113
- - [x] flashbots_getFeeRefundsByBlock
114
- - [x] flashbots_setFeeRefundRecipient
115
- - [x] buildernet_getDelayedRefunds
116
- - [x] buildernet_getDelayedRefundTotalsByRecipient
117
- - [x] flashbots_getMevRefundTotalByRecipient
118
- - [x] flashbots_getMevRefundTotalBySender
119
-
120
- ### Engine RPC Methods Implemented
121
-
122
- - [x] engine/blob
123
- - [x] engine_getBlobsV1
124
- - [x] engine_getBlobsV2
125
- - [x] engine_getBlobsV3
126
- - [x] engine/capabilities
127
- - [x] engine_exchangeCapabilities
128
- - [x] engine/forkchoice
129
- - [x] engine_forkchoiceUpdatedV1
130
- - [x] engine_forkchoiceUpdatedV2
131
- - [x] engine_forkchoiceUpdatedV3
132
- - [x] engine/payload
133
- - [x] engine_newPayloadV1
134
- - [x] engine_newPayloadV2
135
- - [x] engine_newPayloadV3
136
- - [x] engine_newPayloadV4
137
- - [x] engine_getPayloadV1
138
- - [x] engine_getPayloadV2
139
- - [x] engine_getPayloadV3
140
- - [x] engine_getPayloadV4
141
- - [x] engine_getPayloadV5
142
- - [x] engine_getPayloadBodiesByHashV1
143
- - [x] engine_getPayloadBodiesByRangeV1
144
- - [x] engine_newPayloadV5
145
- - [x] engine_getPayloadV6
146
- - [x] engine/transition-configuration
147
- - [x] engine_exchangeTransitionConfigurationV1
55
+ ## Error Handling
56
+
57
+ All methods return typed responses. Handle errors appropriately:
58
+
59
+ ```typescript
60
+ try {
61
+ const balance = await client.eth_getBalance(address, 'latest');
62
+ console.log('Balance:', balance);
63
+ } catch (error) {
64
+ console.error('RPC Error:', error);
65
+ }
66
+ ```
67
+
68
+ ## Type Safety
69
+
70
+ Full TypeScript support with comprehensive type definitions for all RPC methods and responses.
71
+
72
+ ## Dependencies
73
+
74
+ - `@asyncswap/jsonrpc` - JSON-RPC 2.0 client/server implementation
75
+
76
+ ## License
77
+
78
+ MIT
package/example.ts CHANGED
@@ -18,7 +18,9 @@ const payload = engine.engine_getPayloadV1("0x1");
18
18
 
19
19
  console.log(payload);
20
20
 
21
- import { EthFlashbotsClient } from "./src";
21
+ import { FlashbotsClient } from "./src";
22
22
 
23
23
  const rpc = "https://relay.flashbots.net";
24
- const client = new EthFlashbotsClient(rpc);
24
+ const client = new FlashbotsClient(rpc);
25
+ const body = client.rpc.buildRequest("eth_sendBundle", []);
26
+ client.eth_accounts();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@asyncswap/eth-rpc",
3
3
  "description": "A library for ethereum execution clients apis.",
4
4
  "author": "Meek Msaki",
5
- "version": "0.4.1",
5
+ "version": "0.4.3",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "dist/index.js",
@@ -41,6 +41,6 @@
41
41
  "typescript": "^5"
42
42
  },
43
43
  "dependencies": {
44
- "@asyncswap/jsonrpc": "^0.4.0"
44
+ "@asyncswap/jsonrpc": "^0.4.3"
45
45
  }
46
46
  }
package/src/engine-api.ts CHANGED
@@ -1,320 +1,37 @@
1
1
  import { JsonRpcClient } from "@asyncswap/jsonrpc";
2
2
 
3
+ export type EngineRpcMethods<
4
+ T extends Record<string, { params: unknown[]; result: unknown }>,
5
+ > = {
6
+ [K in keyof T]: (...params: T[K]["params"]) => Promise<T[K]["result"]>;
7
+ };
8
+
3
9
  export class EngineExecutionClient {
4
- private client: JsonRpcClient;
5
- private headers: Record<string, string>;
10
+ rpc: JsonRpcClient;
11
+ headers: Record<string, string>;
6
12
 
7
13
  constructor(url: string, jwt_token: string) {
8
14
  this.headers = {
9
15
  Authorization: `Bearer ${jwt_token}`,
10
16
  };
11
- this.client = new JsonRpcClient(url);
12
- }
17
+ this.rpc = new JsonRpcClient(url);
13
18
 
14
- // eth/transaction
15
- async eth_sendRawTransaction(transaction: Bytes): Promise<Hash32> {
16
- return await this.client.call(
17
- EngineMethods.eth_sendRawTransaction,
18
- [transaction],
19
- this.headers,
20
- );
21
- }
22
- // eth/state
23
- async eth_getCode(
24
- address: Address,
25
- block: BlockNumberOrTagOrHash,
26
- ): Promise<Bytes> {
27
- return await this.client.call(
28
- EngineMethods.eth_getCode,
29
- [address, block],
30
- this.headers,
31
- );
32
- }
33
- async eth_getLogs(filter: Filter): Promise<FilterResults> {
34
- return await this.client.call(
35
- EngineMethods.eth_getLogs,
36
- [filter],
37
- this.headers,
38
- );
39
- }
40
- // eth/execute
41
- async eth_call(
42
- transaction: GenericTransaction,
43
- block: BlockNumberOrTagOrHash,
44
- ): Promise<Bytes> {
45
- return this.client.call(
46
- EngineMethods.eth_call,
47
- [transaction, block],
48
- this.headers,
49
- );
50
- }
51
- // eth/client
52
- async eth_chainId(): Promise<Uint> {
53
- return await this.client.call(EngineMethods.eth_chainId, [], this.headers);
54
- }
55
- async eth_syncing(): Promise<SyncingStatus> {
56
- return await this.client.call(EngineMethods.eth_syncing, [], this.headers);
57
- }
58
- async eth_blockNumber(): Promise<Uint> {
59
- return await this.client.call(
60
- EngineMethods.eth_blockNumber,
61
- [],
62
- this.headers,
63
- );
64
- }
65
- // eth/block
66
- async eth_getBlockByHash(
67
- blockHash: Hash32,
68
- hydratedTransactions: boolean,
69
- ): Promise<NotFound | Block> {
70
- return await this.client.call(
71
- EngineMethods.eth_getBlockByHash,
72
- [blockHash, hydratedTransactions],
73
- this.headers,
74
- );
75
- }
76
- async eth_getBlockByNumber(
77
- block: BlockNumberOrTag,
78
- hydratedTransactions: boolean,
79
- ): Promise<NotFound | Block> {
80
- return await this.client.call(
81
- EngineMethods.eth_getBlockByNumber,
82
- [block, hydratedTransactions],
83
- this.headers,
84
- );
85
- }
86
- // engine/blob
87
- async engine_getBlobsV1(
88
- blobedVersionedHashes: Hash32[],
89
- ): Promise<BlobAndProofV1[]> {
90
- return await this.client.call(
91
- EngineMethods.engine_getBlobsV1,
92
- [blobedVersionedHashes],
93
- this.headers,
94
- );
95
- }
96
- async engine_getBlobsV2(
97
- blobedVersionedHashes: Hash32[],
98
- ): Promise<BlobAndProofV2[]> {
99
- return await this.client.call(
100
- EngineMethods.engine_getBlobsV2,
101
- [blobedVersionedHashes],
102
- this.headers,
103
- );
104
- }
105
- async engine_getBlobsV3(
106
- blobedVersionedHashes: Hash32[],
107
- ): Promise<Array<BlobAndProofV2[] | null> | null> {
108
- return await this.client.call(
109
- EngineMethods.engine_getBlobsV3,
110
- [blobedVersionedHashes],
111
- this.headers,
112
- );
113
- }
114
- // engine/capabilities
115
- async engine_exchangeCapabilities(
116
- consensusClientMethods: string[],
117
- ): Promise<string[]> {
118
- return await this.client.call(
119
- EngineMethods.engine_exchangeCapabilities,
120
- [consensusClientMethods],
121
- this.headers,
122
- );
123
- }
124
- // engine/forkchoice
125
- async engine_forkchoiceUpdatedV1(
126
- forkchoiceState: ForkchoiceStateV1,
127
- payloadAttribute: PayloadAttributesV1,
128
- ): Promise<ForkchoiceUpdatedResponseV1> {
129
- return await this.client.call(
130
- EngineMethods.engine_forkchoiceUpdatedV1,
131
- [forkchoiceState, payloadAttribute],
132
- this.headers,
133
- );
134
- }
135
- async engine_forkchoiceUpdatedV2(
136
- forkchoiceState: ForkchoiceStateV1,
137
- payloadAttribute: PayloadAttributesV2,
138
- ): Promise<ForkchoiceUpdatedResponseV1> {
139
- return await this.client.call(
140
- EngineMethods.engine_forkchoiceUpdatedV2,
141
- [forkchoiceState, payloadAttribute],
142
- this.headers,
143
- );
144
- }
145
- async engine_forkchoiceUpdatedV3(
146
- forkchoiceState: ForkchoiceStateV1,
147
- payloadAttribute: PayloadAttributesV3,
148
- ): Promise<ForkchoiceUpdatedResponseV1> {
149
- return await this.client.call(
150
- EngineMethods.engine_forkchoiceUpdatedV3,
151
- [forkchoiceState, payloadAttribute],
152
- this.headers,
153
- );
19
+ return new Proxy(this, {
20
+ get: (_, method: string) => {
21
+ return (...params: unknown[]) =>
22
+ this.rpc.call(this.rpc.buildRequest(method, params), this.headers);
23
+ },
24
+ });
154
25
  }
155
- // engine/payload
156
- async engine_newPayloadV1(
157
- executionPayload: ExecutionPayloadV1,
158
- ): Promise<PayloadStatusV1> {
159
- return await this.client.call(
160
- EngineMethods.engine_newPayloadV1,
161
- [executionPayload],
162
- this.headers,
163
- );
164
- }
165
- async engine_newPayloadV2(
166
- executionPayload: ExecutionPayloadV1 | ExecutionPayloadV2,
167
- ): Promise<PayloadStatusNoInvalidBlockHash> {
168
- return await this.client.call(
169
- EngineMethods.engine_newPayloadV2,
170
- [executionPayload],
171
- this.headers,
172
- );
173
- }
174
- async engine_newPayloadV3(
175
- executionPayload: ExecutionPayloadV3,
176
- expectedBlobVersionedHashes: Hash32[],
177
- rootOfTheParentBeaconBlock: Hash32,
178
- ): Promise<PayloadStatusNoInvalidBlockHash> {
179
- return await this.client.call(
180
- EngineMethods.engine_newPayloadV3,
181
- [
182
- executionPayload,
183
- expectedBlobVersionedHashes,
184
- rootOfTheParentBeaconBlock,
185
- ],
186
- this.headers,
187
- );
188
- }
189
- async engine_newPayloadV4(
190
- executionPayload: ExecutionPayloadV3,
191
- expectedBlobVersionedHashes: Hash32[],
192
- rootOfTheParentBeaconBlock: Hash32,
193
- executionRequests: Bytes[],
194
- ): Promise<PayloadStatusNoInvalidBlockHash> {
195
- return await this.client.call(
196
- EngineMethods.engine_newPayloadV4,
197
- [
198
- executionPayload,
199
- expectedBlobVersionedHashes,
200
- rootOfTheParentBeaconBlock,
201
- executionRequests,
202
- ],
203
- this.headers,
204
- );
205
- }
206
- async engine_getPayloadV1(payloadId: Bytes8): Promise<ExecutionPayloadV1> {
207
- return await this.client.call(
208
- EngineMethods.engine_getPayloadV1,
209
- [payloadId],
210
- this.headers,
211
- );
212
- }
213
- async engine_getPayloadV2(payloadId: Bytes8): Promise<{
214
- executionPayload: ExecutionPayloadV1 | ExecutionPayloadV2;
215
- blockValue: Uint256;
216
- }> {
217
- return await this.client.call(
218
- EngineMethods.engine_getPayloadV2,
219
- [payloadId],
220
- this.headers,
221
- );
222
- }
223
- async engine_getPayloadV3(payloadId: Bytes8): Promise<{
224
- executionPayload: ExecutionPayloadV3;
225
- blockValue: Uint256;
226
- blobsBundle: BlobsBundleV1;
227
- shouldOverrideBuilder: boolean;
228
- }> {
229
- return await this.client.call(
230
- EngineMethods.engine_getPayloadV3,
231
- [payloadId],
232
- this.headers,
233
- );
234
- }
235
- async engine_getPayloadV4(payloadId: Bytes8): Promise<{
236
- executionPayload: ExecutionPayloadV3;
237
- blockValue: Uint256;
238
- blobsBundle: BlobsBundleV1;
239
- shouldOverrideBuilder: boolean;
240
- executionRequests: Bytes[];
241
- }> {
242
- return await this.client.call(
243
- EngineMethods.engine_getPayloadV4,
244
- [payloadId],
245
- this.headers,
246
- );
247
- }
248
- async engine_getPayloadV5(payloadId: Bytes8): Promise<{
249
- executionPayload: ExecutionPayloadV3;
250
- blockValue: Uint256;
251
- blobsBundle: BlobsBundleV2;
252
- shouldOverrideBuilder: boolean;
253
- executionRequests: Bytes[];
254
- }> {
255
- return await this.client.call(
256
- EngineMethods.engine_getPayloadV5,
257
- [payloadId],
258
- this.headers,
259
- );
260
- }
261
- async engine_getPayloadBodiesByHashV1(
262
- arrayOfBlockHashes: Hash32[],
263
- ): Promise<ExecutionPayloadBodyV1[]> {
264
- return await this.client.call(
265
- EngineMethods.engine_getPayloadBodiesByHashV1,
266
- [arrayOfBlockHashes],
267
- this.headers,
268
- );
269
- }
270
- async engine_getPayloadBodiesByRangeV1(
271
- startingBlockNumber: Uint64,
272
- numberOfBlocksToReturn: Uint64,
273
- ): Promise<ExecutionPayloadBodyV1[]> {
274
- return await this.client.call(
275
- EngineMethods.engine_getPayloadBodiesByRangeV1,
276
- [startingBlockNumber, numberOfBlocksToReturn],
277
- this.headers,
278
- );
279
- }
280
- async engine_newPayloadV5(
281
- executionPayload: ExecutionPayloadV4,
282
- expectedBlobVersionedHashes: Hash32[],
283
- parentBeaconBlockRoot: Hash32,
284
- executionRequests: Bytes[],
285
- ): Promise<PayloadStatusNoInvalidBlockHash> {
286
- return await this.client.call(
287
- EngineMethods.engine_newPayloadV5,
288
- [
289
- executionPayload,
290
- expectedBlobVersionedHashes,
291
- parentBeaconBlockRoot,
292
- executionRequests,
293
- ],
294
- this.headers,
295
- );
296
- }
297
- async engine_getPayloadV6(payloadId: Bytes8): Promise<{
298
- executionPayload: ExecutionPayloadV4;
299
- blockValue: Uint256;
300
- blobsBundle: BlobsBundleV2;
301
- shouldOverrideBuilder: boolean;
302
- executionRequests: Bytes[];
303
- }> {
304
- return await this.client.call(
305
- EngineMethods.engine_getPayloadV6,
306
- [payloadId],
307
- this.headers,
308
- );
309
- }
310
- // engine/transition-configuration
311
- async engine_exchangeTransitionConfigurationV1(
312
- consensusClientConfiguration: TransitionConfigurationV1,
313
- ): Promise<TransitionConfigurationV1> {
314
- return await this.client.call(
315
- EngineMethods.engine_exchangeTransitionConfigurationV1,
316
- [consensusClientConfiguration],
317
- this.headers,
318
- );
26
+
27
+ setHeaders(headers: Record<string, string>) {
28
+ this.headers = {
29
+ ...this.headers,
30
+ ...headers,
31
+ };
32
+ return this;
319
33
  }
320
34
  }
35
+
36
+ export interface EngineExecutionClient
37
+ extends EngineRpcMethods<EngineMethodsSpec> { }