10 熊哥你好,调用uniswap路由合约addLiquidityETH方法,The called function should be payable if you send value and the value you send should be less than your current balance

我是使用的remix的内置账户,并且在上面部署了,工厂,路由,weth,和一个token的合约。
内置账户地址:0x5B38Da6a701c568545dCfcB03FcB875f56beddC4
ETH余额:99.9999
image.png
token余额:100000000
image.png
理论上这个地址的余额是足够的,然后我去调用合约就报错

image.png

image.png
我这个应该如何做才能成功添加流动性呢?

请先 登录 后评论

最佳答案 2023-04-24 15:06

是我忘记授权了,我需要把token去授权给合约 一定数量的才可以成功添加流动性,不知道是不是这样的原因,反正我是这么操作就成功了。。。。

第一步:将token授权给合约

image.png
第二部:添加流动性

image.png

image.png

思考一个问题?
这里我是只添加了一种 token兑换ETH的,所以只授权了一次。
如果我是2个token相互兑换,那么我就得对2个token进行授权咯?

请先 登录 后评论

其它 2 个回答

lanyangkj

“第一步:将token授权给合约”。
请问下您说的这个token应该授权给哪个合约呀? UniswapV2Router02??还是UniswapV2Factory??或者UniswapV2Pair??
我现在只要一点击添加流动性:addLiquidity()就得报错:
revert
The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
You may want to cautiously increase the gas limit if the transaction went out of gas.
不知道是什么原因??
另外: 这个UniswapV2ERC20.sol是做什么用的?在什么时候会用到?

请先 登录 后评论
lanyangkj

另外,我的输出里还有个这错误。
{
"error": "Failed to decode output: Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.7.0)"

请先 登录 后评论
  • 3 关注
  • 0 收藏,2411 浏览
  • 二狗 提出于 2023-04-24 10:43