Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to get mempool transactions and decode with ethers js

const {providers} = require("ethers");
const abiDecoder = require('abi-decoder');
abiDecoder.addABI(contractABI)// you can get it from the etherScan

const customWsProvider = 
      new providers.WebSocketProvider
      ('ws://localhost:8546');//replace this with alchemy/Infura endpoint
const init = function () {
  customWsProvider.on("pending", async (tx) => {
    let transaction = await customWsProvider.getTransaction(tx)
    if (!transaction) {
      let data = abiDecoder.decodeMethod(transaction.data);
      if (!data) {
        console.log(data)
      }
    }
  });
};

init();
 
PREVIOUS NEXT
Tagged: #mempool #transactions #decode #ethers #js
ADD COMMENT
Topic
Name
7+8 =