[英]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.