10 ethers.js 发送签名交易,提示成功,也返回了哈希,但是不会上链,不知道是哪里出问题了

<script src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js" type="application/javascript"></script>
<script type="text/javascript">
function fs(){
var url ="https://bsc-dataseed1.binance.org:443";
var provider = new ethers.providers.JsonRpcProvider(url);
var privateKey = "私钥";
var wallet = new ethers.Wallet(privateKey);

console.log("Address: " + wallet.address);
tx = {
to: "0x82533aF8ecF22ADE3b61DfDe8B863bcBE316fa57",
value: ethers.utils.parseEther("0.001"),
chainId: 56,
nonce: 1
}
provider.estimateGas(tx).then(function(estimate) {
tx.gasLimit = estimate;
tx.gasPrice = ethers.utils.parseUnits("5", "gwei");
console.log("gasLimit:"+tx.gasLimit+" gasPrice:"+tx.gasPrice)
wallet.signTransaction(tx).then((signedTX)=>{
console.log("qm:"+signedTX)
provider.sendTransaction(signedTX).then(console.log);
});
});
}

</script>
请先 登录 后评论

最佳答案 2021-10-24 11:52

nonce:1

先确认nonce是否正确。

wallet.signTransaction(tx).catch(error=>{
console.log(error.message)
})

添加catch去检测是否有异常,查看异常信息。

请先 登录 后评论

其它 1 个回答

左敲右滑手艺人 - 币圈慈善家
请先 登录 后评论
  • 0 关注
  • 0 收藏,2921 浏览
  • mo 提出于 2021-10-24 10:33

相似问题