-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PDA ConstraintSeeds error with generated js client #108
Comments
you haven't done anything wrong i believe there's a bug in codama (which is the package that's used to generate the JS client) I copied your example and ran it locally and also had the same issue. // Resolve default values.
if (!accounts.counter.value) {
accounts.counter.value = await getProgramDerivedAddress({
programAddress,
seeds: [
addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder()).encode(
expectSome(args.name)
),
],
});
} the seeds portion is incorrect. const [counterAddress, _counterBump] = await getProgramDerivedAddress({
programAddress: MY_PROGRAM_PROGRAM_ADDRESS,
seeds: [Buffer.from('test')],
}); I also verified it using the solana/web3.js v1.95.5 (the create-solana-program uses the new solana web3.js v2.0) const [legacyWeb3JsPda] = PublicKey.findProgramAddressSync(
[Buffer.from('test')],
new PublicKey(MY_PROGRAM_PROGRAM_ADDRESS)
); for now to work around your issue, you can do the following // calculate the counter PDA manually
const [counterAddress, _counterBump] = await getProgramDerivedAddress({
programAddress: MY_PROGRAM_PROGRAM_ADDRESS,
seeds: [Buffer.from('test')],
});
// explicitly set the counter PDA address in your ix
const createIx = await getCreateInstructionAsync({
name: 'test',
counter: counterAddress,
authority: authority.address,
payer: authority,
});
// same as before |
i submitted an issue on codama - codama-idl/codama#337 |
Hi there, thanks for raising this. However, you are giving conflicting results by saying that the String prefix must be a @SDPyle Would you mind sharing the Anchor IDL that gets generated so I can see what type it provides for that seed? |
Wow. Thank you so much! I tried @swimricky's update and it worked! Here's the Anchor IDL:
Let me know if there's anything else I can help with. God Bless! |
@lorisleiva sorry it was late and i made a mistake if you use the utf8encoder without the sized prefix you'll derive the correct address const [counterAddress, _counterBump] = await getProgramDerivedAddress({
programAddress: MY_PROGRAM_PROGRAM_ADDRESS,
seeds: [Buffer.from('test')],
});
const [counderAddress2, _counterBump2] = await getProgramDerivedAddress({
programAddress: MY_PROGRAM_PROGRAM_ADDRESS,
seeds: [
getUtf8Encoder().encode('test'),
],
});
t.deepEqual(counterAddress, counderAddress2, 'counterAddress should match'); |
Thanks for the detailed updates guys! Yes, I can see now that the Anchor macro says The really annoying thing is that this is actually not exposed on the IDL whatsoever. "pda": {
"seeds": [
{
"kind": "arg",
"path": "name" // argument "name" is `string`, not `string.as_bytes()` or something.
}
]
} So from the perspective of Codama, you're just getting the Since I believe this is the way most people using string as seeds anyway, it may be okay to just assume that string seed should never have any prefix. But that would introduce a bug for anyone that currently uses I think it's still worth doing but maybe best to release it in 2.0. 🤔 |
Let's close this issue in favour of the new one created by @swimricky. 🙏 |
I love what this project is doing, and I'm very grateful for it.
I'm having an issue with PDAs and the generated js client.
Simple modification to the template scaffold to use a seed from the instruction:
Test:
This generates:
I'm relatively new to Solana development, so it's entirely possible that I'm missing something, but it seems like something isn't working as intended.
Thank you for your time and attention.
The text was updated successfully, but these errors were encountered: