Skip to content

Pending transaction subscription (newPendingTransactions full tx) #14

@koko1123

Description

@koko1123

Summary

Add support for subscribing to full pending transactions via WebSocket (eth_subscribe with newPendingTransactions and full: true).

Motivation

MEV bots need to see pending transactions as they enter the mempool to identify opportunities (sandwich, backrun, liquidation). The current WebSocket subscription support needs to include full transaction objects -- not just hashes -- to avoid an extra eth_getTransactionByHash round-trip per pending tx.

On L2s, pending transaction visibility varies by chain, but where available, it's the primary signal for searchers.

Proposed API

const eth = @import("eth");

var ws = eth.ws_transport.WsTransport.init(allocator, "wss://eth.llamarpc.com");
defer ws.deinit();

// Subscribe to full pending transactions
var sub = try ws.subscribePendingTransactions(.{ .full = true });

while (try sub.next()) |tx| {
    // tx is a full Transaction object
    if (isTargetSwap(tx.data)) {
        // Found a DEX swap in the mempool
        const opportunity = evaluateArb(tx);
        // ...
    }
}

Implementation Notes

  • Uses eth_subscribe with "newPendingTransactions" and {"includeTransactions": true} parameter
  • Parse the full transaction object from the subscription notification
  • Should integrate with the existing WebSocket transport in src/ws_transport.zig
  • Consider a filtered variant that only returns txs matching certain criteria (to/from address, value threshold) to reduce parsing overhead

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is neededl2L2 chain supportmevMEV/searcher tooling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions