Here is an article with a solution:
Ethereum: “Myevent” is not set in the “Web3.JS
GetPastenti” function
The “Myevent” function does not seem to settle correctly when you try to recover the past events using the “GetPastevents” function of the official web3.Js.
problem
In order to solve this problem, you need to specify the name of the event you want to recover as a subject for the “GetPastevents” function. However, in your case, try to use a dynamic variable (Myevent
) without specifying its type or initialization.
Solution
It is possible to solve this problem by using the Inhabitis form and defining the event contract before creating an application for the web3.JS supplier with specific ABI (the binary interface of the application). Here is an updated code fragment:
JavaScript
// Define the ABI event contract
Constant CONCE = {
Methods: {
Myevent: "Myevent"
}
};
// initializes the web3.JS supplier with the specified inhabitant
Const web3 = New Web3 (New Web3.prideers.httpProvider (
"
));
// Define the Eventi and ABI contract address
Constantant constant = "0x ..."; // replace with contract address
Constatabi = [...]; // replace with ABI of the contract
// use the GetPastententi function
Web3.eth.Getpastevents (Contracting, {
From: Web3.utils.onumber (web3.etth.abiaddr [0] .Resing),
Block: Web3.utils.Tonumber (web3.etth.abiaddr [0]. Address)
}, (er, events) => {
If (! Er) {
Console.log (events);
} others {
Console.error (er);
}
});
Note
- Replace
your_project_id
with your influence ID.
- Ensure the ABI Event contract is defined and available correctly in applying the web3.JS supplier
- Update the name of the event (`Myevent ‘) to combine the signature of the event contract method.
Following these steps, you should be able to solve this problem and recover the past events using Web3.Js.