How to pass array with fcl.arg() in a transaction?

Hi,

I use reactjs and I have a problem with a transaction. I don’t understand why I can’t pass an Array with fcl.
This is my code :

const tx = await fcl
                .send([
                    fcl.proposer(fcl.authz),
                    fcl.payer(fcl.authz),
                    fcl.authorizations([fcl.authz]),
                    fcl.limit(9999),
                    fcl.args([
                        fcl.arg(props.nftsToSell, t.Array(t.UInt64)), 
                        fcl.arg(prix.toFixed(2), t.UFix64),
                    ]),
                    fcl.ref(block.id),
                    fcl.transaction(sellSelection),
                ]);

On the first argument “props.nftsToSell” is an array of integers that contains the ids of two nfts to sell, like this [182,183]. I used parseInt() to get these integers in the array (I read on a forum that by default parseInt() cast in UInt64)
But when I run that, I get this error:

    Error: Type Error: Expected integer for UInt64
    at f (types.js:16:1)
    at Object.asArgument (types.js:137:1)
    at types.js:411:1
    at Array.map (<anonymous>)
    at Object.asArgument (types.js:410:1)
    at Dn (resolve-arguments.js:10:1)
    at Un (resolve-arguments.js:20:1)
    at interaction.js:244:1

Can you help me please to understand my error ?

Thanks you very much for your help :slightly_smiling_face:

Hi, @sylv1un I think so there must be some problem with your data type. here is the react code

const passArray = async () => {
    let array = [1, 2]
    const transactionId = await fcl.send([
      fcl.transaction`
      transaction(nftTosel:[UInt64]) {
        prepare(signer: AuthAccount) {

        }
      }
      `,
      fcl.payer(fcl.authz),
      fcl.proposer(fcl.authz),
      fcl.authorizations([fcl.authz]),
      fcl.limit(9999),
      fcl.args([
        fcl.arg(array, t.Array(t.UInt64))
      ])
    ]).then(fcl.decode);
    console.log(transactionId);
  }

and this is the transaction id in the testnet.
https://testnet.flowscan.org/transaction/39344b4f0f4ec6143f7352f0543cf66593f3d5afd2ae18bc19268e49702b908a/script

Ohh Ok ! You are right !
I had an array within an array in my “pops.nftsToSell” variable :upside_down_face:, like this:
[ [1, 2] ]

Thank you very much NasirAliShah it is good for me :pray: :ok_hand:

1 Like