getPendingTransactions Error

Hi guys,
I am trying to handle pending transactions by using web3.eth.getPendingTransactions()
But it seems not works (?)
How can I get pending transactions with Moralis web3?

var pendingMMOrders  = null;
try {

      pendingMMOrders = await web3.eth.getPendingTransactions();

    } catch (err) {

      console.log("getPendingTransactions: Error: ", err);

    }

I got this error:

getPendingTransactions: Error: Error: The method ‘eth_pendingTransactions’ does not exist / is not available.
{
“method”: “eth_pendingTransactions”,
“params”: [],
“jsonrpc”: “2.0”,
“id”: 2390269410,
“origin”: “http://localhost:3000”,
“tabId”: 200
}
at Object._fireError (index.js:50)
at sendTxCallback (index.js:540)
at cb (util.js:689)
at callbackifyOnRejected (util.js:666)
at Item.push…/node_modules/process/browser.js.Item.run (browser.js:153)
at drainQueue (browser.js:123)

Can anyone please help me with this issue? @ivan

Hey @tungtien
Sorry for the long response :raised_hands:

Last time when I’ve checked it, it didn’t work. I’ll check it again :man_mechanic:

Hey @tungtien

You can get pending transactions using speedy nodes. I reccomend you to use websocket connection.

const nodeUrl =
      "wss://speedy-nodes-nyc.moralis.io/xxxxxxxxxxx/bsc/mainnet/ws";
    const provider = new Web3.providers.WebsocketProvider(nodeUrl);
    const web3 = new Web3(provider);

let subscription = web3.eth.subscribe('pendingTransactions', function (error, result) {
        if (result) {
          console.log(result)
        } else if (error) {
          console.log(error);
        }
      });

If you want to recieve more info you can use:


let subscription = web3.eth.subscribe('pendingTransactions', function (error, result) {
        if (result) {
          web3.eth.getTransaction(result, function (error, transaction) {
            console.log(transaction)
          })
        } else if (error) {
          console.log(error);
        }
      });

Happy BUIDLing :man_mechanic:

1 Like

Thank you Yomoo! I will try that…

2 Likes

@Yomoo ,
But there is no Speedy-nodes URL for BSC Testnet right? I need the BSC testnet for development…
And, Will this method works for clouds functions?

Hey @tungtien

Actually, there is:

  • wss://speedy-nodes-nyc.moralis.io/xxxxxx/bsc/testnet/ws

my Bad, I found it. thank you!

1 Like

@Yomoo,
on clouds function, if I call
_WEB3 = await Moralis.web3ByChain(networkId);

is it also using speedy-nodes ?

Most likely we are using speedy-nodes but will confirm this nevertheless.

Is there any way I can use this method for Clouds Functions?

@tungtien

Subscribe functions will not work on the cloud code.

1 Like