1

I am using the Anchor Framework to build Solana Programs. I haven't had this issue until now:

When running anchor build to generate my ../target folder, usually, my ../tests/program-name.ts file is able to locate and read my ../target/types/program_name. However, this time when I run anchor build in my terminal, the ../target/types/program_name file won't generate automatically.

As far as I understand, this is the anchor IDL being generated. Is it how my solana_rust_program communicates with the ../tests/program-name.ts file or am I wrong here?

Regardless, this file is necessary in order for me to run my tests in typescript.


Here is what I have tried so far:

  1. anchor keys sync to generate a new program ID/pubkey for both the Anchor.toml and lib.rs file.
  2. Deleted the previous ../target folder
  3. run anchor build while in the correct directory
  4. Anchor successfully builds, no errors.
  5. run anchor deploy to deploy the program. Anchor deploys and punches out the same program ID as provided in Step 1.
  6. I go to the ../tests/program-name.ts file to implement my program tests and I import { ProgramName } from "../target/types/program_name";
  7. I get the error: Cannot find module '../target/types/single_vault_program' or its corresponding type declarations.ts(2307)

Not sure what else to do. Perhaps I am searching the wrong information online to find the right answer for this? This is a crucial step in developing programs.


My current cli versions:

anchor-cli 0.30.0

solana-cli 1.18.14

4 Answers 4

2

for anchor 30 to generate your IDL you need to add the build idl feature into your Cargo.toml:

idl-build = ["anchor-lang/idl-build"]

enter image description here

And double check you don't have a compiler error in your program. Happens to me from time to time i don't notice and then wonder why there is nothing generated.

1
  • 1
    Now that you mention it, I did have an error. I had defined my pub user: Signer<'info> as 'pub user: Account<'info>` --- which was incorrect. This could have actually been the main issue that was occurring. However, I find your advice very helpful either way. Thank you!
    – TheLazySol
    Commented May 28 at 16:14
2

I figured out the issue to this problem. I had to restart my WSL server in VS Code. Then I ran anchor test --skip-local-validator and it worked! The IDL file was generated accordingly. However, my ../tests/program-name.ts still wasn't detecting the file when I was importing my {ProgramName} from ../target/types/program_name. To fix this, I went ahead and copied the direct path of the IDL file and imported it that way. All works well now!

0

it("Fund PDA with SOL", async () => { const transferInstruction = SystemProgram.transfer({ fromPubkey: wallet.publicKey, toPubkey: PDA, lamports: transferAmount, });

const transaction = new Transaction().add(transferInstruction);

const transactionSignature = await sendAndConfirmTransaction( connection, transaction, [wallet.payer], // signer );

console.log( \nTransaction Signature: + https://solana.fm/tx/${transactionSignature}?cluster=devnet-solana, ); });

0

Probably the VS Code TS server acting up. Try restarting it. ctrl + shift + p then type restart Typescript server`

Hack, rrunning anchor test should build and deploy the program and run the tests

4
  • Unfortunately, this did not solve my issue. I am still facing the same problem. I appreciate the hack, however, even when running anchor test it did not deploy it for me.
    – TheLazySol
    Commented May 26 at 1:37
  • Did you change your Anchor.toml config to point to the devnet cluster? Might be the cause.
    – Jimii
    Commented May 26 at 6:06
  • Yes, the problem still persists. Also, I am attempting to do this on my own localhost cluster.
    – TheLazySol
    Commented May 26 at 17:52
  • the problem was solved!
    – TheLazySol
    Commented May 26 at 18:54

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.