hradhat调试合约无法获取事件

部署了VRFCoordinatorV2Mock合约之后,调用createSubscription方法后,获取合约事件却返回undefined。具体代码如下: `const Mock = await ethers.getContractFactory("VRFCoordinatorV2Mock"); const mock = await Mock.deploy(baseFee, gasPriceLink); await mock.waitForDeployment();

const subscribId = await mock.createSubscription();
const subscribReceipt:any = await subscribId.wait(1);
console.log(subscribReceipt);
console.log(subscribReceipt.events);`

最后通过打印,subscribReceipt能够正常返回,但是该对象里面并没有events属性,但是Chainlink的官方文档却可以通过tx.events[0].topics[1]获取事件属性?hardhat返回结果如下: `

ContractTransactionReceipt { provider: HardhatEthersProvider { _hardhatProvider: LazyInitializationProviderAdapter { _providerFactory: [AsyncFunction (anonymous)], _emitter: [EventEmitter], _initializingPromise: [Promise], provider: [BackwardsCompatibilityProviderAdapter] }, _networkName: 'hardhat', _blockListeners: [], _transactionHashListeners: Map(0) {}, _eventListeners: [] }, to: '0x5FbDB2315678afecb367f032d93F642f64180aa3', from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', contractAddress: null, hash: '0x833ee48c469bfb861950029f41fcc3e40454c965bcec4317786e12e1a9df0235', index: 0, blockHash: '0x710fe3351c7052776fe03982eeb6df63a1dd8449c1489c9408e90275804c735c', blockNumber: 2, logsBloom: '0x00000000000000000000010000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000040000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000040000000200000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000', gasUsed: 68657n, cumulativeGasUsed: 68657n, gasPrice: 1787294237n, type: 2, status: 1, root: undefined } undefined // console.log(subscribReceipt.events)

请先 登录 后评论

最佳答案 2023-12-12 22:32

这是使用版本不同造成的问题。 const subscribId = await mock.createSubscription(); const subscribReceipt:any = await subscribId.wait(1); const subId = subscribReceipt.logs[0].args[0]; 通过上诉代码可以得到events,具体原因是因为以太坊 v6 与V5调用方法不同。在 v5 中,事件是交易收据的一部分,但在 v6 中不是。而且它在 v5 到 v6 的迁移文档中没有出现。这真的非常该死,让我白白浪费了很多时间。

请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 0 收藏,1135 浏览
  • 小小怪 提出于 2023-12-12 16:40