getPastEvents , event is undefined

I have migrated a contract using truffle to Rinkeby through Infura, it went up successfully, and I can interact with it in our dApp using Web3js v0.20.7, specifically the Events.

I would also like to query events using node on a scheduler, so I have this using web3 v1.2.2

const Web3 = require(“web3”);
var cryptozArtifact = require(’./Cryptoz.json’)
const rinkebyCryptoz = “0x822ee9b5d26a45a37885dd2b5a56c45b710c9548”;

let web3 = new Web3(
// Replace YOUR-PROJECT-ID with a Project ID from your Infura Dashboard
new Web3.providers.WebsocketProvider(“wss://rinkeby.infura.io/ws/v3/MY_PROJECT_ID”)
);

const instance = new web3.eth.Contract([cryptozArtifact], rinkebyCryptoz);

instance.getPastEvents(
“AllEvents”,
{ fromBlock: 0, toBlock: “latest” },
(errors, events) => {
if (!errors) {
// process events
console.log(events);
//console.log(JSON.stringify(events, null, 4));
}
}
);

The event logs look like this

{
address: ‘0x822eE9b5D26a45a37885dd2B5A56C45b710C9548’,
blockHash: ‘0x575e4ab2e174e2a1ea24fea3a434c083ec9aa53b3154f5c1fb5344faf4d6fe51’,
blockNumber: 7319169,
logIndex: 2,
removed: false,
transactionHash: ‘0xf4c9b02e451c0e63c1bf66a19869c938f6419e9c37aec01537c3ebce247337b5’,
transactionIndex: 2,
id: ‘log_e00cafdb’,
returnValues: Result {},
event: undefined,
signature: null,
raw: {
data: ‘0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b42726f776e204c656d7572000000000000000000000000000000000000000000’,
topics: [Array]
}
},

and I can’t filter by events I have emitted like LogCardCreated

Error: Event “LogCardCreated” doesn’t exist in this contract.

Any ideas ? thanks !

1 Like

Thanks @Eth_4Life for joining the community. Can you provide the full error response you’re getting when trying to access the logs on mainnet?

Hi Mike, thank you.
These contracts are not deployed on Mainnet, as they are still being developed on Rinkeby. Should we deploy on an alternative Ethereum Test network ?

Sorry about that should have deducted that from your URL, I don’t believe rinkeby would be the issue here, but if you have the full error response that would help us diagnose the issue.

no worries,

so when I console.log(errors), it is null. and the events contains over 167 objects, similar to what I have pasted above. Here are 2 more random ones.

You can access the JSON interface file here : https://github.com/ryanprice/Cryptoz.cards-Dapp/blob/master/src/contracts/Cryptoz.json

{
address: ‘0x822eE9b5D26a45a37885dd2B5A56C45b710C9548’,
blockHash: ‘0x995711f1671278d7fa0e177dc38469ac479f8c9bb3c3acfa5c3fd1e5f9c93561’,
blockNumber: 7319146,
logIndex: 5,
removed: false,
transactionHash: ‘0x3ced58b98ac9dccbbfafb2a597bd03f6716587016f6d22b5dd66425ca165925c’,
transactionIndex: 5,
id: ‘log_299ccb9a’,
returnValues: Result {},
event: undefined,
signature: null,
raw: {
data: ‘0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000454696e7900000000000000000000000000000000000000000000000000000000’,
topics: [Array]
}
},
{
address: ‘0x822eE9b5D26a45a37885dd2B5A56C45b710C9548’,
blockHash: ‘0x995711f1671278d7fa0e177dc38469ac479f8c9bb3c3acfa5c3fd1e5f9c93561’,
blockNumber: 7319146,
logIndex: 6,
removed: false,
transactionHash: ‘0x59549aae11a98cbbe5517cb34a9b256f03d0d6ab9cad52f0f6abc7a457a127a4’,
transactionIndex: 6,
id: ‘log_59a41230’,
returnValues: Result {},
event: undefined,
signature: null,
raw: {
data: ‘0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000015426c6f6f647920486f72726f727320436173746c650000000000000000000000’,
topics: [Array]
}
},

maybe this will help too

/home/rprice/Downloads/cryptoz-cards-server/node_modules/web3-eth-contract/src/index.js:546
throw new Error(‘Event "’ + eventName + ‘" doesn’t exist in this contract.’);
^

Error: Event “LogCardCreated” doesn’t exist in this contract.
at Contract._generateEventOptions (/home/rprice/Downloads/cryptoz-cards-server/node_modules/web3-eth-contract/src/index.js:546:15)
at Contract.getPastEvents (/home/rprice/Downloads/cryptoz-cards-server/node_modules/web3-eth-contract/src/index.js:661:49)
at Object. (/home/rprice/Downloads/cryptoz-cards-server/getEvents.js:20:10)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11

@Eth_4Life,

This seems to be an issue with web3.js, the data returns correctly when I query for it directly:

$ wscat -c wss://rinkeby.infura.io/ws/v3/MY-PROJECT-ID
connected (press CTRL+C to quit)
> {"jsonrpc":"2.0", "id": 1123123, "method": "eth_getLogs", "params": [{"address": "0x822eE9b5D26a45a37885dd2B5A56C45b710C9548", "topics":["0xd56e3675590b3a0ffa7898c8a21c1dc687046d1a54c8d9d28c3e429e51f5670c"], "fromBlock":"0x0", "toBlock":"latest"}]}

I get back the results included at https://gist.github.com/ryanschneider/4d370396eeba2edcb2422c715ede7b10

I’m not terribly familiar w/ web3.js but it sounds like it didn’t properly parse your ABI file, I would suggest checking for similar issues on their github: https://github.com/ethereum/web3.js/issues?q=is%3Aissue+is%3Aopen+getPastEvents

Awesome, ok this will help, at least with my sanity :slight_smile: I will go try out some stuff and maybe some other versions of web3j too. I’ll come back and post here when I find a solution. Really appreciate the replies and support here guys.

Just to follow up in case this helps someone else. I could not figure out how to get the data I wanted in web3js, so I switched to https://docs.ethers.io/v5/ and everything is working great. Thanks everyone for the feedback, consider this resolved.

1 Like