I am following the following tutorial:
https://dev.to/findiglay/building-a-blog-on-solana-2pg8
But in the code below it is creating seeds using the value from blog_account. I want to pass some instructions here from RPC Client side (like: id = 1)
#[instruction(post_account_bump: u8, title: String, body: String)]
pub struct CreatePost<'info> {
#[account(mut, has_one = authority)]
pub blog_account: Account<'info, Blog>,
#[account(
init,
seeds = [
b"post".as_ref(),
blog_account.key().as_ref(),
&[blog_account.post_count as u8].as_ref() // here in place of blog_account.post_count I want to use my custom variable
],
bump = post_account_bump,
payer = authority,
space = 10000
)]
pub post_account: Account<'info, Post>,
pub authority: Signer<'info>,
pub system_program: Program<'info, System>
}
i have tried passing u64 value in instruction but it give me following error:
Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Cross-program invocation with unauthorized signer or writable account
code i used:
#[instruction(post_account_bump: u8, title: String, body: String, id: u64)]
pub struct CreatePost<'info> {
#[account(mut, has_one = authority)]
pub blog_account: Account<'info, Blog>,
#[account(
init,
seeds = [
b"post".as_ref(),
blog_account.key().as_ref(),
&[id as u8].as_ref() // passing id in arguments from RPC call using new anchor.BN(2)
],
bump = post_account_bump,
payer = authority,
space = 10000
)]
pub post_account: Account<'info, Post>,
pub authority: Signer<'info>,
pub system_program: Program<'info, System>
}
id
cast from u64 to u8 sounds like a bad idea, since it would lead to the a collision (same PDA for different arguments) every 256 accounts.