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.


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(
        gasLimit: ethers.utils.hexlify(200000),
        gasPrice: ethers.utils.parseUnits("10", "gwei"),


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',
  argument: 'param',
  value: 'struct IV3SwapRouter.ExactInputSingleParams params'

2 Answers 2


we can go for the object {} ir const ExactInputSingleParams={

amountOutMinimum: amountOutMinimum


then create an instance using the web3 or ethers with that instance you can fetch the methods like constgasEstimate=contract.methods.exactInputSingle(ExactInputSingleParams).estimateGas({walletAddress:walletAddress,value:if the function is payable}); const res= contract.methods.exactInputSingle(ExactInputSingleParams).estimateGas({walletAddress:walletAddress,value:if the function is payable,gas});

with this you can pass the struct of the contract in a key-value pair as an object.


It accepts a tuple type.


pragma solidity ^0.8.0;
contract Test {
    struct StructA{ string name; address _address;}
    StructA _structA;
    constructor(StructA memory structA) {
        _structA = structA;

Input: ["hi", '0x5B38Da6a701c568545dCfcB03FcB875f56beddC4']

-> Successful deployment

You should provide the values in the order they are specified in the struct, and wrap that list in array to be able to pass a struct instance to smart contract's function using web3.js or ethers.js.

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.