Error.ts:35 FuelError: Invalid struct Vec. Field "buf" not present

Hi people!
When executing a function I get this error

error.ts:35 FuelError: Invalid struct Vec. Field "buf" not present.

According to ABI, these are the parameter types

    is_whitelisted: InvokeFunction<
      [
        user: IdentityInput,
        max_payment: BigNumberish,
        key: BigNumberish,
        proof: Vec<string>,
      ],
      boolean
    >;

And I’m passing this as a parameter to “proof”, which correspond to the type specified in the ABI:

['0x084a71ec624e85335823e25249c22fa9d7a483bd9e637f4a0baa4029fe4eaf06', '0xddedf04e87aad7b7fd3142c9210feee40e06e24b8a5213aec569b1e77c528c80', '0xfb74eff4869e9d1470546566afeb9e8f550d26376a04edb58cd329ec180333a8']

PS: executing the function in the console, directly to the contract, it executes correctly, so an error in the contract could be ruled out.

Hi @GeraB :wave:

Could you share the Sway code for the function is_whitelisted, the ABI (if possible) and the contract ID of the contract that you called directly?

Sure!

function:

    #[storage(read)]
    fn is_whitelisted(user: Identity, max_payment:u256,key:u64, proof:Vec<b256>) -> bool{
        check_whitelist(user,max_payment,key,proof)
    }

ABI:

    is_whitelisted: InvokeFunction<
      [
        user: IdentityInput,
        max_payment: BigNumberish,
        key: BigNumberish,
        proof: Vec<string>,
      ],
      boolean
    >;

ContractID

fuel1ey5d3q9zm28yl4gzy9gv04cd89ft4735llus669uylkw74ae6mgq57ncfr

I tried to replicate your issue, but everything worked as expected.

Could you share a repository, either of your full project or a minimum reproduction of the issue?

I can’t share the repo, but this is the hook where I’m using that function.

export function useUserWhitelisted({
  contract,
  user,
  userMerkleProof,
  enabled,
}: Props) {
  const { data, isLoading, isFetched } = useQuery({
    queryKey: [
      "useUserWhitelisted",
      contract?.id?.toString(),
      user,
      userMerkleProof?.node,
    ],

    queryFn: async () => {
      try {
        if (!userMerkleProof) return false;

        const identityInput = toIdentityAddressInput(user?.bech32 as string);

        // This is showed correctly;
        console.log("__IDENTITY INPUT", identityInput);
        console.log("MERKLE PROOF VALUE ", userMerkleProof?.value);
        console.log("MERKLE PROOF KEY OF VALUE ", userMerkleProof?.keyOfProof);
        console.log("MERKLE PROOF ", userMerkleProof?.proof_nodes);

        const result = await contract?.functions
          .is_whitelisted(
            identityInput,
            userMerkleProof?.value || 0,
            userMerkleProof?.keyOfProof || 0,
            userMerkleProof?.proof_nodes || [],
          )
          .get();

        if (result) {
          console.log("RESULT", result);

          return result.value;
        }
        return false;
      } catch (e) {
        const parsedError = parseFuelError(e);
        const msg = customReportError(e);

        if (parsedError.log) {
          throw new Error(parsedError.log);
        } else if (parsedError.message) {
          throw new Error(parsedError.message);
        }

        throw new Error(msg);
      }
    },
    enabled:
      !!contract &&
      !!enabled &&
      userMerkleProof !== undefined &&
      (!!user || userMerkleProof === null),
  });

  return {
    data,
    isPending: isLoading,
    isFetched: isFetched,
  };
}

@p.s This is the complete error:

It’s challenging to debug this issue without reproducing it.

What fuels version are you using?

At that time I was using version 0.96.1, I stop appearing using version 0.91.0 but I lose the functions to connect to the dapp with Metamask or Solana.

What forc versions are you using?

I’m using 0.66.2 now

Could you share the JSON ABI that is generated in the out directory of you contract (e.g. contract_name/out/contrac-name-abi.json)?

Sure! I put it on this folder:
https://drive.google.com/drive/folders/1-i6y-DzrR5lr7eYiMJZdnRWAHg1_FShl?usp=sharing

Hey @p.s ! I have just created a simple repo with the bug, I hope it will help you

That’s perfect, thanks @GeraB.

So in the useSalesContract hook you reference the SaleContractAbi__factory which was built using forc 0.62.0. We have also since changed our ABI specification in forc 0.63.0, which might be why you’re experiencing these issue.

I’d suggest the following:

  • Ensure you’re using the latest forc version.
    (Run fuelup upgrade from your terminal)
  • Deleting the generating TypeScript types folders (services/contract/sale and services/contract/staking).
  • Re-run the type generation via fuels build or fuels typegen.
  • Re-deploy the contracts to ensure versions are aligned correctly.

Thanks for that guide @p.s!, I implemented it to update everything but I keep getting the same error.
The changes are uploaded in the repo

Yes, it’s definitely not just that. What could be missing? Did you try with the js code as well or just from console directly to the contract? :thinking:

Hey @GeraB :wave:

It still appears that you’re building with an old version of forc resulting in the old specification of the ABI being built.

I’ve created the following PR that showcases the rebuild contract in the correct format, and I can successfully run your dApp. I had to use a slimmed down version of the SaleContract with only the is_whitelisted method (as that’s the only function you provided.

If you’d like me to take a look at your project then feel free to add me to your private repository and I can help expedite your issue.

Hey @p.s! Sorry for the delay, I’ve been working on it and it worked fine, thank you very much for your help. :hugs:

You’re most welcome - please let us know if you face further issues.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.