{"id":22672162,"url":"https://github.com/jimlynchcodes/anchor-env-multi-devnet","last_synced_at":"2026-02-21T14:02:28.126Z","repository":{"id":265584415,"uuid":"896139604","full_name":"JimLynchCodes/anchor-env-multi-devnet","owner":"JimLynchCodes","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-30T01:45:08.000Z","size":32,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-09T16:18:06.678Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JimLynchCodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-29T16:18:26.000Z","updated_at":"2024-11-30T23:37:32.000Z","dependencies_parsed_at":"2024-11-30T02:30:16.918Z","dependency_job_id":"8db278fb-e7ca-41db-9d00-0c7f420ba780","html_url":"https://github.com/JimLynchCodes/anchor-env-multi-devnet","commit_stats":null,"previous_names":["jimlynchcodes/anchor-env-multi-devnet"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimLynchCodes%2Fanchor-env-multi-devnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimLynchCodes%2Fanchor-env-multi-devnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimLynchCodes%2Fanchor-env-multi-devnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JimLynchCodes%2Fanchor-env-multi-devnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JimLynchCodes","download_url":"https://codeload.github.com/JimLynchCodes/anchor-env-multi-devnet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237111687,"owners_count":19257387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-09T16:18:11.427Z","updated_at":"2025-10-14T02:11:31.238Z","avatar_url":"https://github.com/JimLynchCodes.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# anchor-env-multi-devnet\n\nThis project is an example of holding two different key pairs in an Anchor project and deploy different versions of the same program (e.g., \"staging\" and \"prod\") to devnet with different program IDs. The steps to achieve this involve configuring the project to support multiple deployments and ensuring that you can manage separate program IDs for each environment.\n\n\u003cbr/\u003e\n\n# Steps to prepare the project for different program IDs\n\n\n## Create Separate Key Pairs for Staging and Production\n\nYou need two different key pairs for the two environments. You can generate key pairs using the Solana CLI:\n\n```\nsolana-keygen new --outfile ~/devnet-staging-keypair.json\nsolana-keygen new --outfile ~/devnet-prod-keypair.json\n```\n\nCheck the public key of a given keypair like this:\n```\nsolana-keygen pubkey ~/devnet-staging-keypair.json\nsolana-keygen pubkey ~/devnet-prod-keypair.json\n```\n\nHere's how to modify your Anchor.toml:\n\nAnchor.toml\n```\n[programs.devnet]\nstaging = \"staging_program_id\"\n\n[programs.devnet]\nprod = \"prod_program_id\"\n```\n\n\nUpdate the program id in the code to work with both deployment targets:\n\nlib.rs\n```\n#[cfg(feature = \"staging\")]\npub const PROGRAM_ID: \u0026str = \"staging_program_id\";\n\n#[cfg(feature = \"prod\")]\npub const PROGRAM_ID: \u0026str = \"prod_program_id\";\n\n// Example usage of PROGRAM_ID\npub fn get_program_id() -\u003e \u0026'static str {\n    PROGRAM_ID\n}\n```\n\n\nThen be sure to build it with the --features flag:\n```\nanchor build --features staging\n```\n\nWhen deploying, specify the keypair with the program id flag.\n```\nsolana program deploy --program-id ~/path-to-your-keypair.json your_program.so\n```\n\nCheck that it was deployed properly:\n```\nsolana program show \u003cprogram_id\u003e\n```\n\n\n\n## Multi-deployment setup\n\n1) Show public key of keypair created by anchor init\n\n```\nsolana-keygen pubkey ./target/deploy/my_project-keypair.json \n```\n\nIn this case, 7HB2ioJ5bFu2K5xnqxbSampSdCHdToftNzEJJCzkybUx\n\nThen create a second key:\n```\nsolana-keygen new --outfile ./target/deploy/staging-keypair.json\n```\n\nTake note of the public key printed, save the seed phrase, and notice how running the \"pubkey\" command on this one prints the same key.\n\nIn this case, G8wijYorkKGjFkwNQ8zoUdWR67NoZ3Jwc3t4Q2dFJREb\n\n\nThen, \n\n1) Update lib.rs\n\n```\n// \"first key (my_project-keypair.json)\"\ndeclare_id!(\"7HB2ioJ5bFu2K5xnqxbSampSdCHdToftNzEJJCzkybUx\");\n\n// \"second key (my_project-keypair.json)\"\n// declare_id!(\"G8wijYorkKGjFkwNQ8zoUdWR67NoZ3Jwc3t4Q2dFJREb\");\n```\n\n2) Update Anchor.toml\n\n```\n[programs.localnet]\nmy_project = \"7HB2ioJ5bFu2K5xnqxbSampSdCHdToftNzEJJCzkybUx\"\n# my_project = \"G8wijYorkKGjFkwNQ8zoUdWR67NoZ3Jwc3t4Q2dFJREb\"\n\n[programs.devnet]\nmy_project = \"7HB2ioJ5bFu2K5xnqxbSampSdCHdToftNzEJJCzkybUx\"\n# my_project = \"G8wijYorkKGjFkwNQ8zoUdWR67NoZ3Jwc3t4Q2dFJREb\"\n```\n\n3) Then build and deploy to first _\"environment\"_\n\n```\nanchor build \n```\n\nspecify key and program name when deploying:\n```\nanchor deploy --provider.cluster devnet --program-keypair ./target/deploy/my_project-keypair.json --program-name my_project\n```\n\nThis deploys the smart contract at 7HB2ioJ5bFu2K5xnqxbSampSdCHdToftNzEJJCzkybUx\n\n\nDon't forget to deploy the idl also!\n```\nanchor idl init --provider.cluster devnet  --filepath ./target/idl/my_project.json 7HB2ioJ5bFu2K5xnqxbSampSdCHdToftNzEJJCzkybUx\n```\n\nAnd upgrading later:\n```\nanchor idl upgrade --provider.cluster devnet --filepath ./target/idl/my_project.json 7HB2ioJ5bFu2K5xnqxbSampSdCHdToftNzEJJCzkybUx\n```\n\n---\n\n## Deploy to _Other_ Environment (Eg. Devnet Staging)\n\n1) Check the pub key again for the other keypair\n```\nsolana-keygen pubkey ./target/deploy/my_project-keypair.json\n```\n\n2) Update lib.rs to declare the other key\n\n3) Update Anchor.toml to set the other pubkey\n\n4) Then make a new build\n\n```\nanchor build\n```\n\n5) deploy\n```\nanchor deploy --provider.cluster devnet --program-keypair ./target/deploy/staging-keypair.json --program-name my_project\n```\n\n6) and deploy idl\n\nfirst time\n```\nanchor idl init --provider.cluster devnet --filepath ./target/idl/my_project.json G8wijYorkKGjFkwNQ8zoUdWR67NoZ3Jwc3t4Q2dFJREb\n```\n\nupdating later\n```\nanchor idl upgrade --provider.cluster devnet --filepath ./target/idl/my_project.json G8wijYorkKGjFkwNQ8zoUdWR67NoZ3Jwc3t4Q2dFJREb\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimlynchcodes%2Fanchor-env-multi-devnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimlynchcodes%2Fanchor-env-multi-devnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimlynchcodes%2Fanchor-env-multi-devnet/lists"}