So... I tinkered with my my problem.
Apparently, the core problem is that my deployed Rinkeby contract doesn't work as expected for some reason while the very same contract instantiated via hardhat console works perfectly.
Function in a deployed contract shows empty event while the same function in a contract instantiated via hardhat console works as expected and shows the correct event data.
Apr 29, 2022, 4:10 PM
Ok. So I'll try to be concise and to the point from now.
Sorry for previous messages being uninformative.
1. I deploy the contract in hardhat console and interact with the function.
Everything runs smoothly.
hardhat console
...
> const Voting = await ethers.getContractFactory("Voting");
undefined
> const voting = await Voting.deploy();
undefined
> await voting.deployed();
...
> (await (await voting.addVoting()).wait()).events[0].args[0];
0
I get the expected 0 from the event.
2. I deploy the contract to Rinkeby and try to get the same output.
I fail.
hh run scripts/deploy.js --network rinkeby
Voting deployed to: 0xCaf1C1AA53D3513ec2d96A85f830EA5B89e53aFe
...
hh console
...
> const Voting = await ethers.getContractFactory("Voting");
undefined
> const voting = await Voting.attach("0xCaf1C1AA53D3513ec2d96A85f830EA5B89e53aFe");
undefined
> (await (await voting.addVoting()).wait()).events[0].args[0];
Uncaught TypeError: Cannot read properties of undefined (reading 'args')
at processTimers (node:internal/timers:502:7)
at listOnTimeout (node:internal/timers:528:9)
at runNextTicks (node:internal/process/task_queues:65:3)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at REPL22:1:76
Why could this happen?
My deploy script:
const hre = require("hardhat");
const main = async () => {
[owner] = await ethers.getSigners();
const Voting = await hre.ethers.getContractFactory("Voting");
const voting = await Voting.connect(owner).deploy();
await voting.deployed();
console.log("Voting deployed to:", voting.address);
}
const runMain = async () => {
try {
await main();
process.exit(0);
} catch (error) {
console.log(error);
process.exit(1);
}
};
runMain();
Sorry for previous messages being uninformative.
1. I deploy the contract in hardhat console and interact with the function.
Everything runs smoothly.
hardhat console
...
> const Voting = await ethers.getContractFactory("Voting");
undefined
> const voting = await Voting.deploy();
undefined
> await voting.deployed();
...
> (await (await voting.addVoting()).wait()).events[0].args[0];
0
I get the expected 0 from the event.
2. I deploy the contract to Rinkeby and try to get the same output.
I fail.
hh run scripts/deploy.js --network rinkeby
Voting deployed to: 0xCaf1C1AA53D3513ec2d96A85f830EA5B89e53aFe
...
hh console
...
> const Voting = await ethers.getContractFactory("Voting");
undefined
> const voting = await Voting.attach("0xCaf1C1AA53D3513ec2d96A85f830EA5B89e53aFe");
undefined
> (await (await voting.addVoting()).wait()).events[0].args[0];
Uncaught TypeError: Cannot read properties of undefined (reading 'args')
at processTimers (node:internal/timers:502:7)
at listOnTimeout (node:internal/timers:528:9)
at runNextTicks (node:internal/process/task_queues:65:3)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at REPL22:1:76
Why could this happen?
My deploy script:
const hre = require("hardhat");
const main = async () => {
[owner] = await ethers.getSigners();
const Voting = await hre.ethers.getContractFactory("Voting");
const voting = await Voting.connect(owner).deploy();
await voting.deployed();
console.log("Voting deployed to:", voting.address);
}
const runMain = async () => {
try {
await main();
process.exit(0);
} catch (error) {
console.log(error);
process.exit(1);
}
};
runMain();
I didn't pass the --network rinkeby in calls to hh and that was the issue :)
Solved it myself.
Solved it myself.
Apr 29, 2022, 5:00 PM
because of (await (await voting.addVoting()).wait()).events[0].args[0];
assign the .wait() to a var and seek for events on it, even if hardhat still kinda "bugged"? i think? about events.
Sometimes it get them, sometimes it print out undefined 🤷♂️
assign the .wait() to a var and seek for events on it, even if hardhat still kinda "bugged"? i think? about events.
Sometimes it get them, sometimes it print out undefined 🤷♂️
Apr 29, 2022, 5:41 PM