GeraB
October 30, 2024, 12:47pm
1
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.
p.s
October 30, 2024, 2:09pm
2
Hi @GeraB
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?
GeraB
October 30, 2024, 2:36pm
3
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
p.s
October 30, 2024, 3:16pm
4
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?
GeraB
October 30, 2024, 3:34pm
5
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,
};
}
GeraB
October 31, 2024, 12:43pm
6
@p.s This is the complete error:
p.s
November 1, 2024, 8:38am
7
It’s challenging to debug this issue without reproducing it.
What fuels
version are you using?
GeraB
November 1, 2024, 11:57am
8
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.
p.s
November 4, 2024, 4:56am
9
What forc
versions are you using?
p.s
November 4, 2024, 12:54pm
11
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
)?
GeraB
November 4, 2024, 1:11pm
12
GeraB
November 4, 2024, 11:47pm
13
Hey @p.s ! I have just created a simple repo with the bug, I hope it will help you
Contribute to geraBarboni/Fuel-error development by creating an account on GitHub.
p.s
November 5, 2024, 8:09am
14
GeraB:
I’m using 0.66.2 now
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.
GeraB
November 5, 2024, 2:18pm
15
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
GeraB
November 5, 2024, 9:23pm
16
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?
p.s
November 6, 2024, 4:49am
17
Hey @GeraB
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.
GeraB
November 8, 2024, 11:54am
18
Hey @p.s ! Sorry for the delay, I’ve been working on it and it worked fine, thank you very much for your help.
p.s
November 11, 2024, 4:32am
19
You’re most welcome - please let us know if you face further issues.
system
Closed
December 2, 2024, 12:33am
20
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.