2

I'd like to send a transaction to a smart contract (token swap). https://ftmscan.com/address/0xa38cd27185a464914d3046f0ab9d43356b34829d#code

The smart contract requires an additional boolean value next to the addresses:

Function: swapExactTokensForTokens(uint256, uint256, (address,address,bool)[], address, uint256)

when I send

const txObject = { nonce: web3.utils.toHex(txCount), gasLimit: web3.utils.toHex(350000), gasPrice: web3.utils.toHex(web3.utils.toWei(gas, "Gwei")),
to: contractAddress, data: contract.methods.swapExactTokensForTokens(web3.utils.toHex(from_amt), web3.utils.toHex(to_amt),['0x04068DA6C83AFCFA0e13ba15A6696662335D5B75','0xE55e19Fb4F2D85af758950957714292DAC1e25B2',false], address, web3.utils.toHex(deadline)).encodeABI(), chainId: web3.utils.toHex(chain_id) }

I get the error message

reason: 'invalid tuple value',
code: 'INVALID_ARGUMENT',
argument: 'tuple', value: '0x04068DA6C83AFCFA0e13ba15A6696662335D5B75'

How to format this tuple correctly?

2 Answers 2

0

In solidity tuple always pass in [] bracket. For your function input format is

(uint256,uint256,[["address","address",bool]],"address",uint256).

should check the format carefully, especially nested tuple in list

1
  • I did that. I get "Error: invalid tuple value"
    – Helmuth
    Mar 9, 2022 at 13:43
0

According to this test in Web3 playground, wrapping your array in additional array should work:

const txObject = {
  nonce: web3.utils.toHex(txCount),
  gasLimit: web3.utils.toHex(350000),
  gasPrice: web3.utils.toHex(web3.utils.toWei(gas, "Gwei")),
  to: contractAddress,
  data: contract.methods.swapExactTokensForTokens(
    web3.utils.toHex(from_amt), 
    web3.utils.toHex(to_amt), 
    [
      [
        '0x04068DA6C83AFCFA0e13ba15A6696662335D5B75',
        '0xE55e19Fb4F2D85af758950957714292DAC1e25B2',
        false,
      ],
    ],
    address,
    web3.utils.toHex(deadline)
  ).encodeABI(),
  chainId: web3.utils.toHex(chain_id)
}

Your Answer

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

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