What determines program ID?

I am following the helloworld example.

I just noticed that rerunning this command:

solana program deploy User/solana-contracts/example-helloworld/dist/program/helloworld.so

Always produces the same program ID, even with changes to the code.

I can change that ID my modifying the helloworld-keypair.json, but that still raises few questions.

  1. Am I upgrading the same contract instead of deploying a new one?

  2. Why can I deploy anything with any random numbers in helloworld-keypair.json? Presumably address derived from that private key wouldn’t have enough native tokens to deploy anything.

  3. How to specify keypair to use? Doesn’t state so anywhere, but does it look for private key next to the binary and if not found uses the main one stored /home/solana.

  4. Is there a keypair per program deployed independent to the one user has?

  5. Why is program ID different each time after tweaking the helloworld-keypair.json but always the same with the base configuration?

Good questions!

Yes. You are just updating the code for the smart contract

I’m not sure if any random numbers are valid. I think only specifically formulated numbers will make a valid private key. But the reason any account works is because it isn’t the program keypair that is paying for the deployment, it’s your Solana CLI wallet.

The one from solana config get keypair.

I believe it uses the one next to the binary by default, but you can add another argument after the path to the binary to specify which key to use.

No, I don’t think so.

Oh, maybe you tweaked it to create an invalid keypair, so that it ignored that file. And if it can’t find a valid keypair in the file next to it, it says in the CLI documentation that it will use a randomly generated key when deploying the program:

Lightning reply! Thank you.
I’ll digest it all tomorrow.

1 Like