[英]How to get a transaction receipt once minting is done
我正在使用 React 構建我的 NFT Minting DApp 的前端。
我試圖在創建事務后在控制台中打印到 etherscan/hash 的 URL,但是當事務開始時我得到了日志,所以它在 etherscan 中不可用。
我檢查了其他網站,但沒有一個足夠確鑿。
鑄幣過程完成后如何獲得交易收據?
try {
ethereum
.request({
method: "eth_sendTransaction",
params: [tx],
})
.then(
async (result) =>
{
let nftTxn = await nftContract.safeMint;
console.log("Minting... please wait");
web3.eth.getTransactionReceipt(result)
.then(console.log(`Mined, see transaction: https://ropsten.etherscan.io/tx/${result}`));
}
)
最后,我做到了。 我決定使用間隔。 來源: 這里
if (result!=null){
const interval = setInterval(()=>{
console.log("Attempting to get transaction receipt...");
web3.eth.getTransactionReceipt(result, function(err, rec){
if (rec) {
console.log(`See transaciton in https://ropsten.etherscan.io/tx/${rec.transactionHash}`);
clearInterval(interval);
} else {
console.log(err);
}
});
}, 1000);
}
沒有可以訂閱的聽眾嗎?
web3.eth.subscribe("alchemy_fullPendingTransactions")
我在 web3js 中這樣做的方式是這樣的, transactionHash
將很快被注銷,然后收據就會到達。
myContract.methods
.myMethod(123)
.send({ from: "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe" })
.on("transactionHash", function (hash) {
console.log("transactionHash", hash);
})
.on("confirmation", function (confirmationNumber, receipt) {
console.log("confirmationNumber", confirmationNumber);
console.log("receipt", receipt);
})
.on("receipt", function (receipt) {
// receipt example
console.log(receipt);
})
.on("error", function (error, receipt) {
// If the transaction was rejected by the network with a receipt, the second parameter will be the receipt.
console.log("error", error);
console.log("receipt", receipt);
});
https://web3js.readthedocs.io/en/v1.7.0/web3-eth-contract.html#id37
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.