我正在尝试使用Uniswap v2接口交换令牌。合同的代码是这里。
我可以将Eth保存到合同中,但是我无法通过javascript成功地调用swapEthForTokenWithUniswap()。
const swap = async() => {
const res = await defitry.methods.swapEthForTokenWithUniswap(web3.utils.toWei('0.1', 'ether'))
.send({from:acc.address,
gas: 100000})
console.log(res)
}事务保持倒转,但我可以使用以太扫描上的writeContract选项卡调用函数和交换。我一直在找Object.TransactionRevertedWithoutReasonError
发布于 2020-06-27 03:55:21
我想是因为你所通过的气体限制。如果你看一个成功交易,它实际上消耗了222750个气体,所以你需要调整你的限制或者使用estimateGas函数。
我注意到的另一件事是,使用合同中的now作为最后期限使用是一种安全风险。截止日期时间戳应该从前端传递,因为now总是矿工包含事务的时间。还请参阅我的博客帖子以获得更多详细信息。
https://ethereum.stackexchange.com/questions/84571
复制相似问题