getTransaction not found using Cloud Code

I am using a BSC node, and have the historical transactions plugin activated.

In the cloud code I am executing the code I found in the documentation:

const options = { chain: "bsc", address: LPaddress, order: "desc" };
const transactions = Moralis.Web3.getTransactions(options);

Where LPaddress is the LPaddress is the address of an LP token. I get the error that the function does not exist. Do I still need to add some sort of library? I am able to get my API key per the Web3 API documentation instructions, but there is no instruction for how to call this in the cloud code.

Hey @markyjennings

You can’t use Moralis.Web3.getTransactions(options) in Cloud Functions.
Instead you can call Web3 Api from the Cloud Functions. Exmaple of calling transactions:

Moralis.Cloud.define("getTransactions", async (request) => {
   return Moralis.Cloud.httpRequest({
      method: "GET",
      headers: {
        accept: "application/json",
        "X-API-Key": "xxxxxxxxxxxxxxxx",
      },
      url: `https://deep-index.moralis.io/api/historical/token/erc20/transactions?chain=matic&chain_name=mainnet&address=${params.userAddress}`,
    }).then(function (httpResponse) {
      return httpResponse.data;
    });
});

Also take a look at:

Hope this will help you :man_mechanic:

1 Like