Based on Solana cookbook, PDA is derived from program ID and seeds.
There's no possibility that program ID is different, so I thought maybe there's mistype in seeds.
I checked over 30 times seeing program's seed and test code's seed, but they are same and keep occurs "seeds constraint was violated" error.
This problem is occured trying to initialize metaplex's Collection Authority Record(not imported from library, declared at my program with same format).
Below code snippets are program/test code and I'm running my program at devnet.
- program
// same format at Metaplex library but different data type
#[account]
#[derive(Default)]
pub struct CollectionAuthorityRecord {
pub key: u8, //1
pub bump: u8, //1
pub update_authority: Option<Pubkey>, //33 (1 + 32)
}
// part of InitializeCollectionAuthRec
#[account(
init,
payer = signer,
space = 500,
seeds = [
b"metadata",
metadata_program.key().as_ref(),
// collection_nft_mint.key().as_ref(),
Pubkey::from_str("22TxMWPYoBJ1dq9MVWt9eaiYyZPkoXZk8WWxaFT116UE").unwrap().key().as_ref(),
b"collection_authority",
Pubkey::from_str("7kNPcRsksfS8KV6KtoKNMFKxY82YkWXz5QZyG3kEHynF").unwrap().key().as_ref(),
],
bump,
)]
pub collection_authority_record: Account<'info, CollectionAuthorityRecord>,
- test code
it("Initialize collection authority record", async () => {
const [collectionAuthorityRecord] = await PublicKey.findProgramAddressSync(
[
Buffer.from("metadata"),
METADATA_PROGRAM_ID.toBuffer(),
// collectionNftMint.address.toBuffer(),
new PublicKey("22TxMWPYoBJ1dq9MVWt9eaiYyZPkoXZk8WWxaFT116UE").toBuffer(),
Buffer.from("collection_authority"),
// pdaCollection.toBuffer(),
new PublicKey("7kNPcRsksfS8KV6KtoKNMFKxY82YkWXz5QZyG3kEHynF").toBuffer(),
],
METADATA_PROGRAM_ID
);
console.log("collectionAuthRec")
console.log(collectionAuthorityRecord)
try {
const tx = await program.methods
.initializeCollectionAuthRec()
.accounts({
signer: owner_PDA.publicKey,
collectionAuthorityRecord: collectionAuthorityRecord,
metadataProgram: METADATA_PROGRAM_ID
})
.signers([owner_PDA])
.rpc();
console.log("View transaction in explorer:")
console.log(`https://explorer.solana.com/tx/${tx}?cluster=devnet`)
} catch(e) {
console.log(e)
}
})
If I'm missing something, plz let me kwow. Thanks.
owner_pda
account?