coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.64k stars 1.33k forks source link

Error Number: 4100. Error Message: The declared program id does not match the actual program id. #1599

Closed rickiey closed 2 years ago

rickiey commented 2 years ago

I used TOTURIAL in this step, and the result was a problem.

https://project-serum.github.io/anchor/tutorials/tutorial-0.html#generating-a-client

node client.js output:

Running client.
Transaction simulation failed: Error processing Instruction 0: custom program error: 0x1004 
    Program EqyEgYNGujjUyhgFYkzP9va2oFFw6rbyyp1AsbMnrt51 invoke [1]
    Program log: AnchorError occurred. Error Code: DeclaredProgramIdMismatch. Error Number: 4100. Error Message: The declared program id does not match the actual program id.
callensm commented 2 years ago

can you be a little more clear on the steps to reproduce the error, please?

rickiey commented 2 years ago

I understand, I have to declare program_id when I start writing code, so that it and the deployed program_id consistent such as: declare_id!("AnLTG7X1FJRcnxVsKXMn7B6GrVuMn6xgxJ8TqTmbd7GP"); const programId = new anchor.web3.PublicKey("AnLTG7X1FJRcnxVsKXMn7B6GrVuMn6xgxJ8TqTmbd7GP");

But I don't know how it is generated.

callensm commented 2 years ago

it may be that the keypair generated and written to ./target/deploy/<program>-keypair.json is different that the public key you're asserting in the code with declare_id.

try copying the keypair file you want to that path with the appropriate file name to ensure anchor is deploying with the same keypair that you're asserting and run it again.

rickiey commented 2 years ago

thx, I know how to do it.

yangyangpig commented 2 years ago

@rickiey hello, how do you solve the issue, can you tell me?