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:

2 Likes

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

when we use the web3.eth.getTransaction method, does it will cost us a request ?
Because in this case, it have a lot of pending transactions and with the 3500 request / min limitation on moralis, node server cant follow

Hi @ngostephane,
Did you solve this problem?

Getting transactions from a node or with the api will use request

Dear @cryptokid,
const subscription = web3.eth.subscribe(ā€œpendingTransactionsā€, async (err, res) => { });

I am getting the following error after 6-7 requests with the method.
UnhandledPromiseRejectionWarning: Error: CONNECTION ERROR: Couldnā€™t connect to node on WS.

I would recommend to use another node provider.

On what chain happens that?

I am struggling with speedy nodes waiting from bsc network.

I used this code now and I got a lot of transaction hashes without an error

const nodeUrl =
      "wss://speedy-nodes-nyc.moralis.io/4324/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);
        }
      });

anyway, you will get into issues when trying to get the exact transactions for those transaction hashes
you also have add some config to automatically reconnect

we still recommend to use a different node provider

What can I use? Do you have a suggestion?
Can I do it with Moralis?