获取全局var hardhat Console

发布于 2025-02-01 20:10:49 字数 1086 浏览 2 评论 0原文

嗨,我正在尝试在Hardhat Console测试我的合同。我可以很好地运行我的功能,但是当我尝试阅读公共全局var时,它会引发错误。

因此:例如:

    uint256 public testVar;

   function setInt(uint256 _intset) external {
        testVar = _intset;
    }

然后在成功运行的factory。setint(123)之后,在我运行的控制台中:

等待factory.testvar(),

但是由于某些原因,我会收到错误消息:

Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="testVar()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.6.3)
    at step  {
  reason: null,
  code: 'CALL_EXCEPTION',
  method: 'testVar()',
  data: '0x',
  errorArgs: null,
  errorName: null,
  errorSignature: null,
  address: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
  args: [],
  transaction: {
    data: '0x9c328fb3',
    to: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
    from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
    gasLimit: BigNumber { value: "29021272" }
  }
}

任何想知道为什么我不能简单地获得这个公共var?

值得注意的是,如果我尝试跑步

工厂

等待

Hi I am trying to test my contract in hardhat console. I am able to run my functions just fine but when I try to read a public global var it throws an error.

So for example:

    uint256 public testVar;

   function setInt(uint256 _intset) external {
        testVar = _intset;
    }

Then after successfully runnign await factory.setInt(123) in the console I run:

await factory.testVar()

But then for some reason I get the error message:

Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="testVar()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.6.3)
    at step  {
  reason: null,
  code: 'CALL_EXCEPTION',
  method: 'testVar()',
  data: '0x',
  errorArgs: null,
  errorName: null,
  errorSignature: null,
  address: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
  args: [],
  transaction: {
    data: '0x9c328fb3',
    to: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
    from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
    gasLimit: BigNumber { value: "29021272" }
  }
}

Any idea why i cannot simply get this public var?

Worth noting if i try run

await factory.testVar without the param it just says

[Function (anonymous)]

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫腻 2025-02-08 20:10:49

对将来阅读本文的任何人。我的问题是,在我的HardHat配置文件中,我从未配置过我的帐户:

因此,一旦设置:

accounts: [process.env.private_key]

它可以正常工作。

瓦格米

To anyone in the future who is reading this. My problem was that in my hardhat config file I never configured my accounts:

So once I set:

accounts: [process.env.private_key]

It works fine.

WAGMI

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文