![](/img/trans.png)
[英]'code': -32603, 'message': 'Error: Transaction reverted without a reason string' while i'm trying to use swapExactTokensForTokens UNISWAP
[英]Uniswap swapRouter02 Error: Transaction reverted without a reason string
我正在測試uniswap的swap交易
我的新合約 swap() -> uniswap swapRouter02 contract exactInputSingle() 不是從錢包到合約交換
具體來說,下面的代碼正在嘗試將我的合約的 0.08 WETH 交換為某個 UNI。 我檢查了我的合同有 0.08 美元。
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 => WETH token address
0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984 => UNI token address
0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45 => Uniswap SwapRouter02 contract address
但是嘗試時出現錯誤消息
ISwapRouter02(0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45).exactInputSingle(params);
錯誤:事務在 ~~ 處無理由字符串還原
這個消息是什么意思? 以及如何調試此錯誤?
我的測試環境是安全帽本地分叉主網。 錯誤消息來自安全帽分叉主網
hardhat: {
chainId: 31337,
forking: {
url: `https://mainnet.infura.io/v3/${INFURA_API_KEY}`,
blockNumber: 14390000
},
},
function swap() external payable override lock returns (uint256) {
//approve
address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2).call(abi.encodeWithSelector(IERC20.approve.selector, 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45, 0x011C37937E080000));
//test
uint256 amountOut;
ISwapRouter02.ExactInputSingleParams memory params =
IV3SwapRouter.ExactInputSingleParams({
tokenIn: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,
tokenOut: 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984,
fee: 0,
recipient: msg.sender,
//deadline: _params.deadline,
amountIn: 0x011C37937E080000, //0.08
amountOutMinimum: 0x0,
sqrtPriceLimitX96: 0
});
ISwapRouter02(0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45).exactInputSingle(params);
return 1;
}
錯誤:無法估算氣體; 交易可能會失敗或可能需要手動限制氣體 [參見:https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT] (reason="Error: Transaction reverted without a reason string", method="estimateGas", transaction= {"from":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","to":"0xd5a946A0C214d732a8cf5678be593d26E1bf2170","data":"","accessList":null}, error={"name":"ProviderError","code":-32603 _isProviderError":true,"data":{"message":"Error: Transaction reverted without a reason string","data":"0x"}}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.8)
我發現我的錯了,原因是 amountOutMinimum 值必須不是 0x0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.