最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get events from a transaction receipt in hardhat - Stack Overflow

programmeradmin3浏览0评论

I have an ethers contract that I've made a transaction with:

const randomSVG = new ethers.Contract(RandomSVG.address, RandomSVGContract.interface, signer)
let tx = await randomSVG.create()

I have an event with this transaction:

function create() public returns (bytes32 requestId) {
        requestId = requestRandomness(keyHash, fee);
        emit requestedRandomSVG(requestId);
    }

However, I can't see the logs in the transaction receipt.]()

// This returns undefined
console.log(tx.logs)

I have an ethers contract that I've made a transaction with:

const randomSVG = new ethers.Contract(RandomSVG.address, RandomSVGContract.interface, signer)
let tx = await randomSVG.create()

I have an event with this transaction:

function create() public returns (bytes32 requestId) {
        requestId = requestRandomness(keyHash, fee);
        emit requestedRandomSVG(requestId);
    }

However, I can't see the logs in the transaction receipt.](https://docs.ethers.io/v5/api/providers/types/#providers-TransactionReceipt)

// This returns undefined
console.log(tx.logs)
Share Improve this question asked Sep 1, 2021 at 12:22 Patrick CollinsPatrick Collins 6,1316 gold badges35 silver badges73 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 19

When you create a transaction with Ethers.js, you get back a TransactionResponse that may not be included in the blockchain yet. Therefore it doesn't know what logs will be emitted.

Instead, you want to wait until the transaction is confirmed and you get back a TransactionReceipt. At this point the transaction was included in a block, and you can see which events were emitted.

const randomSVG = new ethers.Contract(RandomSVG.address, RandomSVGContract.interface, signer)
const tx = await randomSVG.create()
// Wait until the tx has been confirmed (default is 1 confirmation)
const receipt = await tx.wait()
// Receipt should now contain the logs
console.log(receipt.logs)
发布评论

评论列表(0)

  1. 暂无评论