@msaki/eth-rpc 0.1.0 → 0.2.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.
@@ -1,202 +1,295 @@
1
- import { JsonRpcClient, initializeRpcClient } from "@msaki/jsonrpc";
2
- export type * as EthSchema from "./types";
3
- import type { EthSchema } from ".";
1
+ import { initializeRpcClient, JsonRpcClient } from "@msaki/jsonrpc";
4
2
 
5
3
  export enum Methods {
6
- // eth/transaction
7
- eth_getTransactionByHash = "eth_getTransactionByHash",
8
- eth_getTransactionByBlockHashAndIndex = "eth_getTransactionByBlockHashAndIndex",
9
- eth_getTransactionReceipt = "eth_getTransactionReceipt",
10
- // eth/submit
11
- eth_sendTransaction = "eth_sendTransaction",
12
- eth_sendRawTransaction = "eth_sendRawTransaction",
13
- // eth/state
14
- eth_getBalance = "eth_getBalance",
15
- eth_getStorageAt = "eth_getStorageAt",
16
- eth_getTransactionCount = "eth_getTransactionCount",
17
- eth_getCode = "eth_getCode",
18
- eth_getProof = "eth_getProof",
19
- // eth/sign
20
- eth_sign = "eth_sign",
21
- eth_signTransaction = "eth_signTransaction",
22
- // eth/filter
23
- eth_newFilter = "eth_newFilter",
24
- eth_newBlockFilter = "eth_newBlockFilter",
25
- eth_newPendingTransactionFilter = "eth_newPendingTransactionFilter",
26
- eth_uninstallFilter = "eth_uninstallFilter",
27
- eth_getFilterChanges = "eth_getFilterChanges",
28
- eth_getFilterLogs = "eth_getFilterLogs",
29
- eth_getLogs = "eth_getLogs",
4
+ // eth/transaction
5
+ eth_getTransactionByHash = "eth_getTransactionByHash",
6
+ eth_getTransactionByBlockHashAndIndex = "eth_getTransactionByBlockHashAndIndex",
7
+ eth_getTransactionReceipt = "eth_getTransactionReceipt",
8
+ // eth/submit
9
+ eth_sendTransaction = "eth_sendTransaction",
10
+ eth_sendRawTransaction = "eth_sendRawTransaction",
11
+ // eth/state
12
+ eth_getBalance = "eth_getBalance",
13
+ eth_getStorageAt = "eth_getStorageAt",
14
+ eth_getTransactionCount = "eth_getTransactionCount",
15
+ eth_getCode = "eth_getCode",
16
+ eth_getProof = "eth_getProof",
17
+ // eth/sign
18
+ eth_sign = "eth_sign",
19
+ eth_signTransaction = "eth_signTransaction",
20
+ // eth/filter
21
+ eth_newFilter = "eth_newFilter",
22
+ eth_newBlockFilter = "eth_newBlockFilter",
23
+ eth_newPendingTransactionFilter = "eth_newPendingTransactionFilter",
24
+ eth_uninstallFilter = "eth_uninstallFilter",
25
+ eth_getFilterChanges = "eth_getFilterChanges",
26
+ eth_getFilterLogs = "eth_getFilterLogs",
27
+ eth_getLogs = "eth_getLogs",
28
+ // eth/feeMarket
29
+ eth_gasPrice = "eth_gasPrice",
30
+ eth_blobBaseFee = "eth_blobBaseFee",
31
+ eth_maxPriorityFeePerGas = "eth_maxPriorityFeePerGas",
32
+ eth_feeHistory = "eth_feeHistory",
33
+ // eth/execute
34
+ eth_call = "eth_call",
35
+ eth_estimateGas = "eth_estimateGas",
36
+ eth_createAccessList = "eth_createAccessList",
37
+ eth_simulateV1 = "eth_simulateV1",
38
+ // eth/client
39
+ eth_chainId = "eth_chainId",
40
+ eth_syncing = "eth_syncing",
41
+ eth_coinbase = "eth_coinbase",
42
+ eth_accounts = "eth_accounts",
43
+ eth_blockNumber = "eth_blockNumber",
44
+ net_version = "net_version",
45
+ // eth/block
46
+ eth_getBlockByHash = "eth_getBlockByHash",
47
+ eth_getBlockByNumber = "eth_getBlockByNumber",
48
+ eth_getBlockTransactionCountByHash = "eth_getBlockTransactionCountByHash",
49
+ eth_getBlockTransactionCountByNumber = "eth_getBlockTransactionCountByNumber",
50
+ eth_getUncleCountByBlockHash = "eth_getUncleCountByBlockHash",
51
+ eth_getUncleCountByBlockNumber = "eth_getUncleCountByBlockNumber",
52
+ eth_getBlockReceipts = "eth_getBlockReceipts",
30
53
  }
31
54
 
32
55
  export class EthExecutionClient {
33
- private client: JsonRpcClient;
56
+ private client: JsonRpcClient;
34
57
 
35
- constructor(url: string) {
36
- this.client = initializeRpcClient(url)
37
- }
58
+ constructor(url: string) {
59
+ this.client = initializeRpcClient(url);
60
+ }
38
61
 
39
- // eth/transaction
40
- async eth_getTransactionByHash(
41
- transactioHash: EthSchema.Hash32
42
- ): Promise<EthSchema.NotFound | EthSchema.TransactionInfo> {
43
- return await this.client.call(
44
- Methods.eth_getTransactionByHash,
45
- [transactioHash]
46
- );
47
- }
48
- async eth_getTransactionByBlockHashAndIndex(
49
- blockHash: EthSchema.Hash32,
50
- transactionIndex: EthSchema.Uint
51
- ): Promise<EthSchema.NotFound | EthSchema.TransactionInfo> {
52
- return await this.client.call(
53
- Methods.eth_getTransactionByBlockHashAndIndex,
54
- [blockHash, transactionIndex]
55
- );
56
- }
57
- async eth_getTransactionReceipt(
58
- transactionHash: EthSchema.Hash32,
59
- ): Promise<EthSchema.NotFound | EthSchema.ReceiptInfo> {
60
- return await this.client.call(
61
- Methods.eth_getTransactionReceipt,
62
- [transactionHash]
63
- );
64
- }
62
+ // eth/transaction
63
+ async eth_getTransactionByHash(
64
+ transactioHash: Hash32,
65
+ ): Promise<NotFound | TransactionInfo> {
66
+ return await this.client.call(Methods.eth_getTransactionByHash, [
67
+ transactioHash,
68
+ ]);
69
+ }
70
+ async eth_getTransactionByBlockHashAndIndex(
71
+ blockHash: Hash32,
72
+ transactionIndex: Uint,
73
+ ): Promise<NotFound | TransactionInfo> {
74
+ return await this.client.call(
75
+ Methods.eth_getTransactionByBlockHashAndIndex,
76
+ [blockHash, transactionIndex],
77
+ );
78
+ }
79
+ async eth_getTransactionReceipt(
80
+ transactionHash: Hash32,
81
+ ): Promise<NotFound | ReceiptInfo> {
82
+ return await this.client.call(Methods.eth_getTransactionReceipt, [
83
+ transactionHash,
84
+ ]);
85
+ }
65
86
 
66
- // eth/submit
67
- async eth_sendTransaction(
68
- transaction: EthSchema.GenericTransaction
69
- ): Promise<EthSchema.Hash32> {
70
- return await this.client.call(
71
- Methods.eth_sendTransaction,
72
- [transaction]
73
- )
74
- }
75
- async eth_sendRawTransaction(
76
- transaction: EthSchema.Bytes
77
- ): Promise<EthSchema.Hash32> {
78
- return await this.client.call(
79
- Methods.eth_sendRawTransaction,
80
- [transaction]
81
- )
82
- }
83
- // eth/state
84
- async eth_getBalance(
85
- address: EthSchema.Address,
86
- block: EthSchema.BlockNumberOrTagOrHash
87
- ): Promise<EthSchema.Uint> {
88
- return await this.client.call(
89
- Methods.eth_getBalance,
90
- [address, block]
91
- )
92
- }
93
- async eth_getStorageAt(
94
- address: EthSchema.Address,
95
- storageSlot: EthSchema.Bytes32,
96
- block: EthSchema.BlockNumberOrTagOrHash
97
- ): Promise<EthSchema.Bytes> {
98
- return await this.client.call(
99
- Methods.eth_getStorageAt,
100
- [address, storageSlot, block]
101
- )
102
- }
103
- async eth_getTransactionCount(
104
- address: EthSchema.Address,
105
- block: EthSchema.BlockNumberOrTagOrHash
106
- ): Promise<EthSchema.Uint> {
107
- return await this.client.call(
108
- Methods.eth_getTransactionCount,
109
- [address, block]
110
- )
111
- }
112
- async eth_getCode(
113
- address: EthSchema.Address,
114
- block: EthSchema.BlockNumberOrTagOrHash
115
- ): Promise<EthSchema.Bytes> {
116
- return await this.client.call(
117
- Methods.eth_getCode,
118
- [address, block]
119
- )
120
- }
121
- async eth_getProof(
122
- address: EthSchema.Address,
123
- storageKeys: EthSchema.Bytes32[],
124
- block: EthSchema.BlockNumberOrTagOrHash,
125
- ): Promise<EthSchema.AccountProof> {
126
- return await this.client.call(
127
- Methods.eth_getProof,
128
- [address, storageKeys, block]
129
- )
130
- }
131
- // eth/sign
132
- async eth_sign(
133
- address: EthSchema.Address,
134
- message: EthSchema.Bytes
135
- ): Promise<EthSchema.Bytes65> {
136
- return await this.client.call(
137
- Methods.eth_sign,
138
- [address, message]
139
- )
140
- }
141
- async eth_signTransaction(
142
- transaction: EthSchema.GenericTransaction
143
- ): Promise<EthSchema.Bytes> {
144
- return await this.client.call(
145
- Methods.eth_signTransaction,
146
- [transaction]
147
- )
148
- }
149
- // eth/filter
150
- async eth_newFilter(
151
- filter: EthSchema.Filter
152
- ): Promise<EthSchema.Uint> {
153
- return await this.client.call(
154
- Methods.eth_newFilter,
155
- [filter],
156
- )
157
- }
158
- async eth_newBlockFilter(
159
- ): Promise<EthSchema.Uint> {
160
- return await this.client.call(
161
- Methods.eth_newBlockFilter,
162
- [],
163
- )
164
- }
165
- async eth_newPendingTransactionFilter(
166
- ): Promise<EthSchema.Uint> {
167
- return await this.client.call(
168
- Methods.eth_newPendingTransactionFilter,
169
- []
170
- )
171
- }
172
- async eth_uninstallFilter(
173
- ): Promise<EthSchema.Uint> {
174
- return await this.client.call(
175
- Methods.eth_uninstallFilter,
176
- []
177
- )
178
- }
179
- async eth_getFilterChanges(
180
- ): Promise<EthSchema.FilterResults> {
181
- return await this.client.call(
182
- Methods.eth_getFilterChanges,
183
- []
184
- )
185
- }
186
- async eth_getFilterLogs(
187
- filterIdentifier: EthSchema.Uint
188
- ): Promise<EthSchema.FilterResults> {
189
- return await this.client.call(
190
- Methods.eth_getFilterLogs,
191
- [filterIdentifier]
192
- )
193
- }
194
- async eth_getLogs(
195
- filter: EthSchema.Filter
196
- ): Promise<EthSchema.FilterResults> {
197
- return await this.client.call(
198
- Methods.eth_getLogs,
199
- [filter]
200
- )
201
- }
87
+ // eth/submit
88
+ async eth_sendTransaction(transaction: GenericTransaction): Promise<Hash32> {
89
+ return await this.client.call(Methods.eth_sendTransaction, [transaction]);
90
+ }
91
+ async eth_sendRawTransaction(transaction: Bytes): Promise<Hash32> {
92
+ return await this.client.call(Methods.eth_sendRawTransaction, [
93
+ transaction,
94
+ ]);
95
+ }
96
+ // eth/state
97
+ async eth_getBalance(
98
+ address: Address,
99
+ block: BlockNumberOrTagOrHash,
100
+ ): Promise<Uint> {
101
+ return await this.client.call(Methods.eth_getBalance, [address, block]);
102
+ }
103
+ async eth_getStorageAt(
104
+ address: Address,
105
+ storageSlot: Bytes32,
106
+ block: BlockNumberOrTagOrHash,
107
+ ): Promise<Bytes> {
108
+ return await this.client.call(Methods.eth_getStorageAt, [
109
+ address,
110
+ storageSlot,
111
+ block,
112
+ ]);
113
+ }
114
+ async eth_getTransactionCount(
115
+ address: Address,
116
+ block: BlockNumberOrTagOrHash,
117
+ ): Promise<Uint> {
118
+ return await this.client.call(Methods.eth_getTransactionCount, [
119
+ address,
120
+ block,
121
+ ]);
122
+ }
123
+ async eth_getCode(
124
+ address: Address,
125
+ block: BlockNumberOrTagOrHash,
126
+ ): Promise<Bytes> {
127
+ return await this.client.call(Methods.eth_getCode, [address, block]);
128
+ }
129
+ async eth_getProof(
130
+ address: Address,
131
+ storageKeys: Bytes32[],
132
+ block: BlockNumberOrTagOrHash,
133
+ ): Promise<AccountProof> {
134
+ return await this.client.call(Methods.eth_getProof, [
135
+ address,
136
+ storageKeys,
137
+ block,
138
+ ]);
139
+ }
140
+ // eth/sign
141
+ async eth_sign(address: Address, message: Bytes): Promise<Bytes65> {
142
+ return await this.client.call(Methods.eth_sign, [address, message]);
143
+ }
144
+ async eth_signTransaction(transaction: GenericTransaction): Promise<Bytes> {
145
+ return await this.client.call(Methods.eth_signTransaction, [transaction]);
146
+ }
147
+ // eth/filter
148
+ async eth_newFilter(filter: Filter): Promise<Uint> {
149
+ return await this.client.call(Methods.eth_newFilter, [filter]);
150
+ }
151
+ async eth_newBlockFilter(): Promise<Uint> {
152
+ return await this.client.call(Methods.eth_newBlockFilter, []);
153
+ }
154
+ async eth_newPendingTransactionFilter(): Promise<Uint> {
155
+ return await this.client.call(Methods.eth_newPendingTransactionFilter, []);
156
+ }
157
+ async eth_uninstallFilter(): Promise<Uint> {
158
+ return await this.client.call(Methods.eth_uninstallFilter, []);
159
+ }
160
+ async eth_getFilterChanges(): Promise<FilterResults> {
161
+ return await this.client.call(Methods.eth_getFilterChanges, []);
162
+ }
163
+ async eth_getFilterLogs(filterIdentifier: Uint): Promise<FilterResults> {
164
+ return await this.client.call(Methods.eth_getFilterLogs, [
165
+ filterIdentifier,
166
+ ]);
167
+ }
168
+ async eth_getLogs(filter: Filter): Promise<FilterResults> {
169
+ return await this.client.call(Methods.eth_getLogs, [filter]);
170
+ }
171
+ // eth/feeMarket
172
+ async eth_gasPrice(): Promise<Uint> {
173
+ return await this.client.call(Methods.eth_gasPrice, []);
174
+ }
175
+ async eth_blobBaseFee(): Promise<Uint> {
176
+ return await this.client.call(Methods.eth_blobBaseFee, []);
177
+ }
178
+ async eth_maxPriorityFeePerGas(): Promise<Uint> {
179
+ return await this.client.call(Methods.eth_maxPriorityFeePerGas, []);
180
+ }
181
+ async eth_feeHistory(
182
+ blockCount: Uint,
183
+ newestBlock: BlockNumberOrTag,
184
+ rewardPercentiles: number[],
185
+ ): Promise<FeeHistoryResults> {
186
+ return await this.client.call(Methods.eth_feeHistory, [
187
+ blockCount,
188
+ newestBlock,
189
+ rewardPercentiles,
190
+ ]);
191
+ }
192
+ // eth/execute
193
+ async eth_call(
194
+ transaction: GenericTransaction,
195
+ block: BlockNumberOrTagOrHash,
196
+ ): Promise<Bytes> {
197
+ return this.client.call(Methods.eth_call, [transaction, block]);
198
+ }
199
+ async eth_estimateGas(
200
+ transaction: GenericTransaction,
201
+ block: BlockNumberOrTag,
202
+ ): Promise<Uint> {
203
+ return await this.client.call(Methods.eth_estimateGas, [
204
+ transaction,
205
+ block,
206
+ ]);
207
+ }
208
+ async eth_createAccessList(
209
+ transaction: GenericTransaction,
210
+ block: BlockNumberOrTag,
211
+ ): Promise<AccessListResult> {
212
+ return await this.client.call(Methods.eth_createAccessList, [
213
+ transaction,
214
+ block,
215
+ ]);
216
+ }
217
+ async eth_simulateV1(
218
+ payload: EthSimulatePayload,
219
+ blockTag: BlockNumberOrTagOrHash,
220
+ ): Promise<EthSimulateResult> {
221
+ return await this.client.call(Methods.eth_simulateV1, [payload, blockTag]);
222
+ }
223
+ // eth/client
224
+ async eth_chainId(): Promise<Uint> {
225
+ return await this.client.call(Methods.eth_chainId, []);
226
+ }
227
+ async eth_syncing(): Promise<SyncingStatus> {
228
+ return await this.client.call(Methods.eth_syncing, []);
229
+ }
230
+ async eth_coinbase(): Promise<Address> {
231
+ return await this.client.call(Methods.eth_coinbase, []);
232
+ }
233
+ async eth_accounts(): Promise<Addresses> {
234
+ return await this.client.call(Methods.eth_accounts, []);
235
+ }
236
+ async eth_blockNumber(): Promise<Uint> {
237
+ return await this.client.call(Methods.eth_blockNumber, []);
238
+ }
239
+ async net_version(): Promise<UintDecimal> {
240
+ return await this.client.call(Methods.net_version, []);
241
+ }
242
+ // eth/block
243
+ async eth_getBlockByHash(
244
+ blockHash: Hash32,
245
+ hydratedTransactions: boolean,
246
+ ): Promise<NotFound | Block> {
247
+ return await this.client.call(Methods.eth_getBlockByHash, [
248
+ blockHash,
249
+ hydratedTransactions,
250
+ ]);
251
+ }
252
+ async eth_getBlockByNumber(
253
+ block: BlockNumberOrTag,
254
+ hydratedTransactions: boolean,
255
+ ): Promise<NotFound | Block> {
256
+ return await this.client.call(Methods.eth_getBlockByNumber, [
257
+ block,
258
+ hydratedTransactions,
259
+ ]);
260
+ }
261
+ async eth_getBlockTransactionCountByHash(
262
+ blockHash: Hash32,
263
+ ): Promise<NotFound | Uint> {
264
+ return await this.client.call(Methods.eth_getBlockTransactionCountByHash, [
265
+ blockHash,
266
+ ]);
267
+ }
268
+ async eth_getBlockTransactionCountByNumber(
269
+ block: BlockNumberOrTag,
270
+ ): Promise<NotFound | Uint> {
271
+ return await this.client.call(
272
+ Methods.eth_getBlockTransactionCountByNumber,
273
+ [block],
274
+ );
275
+ }
276
+ async eth_getUncleCountByBlockHash(
277
+ blockHash: Hash32,
278
+ ): Promise<NotFound | Uint> {
279
+ return await this.client.call(Methods.eth_getUncleCountByBlockHash, [
280
+ blockHash,
281
+ ]);
282
+ }
283
+ async eth_getUncleCountByBlockNumber(
284
+ block: BlockNumberOrTag,
285
+ ): Promise<NotFound | Uint> {
286
+ return await this.client.call(Methods.eth_getUncleCountByBlockNumber, [
287
+ block,
288
+ ]);
289
+ }
290
+ async eth_getBlockReceipts(
291
+ block: BlockNumberOrTagOrHash,
292
+ ): Promise<NotFound | ReceiptInfo> {
293
+ return await this.client.call(Methods.eth_getBlockReceipts, [block]);
294
+ }
202
295
  }
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
- export * from "./types";
2
- export * from "./eth-methods";
3
1
  export * from "./beacon-methods";
2
+ export * from "./eth-methods";
@@ -0,0 +1,23 @@
1
+ declare global {
2
+ // base.yaml
3
+ export type Hex = `0x${string}`;
4
+ export type Address = `0x${string}`;
5
+ export type Addresses = Address[];
6
+ export type Byte = Hex;
7
+ export type Bytes = Hex;
8
+ export type Bytes32 = Hex;
9
+ export type Bytes8 = Hex;
10
+ export type Bytes48 = Hex;
11
+ export type Bytes96 = Hex;
12
+ export type Bytes256 = Hex;
13
+ export type Bytes65 = Hex;
14
+ export type Ratio = number;
15
+ export type Uint = Hex;
16
+ export type Uint64 = Hex;
17
+ export type Uint256 = Hex;
18
+ export type UintDecimal = string; // e.g '1'
19
+ export type Hash32 = Hex;
20
+ export type NotFound = null;
21
+ }
22
+
23
+ export { };
@@ -0,0 +1,46 @@
1
+ declare global {
2
+ // block.yaml
3
+ export type BlockTag =
4
+ | "earliest"
5
+ | "finalized"
6
+ | "safe"
7
+ | "latest"
8
+ | "pending";
9
+ export type BlockNumberOrTag = Hex | BlockTag;
10
+ export type BlockNumberOrTagOrHash = BlockNumberOrTag | Hex;
11
+ export interface Block {
12
+ hash: Hash32;
13
+ parentHash: Hash32;
14
+ sha3Uncles: Hash32;
15
+ miner: Address;
16
+ stateRoot: Hash32;
17
+ transactionsRoot: Hash32;
18
+ receiptsRoot: Hash32;
19
+ logsBloom: Bytes256;
20
+ number: Uint;
21
+ gasLimit: Uint;
22
+ gasUsed: Uint;
23
+ timestamp: Uint;
24
+ extraData: Bytes;
25
+ mixHash: Hash32;
26
+ nonce: Bytes8;
27
+ size: Uint;
28
+ transactions: Hash32[] | TransactionInfo[];
29
+ uncles: Hash32[];
30
+ requestedHash?: Hash32;
31
+ baseFeePerGas?: Uint;
32
+ withdrawalsRoot?: Hash32;
33
+ blobGasUsed?: Uint;
34
+ excessBlobGas?: Uint;
35
+ parentBeaconBlockRoot?: Hash32;
36
+ withdrawals?: Withdrawal[];
37
+ difficulty?: Uint;
38
+ }
39
+ export interface BadBlock {
40
+ block: Block;
41
+ hash: Hash32;
42
+ rlp: Bytes;
43
+ }
44
+ }
45
+
46
+ export { };
@@ -0,0 +1,11 @@
1
+ declare global {
2
+ // client.yaml
3
+ export type SyncingStatus = Syncing | false;
4
+ export interface Syncing {
5
+ startingBlock?: Uint;
6
+ currentBlock?: Uint;
7
+ highestBlock?: Uint;
8
+ }
9
+ }
10
+
11
+ export { };