Skip to content

Commit 03e069e

Browse files
authored
feat: introduce v0.3.0 RPCs (#989)
* spike * fix ws example * add min client version
1 parent c169329 commit 03e069e

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

docs/base-chain/flashblocks/apps.mdx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,80 @@ curl https://sepolia-preconf.base.org -X POST -H "Content-Type: application/json
200200
}
201201
```
202202

203+
#### eth_subscribe <Badge color="orange" shape="rounded">Beta</Badge>
204+
205+
Subscribe to real-time streams of Flashblocks data via WebSocket. Three subscription types are available:
206+
207+
<Note>Requires node-reth minimum client version v0.3.0</Note>
208+
209+
- **pendingLogs** - Stream logs from transactions in Flashblocks
210+
- **newFlashblockTransactions** - Stream transaction hashes included in the block
211+
- **newFlashblocks** - Stream the pending block as new Flashblocks arrive
212+
213+
```javascript
214+
import WebSocket from 'ws';
215+
import { createHash } from 'crypto';
216+
217+
const ws = new WebSocket('wss://sepolia.flashblocks.base.org/ws');
218+
219+
ws.on('open', () => {
220+
console.log('Connected to Flashblocks WebSocket');
221+
// Subscribe to new Flashblocks
222+
ws.send(JSON.stringify({
223+
jsonrpc: "2.0",
224+
method: "eth_subscribe",
225+
params: ["newFlashblockTransactions"],
226+
id: 1
227+
}));
228+
});
229+
230+
ws.on('message', (data: WebSocket.Data) => {
231+
try {
232+
if (Buffer.isBuffer(data)) {
233+
if (data.length >= 37) {
234+
const txHash = '0x' + data.slice(5, 37).toString('hex');
235+
console.log(txHash);
236+
}
237+
} else {
238+
const response = JSON.parse(data.toString());
239+
if (response.id === 1) {
240+
console.log('✓ Subscribed');
241+
}
242+
}
243+
} catch (error) {
244+
// Handle error
245+
}
246+
});
247+
248+
ws.on('error', (error) => {
249+
console.error('WebSocket error:', error);
250+
});
251+
252+
ws.on('close', () => {
253+
console.log('WebSocket connection closed');
254+
});
255+
```
256+
257+
#### base_transactionStatus <Badge color="orange" shape="rounded">Beta</Badge>
258+
259+
Check whether a transaction is present in the mempool:
260+
261+
<Note>Requires node-reth minimum client version v0.3.0</Note>
262+
```
263+
curl https://sepolia-preconf.base.org -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"base_transactionStatus","params":["0x..."],"id":1}'
264+
```
265+
266+
**Example Response**
267+
```
268+
{
269+
"jsonrpc": "2.0",
270+
"id": 1,
271+
"result": {
272+
"status": "pending"
273+
}
274+
}
275+
```
276+
203277
### Libraries
204278

205279
You will need to use a Flashblocks-aware RPC endpoint to use Flashblocks with the following libraries:

0 commit comments

Comments
 (0)