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"
}
}
]
}