Search code examples
solanaanchor-solana

How to upgrade a program id on Anchor


Everytime I deploy an Anchor program on Solana, it creates a new Program ID. Is there any way to upgrade the Anchor program using the same Program ID?


Solution

  • By default, the anchor deploy command will deploy a new Program ID. If you want to upgrade your existing program, use this command

    anchor upgrade target/deploy/<PROGRAM_NAME>.so --provider.cluster <CLUSTER> --program-id <PROGRAM_ID>
    

    Where

    • PROGRAM_NAME is the file or name of your generated .so file
    • ClUSTER is which environment you'd like to deploy to (e.g "Devnet")
    • PROGRAM_ID is the existing program id you'd like to upgrade to

    https://project-serum.github.io/anchor/cli/commands.html#upgrade