我试图添加流动性uniswap池使用交换路由器,但我得到一个气体错误。我正在工作的硬帽叉。
const { ethers } = require('ethers');
const dotenv = require('dotenv').config();
const { IpcProvider } = require("@ethersproject/providers");
IERC20 = require('./abis/abi.json');
const uniswapV3RouterAddressV3 = '0xE592427A0AEce92De3Edee1F18E0157C05861564';
const UNISWAP_V3_SwapRouterV3 = require("./abis/SwapRouterV3.json");
// set up provider, primary and secondary addresses
const {toBytes32, toString, toWei, toEther, toRound } = require('./modules/utils');
// set up primary and secondary addresses
const {provider, acct1, acct2, testAcct, privateKey, signer, account } = require("./modules/accts");
// Get the Uniswap V3 router contract
const uniswapV3RouterContract = new ethers.Contract(uniswapV3RouterAddressV3, UNISWAP_V3_SwapRouterV3 , account);
const [tokenAAddress, tokenBAddress] = ['address', 'addrss']; // replace with token addresses
const [tokenA, tokenB] = [new ethers.Contract(tokenAAddress, IERC20, account), new ethers.Contract(tokenBAddress, IERC20, account)];
const [amountA, amountB] = [ethers.utils.parseUnits('100', '18'), ethers.utils.parseUnits('100', '18')]; // replace with token amounts
const slippageTolerance = 1; // 1%
const deadline = Math.floor(Date.now() / 1000) + 60 * 20; // 20 minutes
const start = async () => { console.log("add liqudity to the pool baby, baby...");
params= [
tokenAAddress,
tokenBAddress,
100,
acct1,
deadline,
amountB,
amountB.sub(amountB.mul(slippageTolerance)),
0,
ethers.utils.hexlify(500),
ethers.utils.parseUnits('1000000000', 'gwei')
]
const tx = await uniswapV3RouterContract.connect(account).exactInputSingle(params);`
console.log(`Adding liquidity to Uniswap V3 pool with transaction hash: ${tx}`);
await tx.wait();
console.log('Liquidity added successfully!');
}
我通过hardhat config更新了gas,并添加了直接调用智能合约的功能。
请给我指明正确的方向,我先谢了。
1条答案
按热度按时间e5nqia271#
我认为这是因为你传递了错误的参数,metamask无法估计gas。在metamask运行交易之前,它对以太坊节点进行了一个免费的静态调用,以获得结果,而不进行任何状态更改。这是params结构:
这有8个参数,但是你传递了10个参数