2

I'm trying to build an Anchor program but getting the following error:

anchor build
   Compiling jackcoins v0.1.0 (/home/webskitters/projects WS/jackcoins/jackcoins/programs/jackcoins)
    Finished release [optimized] target(s) in 2.23s
   Compiling jackcoins v0.1.0 (/home/webskitters/projects WS/jackcoins/jackcoins/programs/jackcoins)
error: custom attribute panicked
 --> programs/jackcoins/src/lib.rs:8:1
  |
8 | #[program]
  | ^^^^^^^^^^
  |
  = help: message: Safety checks failed: Failed to get program path

What I've Verified

  1. Program ID matches in all locations:

    • declare_id! in lib.rs matches "BQtK93ZPivZGB3AUH9BBhmgMyvSYxZvzBQH5jR8KHo9f"
    • Same ID exists in target/deploy/jackcoins.json
    • Anchor.toml has correct program ID
  2. File Structure:

    • Program files are in the correct location
    • Keypair exists in target/deploy/
    • Project follows standard Anchor workspace structure
  3. Attempted Solutions:

    • Cleaned and rebuilt project
    • Removed target/ and .anchor/ directories
    • Verified all file permissions
    • Tried building with explicit program name

Environment Details

  • Anchor version: anchor-cli 0.29.0
  • Solana version: solana-cli 1.18.24 (src:7ba2a0e9; feat:3241752014, client:Agave)
  • OS: Ubuntu
  • Project: Token program with two SPL tokens

Code

Here's the relevant part of my lib.rs:

use anchor_lang::prelude::*;
use anchor_spl::associated_token::AssociatedToken;
use anchor_spl::token::{self, Mint, Token, TokenAccount};

declare_id!("BQtK93ZPivZGB3AUH9BBhmgMyvSYxZvzBQH5jR8KHo9f");
pub const JCKP_DECIMALS: u8 = 9;

#[program]
pub mod jackcoins {
    use super::*;
    pub const JCK_DECIMALS: u8 = 9;
    const INITIAL_SUPPLY: u64 = 6_000_000_000;
    // ... rest of program implementation
}

Questions

  1. What could be causing this error despite having correct program ID configuration?
  2. Are there any specific permissions or path requirements I should check?
  3. Are there any Anchor workspace configuration files I should verify?

Any help would be greatly appreciated!

1

1 Answer 1

3

Looking at the anchor code here is what it sais about this error: https://github.com/coral-xyz/anchor/blob/master/lang/syn/src/idl/program.rs#L162

let program_path = get_program_path();
    if program_path.is_err() {
        // Getting the program path can fail in the following scenarios:
        //
        // - Anchor CLI version is incompatible with the current version
        // - The error is coming from Rust Analyzer when the user has `idl-build` feature enabled,
        // likely due to enabling all features (https://github.com/coral-xyz/anchor/issues/3042)
        //
        // For the first case, we have a warning when the user is using different versions of the
        // lang and CLI crate. For the second case, users would either have to disable the
        // `idl-build` feature, or define the program path environment variable in Rust Analyzer
        // settings.
        //
        // Given this feature is not a critical one, and it works by default with `anchor build`,
        // we can fail silently in the case of an error rather than panicking.
        return Ok(());
    }

So probably either the installed CLI version is incompatible with the current version or it has to do with the idl-build feature and you need to redefine your program path environment variable.

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.