I would like to call exactInputSingle function of pancakeswap contract:
"function exactInputSingle(struct IV3SwapRouter.ExactInputSingleParams params) external payable returns (uint256 amountOut)"
But I have to pass an struct to call this function.
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
But ethersJs and web3.js doesn't support calling a function by passing a struct.
How to call the function?
I tried calling fnction by directly providing the value rather than a struct as suggested by someone but it didn't worked.
code:
const exactInputSingleParams = {
tokenIn: process.env.YING_ADDRESS_BSC,
tokenOut: process.env.YANG_ADDRESS_BSC,
fee: 500,
recipient: process.env.PUB_KEY,
amountIn: ethers.utils.parseUnits("1234.0", 18),
amountOutMinimum: ethers.utils.parseUnits("100.0", 18),
sqrtPriceLimitX96: 0,
};
const tx = await contractWithSigner.exactInputSingle(
exactInputSingleParams,
{
gasLimit: ethers.utils.hexlify(200000),
gasPrice: ethers.utils.parseUnits("10", "gwei"),
}
);
error:
Error: unexpected character at position 44 (argument="param", value="struct IV3SwapRouter.ExactInputSingleParams params", code=INVALID_ARGUMENT, version=abi/5.7.0)
at Logger.makeError (D:\trading bot\0xArbi-bot\node_modules\@ethersproject\logger\lib\index.js:238:21)
at Logger.throwError (D:\trading bot\0xArbi-bot\node_modules\@ethersproject\logger\lib\index.js:247:20)
at Logger.throwArgumentError (D:\trading bot\0xArbi-bot\node_modules\@ethersproject\logger\lib\index.js:250:21)
at throwError (D:\trading bot\0xArbi-bot\node_modules\@ethersproject\abi\lib\fragments.js:53:16)
at parseParamType (D:\trading bot\0xArbi-bot\node_modules\@ethersproject\abi\lib\fragments.js:187:21)
at ParamType.fromString (D:\trading bot\0xArbi-bot\node_modules\@ethersproject\abi\lib\fragments.js:333:28)
at D:\trading bot\0xArbi-bot\node_modules\@ethersproject\abi\lib\fragments.js:343:72
at Array.map (<anonymous>)
at parseParams (D:\trading bot\0xArbi-bot\node_modules\@ethersproject\abi\lib\fragments.js:343:32)
at FunctionFragment.fromString (D:\trading bot\0xArbi-bot\node_modules\@ethersproject\abi\lib\fragments.js:756:25) {
reason: 'unexpected character at position 44',
code: 'INVALID_ARGUMENT',
argument: 'param',
value: 'struct IV3SwapRouter.ExactInputSingleParams params'
}