Skip to content

Instantly share code, notes, and snippets.

@svanas
Last active Jan 10, 2022
Embed
What would you like to do?
Listen on Blocknative's mempool WebSocket API
var
Mempool: IMempool;
procedure TForm1.Button1Click(Sender: TObject);
begin
Mempool := TSgcMempool.Subscribe(
Mainnet, // ethereum main net
'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // your blocknative API key
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // address to watch
procedure(event: TJsonObject; err: IError) // continuous events (or a blocknative error)
begin
var tx := web3.eth.blocknative.mempool.getTransaction(event);
if Assigned(tx) then
TThread.Synchronize(nil, procedure
begin
Memo1.Lines.Add(tx.ToString);
end);
end,
procedure(err: IError) // non-blocknative-error handler (probably a socket error)
begin
TThread.Synchronize(nil, procedure
begin
MessageDlg(err.Message, TMsgDlgType.mtError, [TMsgDlgBtn.mbOK], 0);
end);
end,
procedure
begin
// connection closed
end);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment