Quantcast
Channel: Error Code: DeclaredProgramIdMismatch - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 3

Answer by nf0x for Error Code: DeclaredProgramIdMismatch

$
0
0

I saw you found the solution, but the issue is more related to the Anchor workflow, which is not correctly explained in the Anchor book as far as I know.

When you are compiling a Solana program built with Anchor for the first time, it goes like this:

  1. Run anchor build
    • This generates the target/ folder.
    • Inside this folder, you'll find deploy/ and in there a keypair file. The keypair file is a generated keypair for the program you are deploying.
  2. Run solana-keygen pubkey target/deploy/{keypair_file}.json
    • This will give you the public key of that keypair
  3. Copy that public key and update it both on Anchor.toml and in lib.rs, where the macro declare_id!() resides.
  4. Run anchor build again, in order to re-compile the code with the new program id.
  5. Lastly, if you want to deploy it in localnet, I recommend using anchor localnet instead of the vanilla solana-test-validator -r since it deploys the program located on target/ for you using that keypair.

You only need to do the first 3 steps the first time you build the program, or in case you delete the target/ folder or the keypair inside it changes.

Hope this clarify things :)


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>