【发布时间】:2021-12-25 02:05:18
【问题描述】:
我正在尝试使用 ethers.js 将交易发送到多边形网络。提交交易后,我await tx.wait(),但 50% 的时间都无法解决。我看到其他人也有类似的问题,但由于他们的汽油价格太低。我目前有这个代码:
const getWallet = (): Wallet => {
return new ethers.Wallet(PRIVATE_KEY, HTTP_PROVIDER);
};
const wallet = getWallet();
const gasPrice = 50000000000;
const swap1 = await wallet.sendTransaction({
data: tx1.data,
chainId: tx1.chainId,
from: tx1.from,
gasLimit: 350449,
gasPrice: gasPrice,
value: '0x' + new BigNumber(tx1.value).toString(16),
to: tx1.to,
nonce: nonce,
});
我总是返回一个具有 tx 哈希的对象,但是当我在 polyscan 上查找该哈希时,它从未出现。有时等待长达一个小时后 tx.wait() 仍然没有解决,并且事务仍然没有出现在 polyscan 中。我取消了我的脚本,将 gasPrice 提高了 20%,然后尝试使用相同的 nonce 再次运行它(希望能够替换它)。那时我通常会被告知更换汽油费太低。有人可以解释一下我在这里做错了什么吗?
【问题讨论】:
标签: blockchain web3 web3js ethers.js