Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The hardhat node subscription event is not working #5146

Closed
yinchonging opened this issue Apr 19, 2024 · 2 comments
Closed

The hardhat node subscription event is not working #5146

yinchonging opened this issue Apr 19, 2024 · 2 comments
Assignees
Labels
status:needs-more-info There's not enough information to start working on this issue

Comments

@yinchonging
Copy link

Version of Hardhat

2.22.2

What happened?

The hardhat node subscription event is not working

Minimal reproduction steps

Step1 (Start hardhat node):

企业微信截图_17135210739300

Step2 (Deploy contract):

企业微信截图_17135211626567

Step3 (Add listener):

企业微信截图_1713521884975

Step4 (Hardhat logs show that the subscription was successful):

企业微信截图_17135212476053

Step5(The event was not emitted after being called):

企业微信截图_17135214145185

How to solve this problem? Thanks!!!

Search terms

No response

@schaable
Copy link
Contributor

schaable commented May 6, 2024

Hi @yinchonging, I followed the above steps using this code with the Lock sample contract and was able to get the log output. It looks like the function selector is not being recognized, and, as such, the transaction is reverting. Are you sure you're calling the right method? Can you provide a minimal reproducible example?

import { ethers, artifacts } from "hardhat";
import { time } from "@nomicfoundation/hardhat-toolbox/network-helpers";

const JAN_1ST_2030 = 1893456000;

async function main() {
  const abi = (await artifacts.readArtifact("Lock")).abi;
  const wsprovider = new ethers.WebSocketProvider("ws://127.0.0.1:8545/");
  const signer = await wsprovider.getSigner();
  const wscontract = new ethers.Contract(
    "0x5FbDB2315678afecb367f032d93F642f64180aa3",
    abi,
    signer
  );

  await time.increaseTo(JAN_1ST_2030 + 1);

  await wscontract.on("Withdrawal", (amount, when) => {
    console.log(`Withdrawal of ${amount} at ${when}`);
  });

  const txResponse = await wscontract.withdraw();
  await txResponse.wait();
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

@schaable schaable added status:needs-more-info There's not enough information to start working on this issue and removed status:triaging labels May 6, 2024
@schaable
Copy link
Contributor

Hi @yinchonging, I'm closing this issue for now since the example you provided seems to be working on my end and we haven't received any additional information from you. I'm happy to reopen it if you can provide more details. Thanks!

@schaable schaable closed this as not planned Won't fix, can't repro, duplicate, stale May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:needs-more-info There's not enough information to start working on this issue
Projects
Status: Done
Development

No branches or pull requests

2 participants