Hi, I am trying to listen for all transaction on an address using the websocket provided. But when I did a test transaction to check for the functionality, it didn’t work and also got no errors. Can someone help with what am doing wrong? Below is the code I used to listen for log events in node js.
const Web3 = require("web3");
let web3 = new Web3(
new Web3.providers.WebsocketProvider(
"wss://kovan.infura.io/ws/v3/ID"
)
);
var subscription = web3.eth
.subscribe(
"logs",
{
address: "some example address",
},
(error, result) => {
if (!error) console.log("Result - " + result);
}
)
.on("data", (log) => console.log("Data - " + log))
.on("changed", (log) => console.log("Changed - " + log))
.on("connected", (log) => console.log("Subscription connected!"));
The connected event fires up on starting the server though.
Hi @Mano, unfortunately the logs sub type for eth_subscribe doesn’t return transactions from an address. Can you try the newPendingTransactions sub type and let us know if that helps? This will report back pending transactions, for mined transactions you will need to inspect the block.
Hi @Leiya_Kenney Thanks for the reference. But I couldn’t find stuff that might help. It would be nice if there’s an websocket that listens for incoming transactions of an address.
Hi @Mano, I would try using something similar to the code found on this thread, but with using ‘pendingTransactions’ instead of ‘logs’ and entering the correct address where that fits in. Let us know how that works out for you.
Hi @Leiya_Kenney, Sorry for the delayed response. I tried the method you suggested but the pendingTransactions doesn’t seem to accept parameters to filter by address like logs, so it returned an error.
Hi @Mano - you’re absolutely correct; sorry about that! I believe this article may help you. It’s a tutorial on checking for transactions to a certain address using web3.js. I believe this is similar to what you’re trying to do, and definitely syncs up with this being much more difficult than it seems at first! Let me know if this helps.