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)
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)