2

I am new in solana smart-contract development and rust. Can anyone help me why i am getting this build time error Could not resolve Accounts symbol Option when using Optional Account in accounts struct. Any kind of help or info will be really helpful for me.

use anchor_lang::prelude::*;

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

#[program]
pub mod nft_project {
    use super::*;

    pub fn initialize(_ctx: Context<Initialize>) -> Result<()> {
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Initialize <'info>{
    require_account: Account<'info,MyAccount>,
    optional_account: Option<Account<'info,Data>> 
}

#[account]
struct MyAccount{
    name: String,
}

#[account]
struct Data {
    name: String,
    age: u8
}

enter image description here

1
  • It looks like you're implementing something very similar to this test program in the Anchor repo: github.com/coral-xyz/anchor/tree/master/tests/optional/programs/… -- perhaps you're on an older version of anchor that doesn't support it. You can first get that test program working and then change it to suit what you need
    – Jon C
    Commented Jan 4, 2023 at 23:14

1 Answer 1

2

I was able to solve this problem after few hours. The problem was i was in a lower version of anchor but upgrading that didn't helped. Problem was coming from the CLI version of anchor , upgrading the anchor cli solved the issue. Not exactly but comment form Jon C helped me to reach there. Thank You.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.