-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
Description
Bug Description
When using seeds
constraints that reference account fields in #[derive(Accounts)]
structs, IDL generation fails with error[E0425]: cannot find value
during anchor build
. The contract compiles successfully with anchor build --no-idl
but fails when generating IDL.
Error Message
error[E0425]: cannot find value `user` in this scope
--> programs/groundzero_contract/src/account_types.rs:79:10
|
79 | #[derive(Accounts)]
| ^^^^^^^^ not found in this scope
|
= note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)
Steps to Reproduce
- Create an Anchor project with version 0.31.x
- Define an account struct with seeds constraint referencing another account field:
#[derive(Accounts)]
pub struct CreateBuyer<'info> {
#[account(mut)]
pub user: Signer<'info>,
#[account(
init,
payer = user,
space = 8 + 33,
seeds = [b"buyerinfo", user.key().as_ref()], // This line causes the error
bump
)]
pub buyer: Account<'info, BuyerInfo>,
pub system_program: Program<'info, System>,
}
- Run
anchor build
- Build fails during IDL generation phase
Expected Behavior
- Contract should build successfully with IDL generation
- Seeds constraints referencing account fields should work as documented
- IDL should properly reflect the account structure
Actual Behavior
- Contract compiles fine with
anchor build --no-idl
- IDL generation fails with "cannot find value" error
- Seeds constraints are not recognized during IDL build phase
Environment
- Anchor CLI Version: 0.31.1
- Anchor Lang Version: 0.31.1
- Rust Version: 1.75.0 (also tested with 1.85.1)
- Solana CLI Version: Latest
- OS: Linux (Fedora 6.15.10-100.fc41.x86_64)
Code Example
Working Example (without seeds)
#[derive(Accounts)]
pub struct CreateBuyer<'info> {
#[account(mut)]
pub user: Signer<'info>,
#[account(
init,
payer = user,
space = 8 + 33
)]
pub buyer: Account<'info, BuyerInfo>,
pub system_program: Program<'info, System>,
}
Failing Example (with seeds)
#[derive(Accounts)]
pub struct CreateBuyer<'info> {
#[account(mut)]
pub user: Signer<'info>,
#[account(
init,
payer = user,
space = 8 + 33,
seeds = [b"buyerinfo", user.key().as_ref()], // Fails here
bump
)]
pub buyer: Account<'info, BuyerInfo>,
pub system_program: Program<'info, System>,
}
Attempted Workarounds
1. Instruction Parameter Approach (Also Fails)
#[derive(Accounts)]
#[instruction(user_key: Pubkey)]
pub struct CreateBuyer<'info> {
#[account(mut)]
pub user: Signer<'info>,
#[account(
init,
payer = user,
space = 8 + 33,
seeds = [b"buyerinfo", user_key.as_ref()], // Still fails
bump
)]
pub buyer: Account<'info, BuyerInfo>,
pub system_program: Program<'info, System>,
}
Lunapraisel222, georgecloud232, udommary, shayyD, adeduroakintade-cpu and 4 more