'react web3 parse and store a transaction [receipt value] from returnValues
I have a minting Dapp in progress using Hashlips github repo. I've succesfully minted using the dapp and after the mint transaction is complete, I send the transaction receipt into the console log.
Inside the transaction receipt we have the events > transfer > returnValues. I want to read a specific return value and store that so I can use this value in another function.
Essentially inside returnValues I have stored a tokenID:'xnumberhere' and I need to use that for putting together images which I'll upload to IPFS.
How do I parse through receipt to save specific object data such as TokenID or even a parent such as blockNumber / blockHash
Current functions - see line 23/24 for logging the receipt
See this image of the console log where I want to retrieve tokenID
const claimNFTs = () => {
let cost = CONFIG.WEI_COST;
let gasLimit = CONFIG.GAS_LIMIT;
let totalCostWei = String(cost * mintAmount);
let totalGasLimit = String(gasLimit * mintAmount);
console.log("Cost: ", totalCostWei);
console.log("Gas limit: ", totalGasLimit);
setFeedback(`Minting your ${CONFIG.NFT_NAME}...`);
setClaimingNft(true);
blockchain.smartContract.methods
.mintNFT(mintAmount)
.send({
gasLimit: String(totalGasLimit),
to: CONFIG.CONTRACT_ADDRESS,
from: blockchain.account,
value: totalCostWei,
})
.once("error", (err) => {
console.log(err);
setFeedback("Sorry, something went wrong please try again later.");
setClaimingNft(false);
})
.then((receipt) => {
console.log(receipt);
setFeedback(
`WOW, the ${CONFIG.NFT_NAME} is yours! go visit Opensea.io to view it.`
);
setClaimingNft(false);
dispatch(fetchData(blockchain.account));
getData();
});
};
Solution 1:[1]
To retrieve the events response of my Mint transaction, I used the following:
var tokenId = receipt.events.Transfer.returnValues.tokenId
console.log("Your NFT ID is: " + receipt.events.Transfer.returnValues.tokenId);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Imtryingbigtime |
