[SOLVED] MORALIS API - Bad Request(400): abi is not a valid ABI - getContractEvents

Hello,

I’m trying to get events by contracts using the EVM EVENTS API. Running the code in TS I’m getting

Moralis SDK Core Error: [C0006] Request failed, Bad Request(400): abi is not a valid ABI

Running the same cfg in swagger I got status code 200 with the right information.

I’ve sent the ABI in differents formats but I still get the same error.

Here is the code:

import { EvmChain } from "@moralisweb3/common-evm-utils";

const runApp = async () => {
  await Moralis.start({
    apiKey: "API_KEY",
  });

  const address: string = '0xFC208080Fe91b12A0dE42373Fd6062FC218baE31';
  const chain: EvmChain = EvmChain.GOERLI;
  const abi = [
    {
      "anonymous": false,
      "inputs": [
        {
          "indexed": true,
          "internalType": "address",
          "name": "nftAddress",
          "type": "address"
        },
        {
          "indexed": false,
          "internalType": "address",
          "name": "assetOwner",
          "type": "address"
        },
        {
          "indexed": true,
          "internalType": "uint256",
          "name": "tokenId",
          "type": "uint256"
        },
        {
          "indexed": false,
          "internalType": "uint256",
          "name": "quantity",
          "type": "uint256"
        },
        {
          "indexed": false,
          "internalType": "address",
          "name": "buyer",
          "type": "address"
        },
        {
          "indexed": true,
          "internalType": "uint256",
          "name": "price",
          "type": "uint256"
        },
        {
          "indexed": false,
          "internalType": "uint256",
          "name": "fee",
          "type": "uint256"
        }
      ],
      "name": "BuyAsset",
      "type": "event"
    }
  ]

  const topic = "BuyAsset(address,address,uint256,uint256,address,uint256,uint256)"

  const response = await Moralis.EvmApi.events.getContractEvents({
    address,
    chain,
    abi,
    topic
  });

  console.log(response.toJSON());
}

runApp();

Response in swagger

{
  "total": 3,
  "page": 0,
  "page_size": 100,
  "result": [
    {
      "transaction_hash": "0x0f29b3afe9883e6e723dc929352b30edbd339a1efc92518cdbbad0b45c4d0d31",
      "address": "0xfc208080fe91b12a0de42373fd6062fc218bae31",
      "block_timestamp": "2022-12-06T21:19:24.000Z",
      "block_number": "8087747",
      "block_hash": "0xeb9cdd30d15bd0d9df5de4b3624eb85ce09fb3efb8e60cb0e02ba29c37886925",
      "data": {
        "nftAddress": "0xd17abebadaaeb8ba0457ec929e2766d505b20e7b",
        "assetOwner": "0xbc4226e82b794672a150837b7637726711a5c463",
        "tokenId": "1",
        "quantity": "1",
        "buyer": "0x562e01f354a1914688ad67f27862a5bf92dba6b6",
        "price": "100000000000000",
        "fee": "5000000000000"
      }
    },
    {
      "transaction_hash": "0x986170dada1798ff070aa11dbef2d9b441d2be0f2197df53b20717675d0be9eb",
      "address": "0xfc208080fe91b12a0de42373fd6062fc218bae31",
      "block_timestamp": "2022-12-06T21:17:36.000Z",
      "block_number": "8087738",
      "block_hash": "0x4baa4e293c5d343304107084f5a112f620a26b68231f5a8f04047262361c95e7",
      "data": {
        "nftAddress": "0xd17abebadaaeb8ba0457ec929e2766d505b20e7b",
        "assetOwner": "0xbc4226e82b794672a150837b7637726711a5c463",
        "tokenId": "2",
        "quantity": "1",
        "buyer": "0x562e01f354a1914688ad67f27862a5bf92dba6b6",
        "price": "100000000000000",
        "fee": "5000000000000"
      }
    },
    {
      "transaction_hash": "0x0a82abf5ca34cd4c3007067a7c4b64be03095fcc4cd00abd8ee3725df32be4d1",
      "address": "0xfc208080fe91b12a0de42373fd6062fc218bae31",
      "block_timestamp": "2022-12-06T20:46:24.000Z",
      "block_number": "8087596",
      "block_hash": "0x79ff619d5ec3f3cd90bee5c495c19f1e29c3fba57dffd760ac79f331cc0499ba",
      "data": {
        "nftAddress": "0xd17abebadaaeb8ba0457ec929e2766d505b20e7b",
        "assetOwner": "0x562e01f354a1914688ad67f27862a5bf92dba6b6",
        "tokenId": "1",
        "quantity": "1",
        "buyer": "0xbc4226e82b794672a150837b7637726711a5c463",
        "price": "100000000000000",
        "fee": "5000000000000"
      }
    }
  ]
}

What version of the sdk you are using?
Did you try without those [] for the abi?

The version is “moralis”: “^2.8.2” , and yes I tried without [] , tried “true”/“false” as string for boolean as well.

I also tried these

"{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"nftAddress\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"assetOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"quantity\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"buyer\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"price\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"fee\",\"type\":\"uint256\"}],\"name\":\"BuyAsset\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"buyerFee\",\"type\":\"uint8\"}],\"name\":\"BuyerFee\",\"type\":\"event\"}"

I’ll check later to see if I can make it work.

I appreciate it :innocent:

It looks like an issue with the SDK for me now. I tried to console log what it sends to the api as POST data and it looks like it doesn’t send the abi.

in @moralisweb3\core\lib\controllers\RequestController.js in RequestController.prototype.post function I tried to add console.log

thanks for the answer, it is weird because swagger works as expected :frowning:

@cryptokid is there any way to report this to get a solution?

we identified the issue and we will have a fix for it

you could try with latest version of the SDK now

this could be the fix:

1 Like

I tried but I get the same error

Ok, I’ll check later

1 Like

it looks like what happened is that we didn’t release yet a new version for the sdk, the plan is to release it today

1 Like

Thanks for your help, it works now <3

1 Like

I’ve updated moralis to v ^2.11.0 and still having this issue. Can someone help, please?

Hey @teterabOb,

How does your ABI looks like in the code?

the syntax that works now is with an object for the abi and not with a list, as in with { } and not with [{ }]

I created a json file with the following code inside, as @cryptokid said just with {}

{
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "nftAddress",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "address",
        "name": "assetOwner",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "uint256",
        "name": "tokenId",
        "type": "uint256"
      },
      {
        "indexed": false,
        "internalType": "uint256",   
        "name": "quantity",
        "type": "uint256"
      },
      {
        "indexed": false,
        "internalType": "address", 
        "name": "buyer",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "uint256",
        "name": "price",
        "type": "uint256"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "fee",
        "type": "uint256"
      }
    ],
    "name": "BuyAsset", 
    "type": "event"
  }

So does it work now or do you still get any error with this format?

it is working fine, @cryptokid helped me to make it work

2 Likes