-
i am deploying the 04-mint.js for mint the NFT, requestNft is emitting the event, but when i use hardhat to mint it in the local enviroment, i don't get the requestId event NftRequested(uint256 indexed requestId, address indexed requester);
function requestNft() public payable returns (uint256 requestId) {
// Pay some mintfee to mint NFT
if (msg.value < i_mintFee) {
revert RandomIpfsNft__NeedMoreETHSent();
}
requestId = i_vrfCoordinator.requestRandomWords(
i_gasLane,
i_subscriptionID,
REQUEST_CONFIRMATIONS,
i_callbackGasLimit,
NUM_WORDS
);
// create a mapping between people who call the requestNft and requestId
// so when we fulfillRandomWords we properly assign the dogs to them
s_requestIdToSender[requestId] = msg.sender;
emit NftRequested(requestId, msg.sender);
} The requestNft is executed, and trnasaction satus is success, but i cant get any indexed parameter from logs // Random IPFS NFT
const randomIpfsNft = await ethers.getContract("RandomIpfsNFT", deployer);
const mintFee = await randomIpfsNft.getMintFee();
const randomIpfsNftMintTx = await randomIpfsNft.requestNft({
value: mintFee,
});
console.log(randomIpfsNft.target);
const randomIpfsNftMintTxReceipt = await randomIpfsNftMintTx.wait(1);
// Check if the transaction status is successful
if (randomIpfsNftMintTxReceipt.status === 1) {
console.log("Transaction successful!");
} else {
console.error(
"Transaction reverted or failed. Check the transaction receipt for details."
);
}
// Need to listen for response
await new Promise(async (resolve, reject) => {
setTimeout(() => reject("Timeout: 'NFTMinted' event did not fire"), 300000); // 5 minute timeout time
// setup listener for our event
randomIpfsNft.once("NftMinted", async () => {
console.log(
`Random IPFS NFT index 0 tokenURI: ${await randomIpfsNft.tokenURI(0)}`
);
resolve();
});
if (chainId == 31337) {
// from receipt we can get our event log
const requestId =
randomIpfsNftMintTxReceipt.logs[0].args.requestId.toString();
const vrfCoordinatorV2Mock = await ethers.getContract(
"VRFCoordinatorV2Mock",
deployer
);
await vrfCoordinatorV2Mock.fulfillRandomWords(
requestId,
randomIpfsNft.target
);
}
}); error:TypeError: Cannot read properties of undefined (reading 'requestId') my github repo for my code: https://github.com/BOBSTRONK/hardhat_NFT/tree/main The code works with sepolia testNetwork, but not locally with hardhat network, because i cant read requestId from event Please help, thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
for who is encouting the same problem i had, you should replace randomIpfsNftMintTxReceipt.logs[0].args.requestId.toString(); |
Beta Was this translation helpful? Give feedback.
for who is encouting the same problem i had, you should replace randomIpfsNftMintTxReceipt.logs[0].args.requestId.toString();
to randomIpfsNftMintTxReceipt.logs[1].args.requestId;
Because it will be the second event after requestRandomWords, because requestRandomWords will emit a event too.