# Custom Solana Program ID: Deploy With a Vanity Keypair

Source: https://www.customsoladdress.com/blog/custom-solana-program-id

Published: 2026-11-02

Updated: 2026-11-09

![Prepare a program address. Program keypair: Choose the program public address; Deployment: Use the supported deployment workflow; Upgrade authority: Review separately from the program address.](https://www.customsoladdress.com/images/blog/custom-solana-program-id-diagram-v2.webp)

Prepare a program address. Program keypair: Choose the program public address; Deployment: Use the supported deployment workflow; Upgrade authority: Review separately from the program address.

[Full-size diagram (SVG)](https://www.customsoladdress.com/images/blog/custom-solana-program-id-diagram-v2.svg)

[Diagram download (PNG)](https://www.customsoladdress.com/images/blog/custom-solana-program-id-diagram-v2.png)

A Solana program ID is the public key of the keypair used for the program's first deployment, so a custom program ID means finding a matching keypair before you deploy, then passing it with solana program deploy --program-id or placing it at target/deploy/<name>-keypair.json for Anchor. After the first deploy, upgrades are controlled by the separate upgrade authority, not by the program ID keypair.

## What a program ID is and where it appears

Every deployed Solana program lives at an address called its program ID. Clients put that address in every instruction they send, IDLs and SDKs hard-code it, and explorers label transactions with it. With the upgradeable BPF loader, the program ID points to a small program account, while the bytecode itself lives in a separate program data account derived from the program ID.

The program ID is fixed at first deployment and survives every later upgrade. That permanence is what makes a custom ID worthwhile: logs, CPI calls, documentation and audits will reference the same string for the life of the protocol, and a short recognizable prefix helps developers spot it in transaction logs and explorer instruction lists. The [Base58 difficulty table in our guide](https://www.customsoladdress.com/guide#difficulty) helps you size that prefix.


## Find a matching program keypair before the first deploy

Generate the keypair locally with a tool such as solana-keygen grind and keep the resulting JSON file private until the program is deployed. Anyone holding that file before your first deploy could deploy their own program at that address, so do not commit it to a public repository. After deployment, the file no longer grants control over the program.

For readability in logs, a short prefix is usually enough. Remember that a prefix starting with a character from 2 to 9 or A to H is much cheaper to find than one starting with a later letter or a lowercase letter, as the [prefix or suffix guide](https://www.customsoladdress.com/blog/choose-solana-address-prefix-suffix) explains. Check characters against Base58 before you start. Prefixes of up to six characters can also be found with the [CustomSolAddress search form](https://www.customsoladdress.com/).


```sh
solana-keygen grind --starts-with Dex:1
# writes Dex....json named after its public key
solana-keygen pubkey ./Dex....json
```


## Deploy with solana program deploy --program-id

For native Rust programs built with cargo build-sbf, the build writes the shared object and a program keypair to target/deploy. The CLI's --program-id option accepts a keypair file and, per its help text, must be a signer for initial deploys but can be a plain address for upgrades. Without the flag, the CLI uses the keypair file sitting next to the .so if present, otherwise a random address.

You can therefore either pass your vanity keypair explicitly or overwrite target/deploy/<name>-keypair.json with it before deploying. The explicit flag is safer in scripts because it removes any doubt about which file was used. The deploy output prints the program ID; confirm it matches your pattern before announcing it.


```sh
cargo build-sbf
solana program deploy target/deploy/my_program.so \
  --program-id ./DexVanityKeypair.json \
  --upgrade-authority ~/.config/solana/id.json \
  --url devnet

solana program show <PROGRAM_ID> --url devnet
```


## Anchor: declare_id!, Anchor.toml and anchor keys sync

Anchor programs embed their own address in code with the declare_id! macro, and Anchor.toml lists program IDs per cluster under [programs.localnet], [programs.devnet] and so on. By default the ID is the public key of target/deploy/<program_name>-keypair.json, which anchor build creates the first time if it is missing. A mismatch between declare_id! and the deployed keypair makes instructions fail with a declared program ID mismatch error.

To use a vanity ID, copy your keypair over target/deploy/<program_name>-keypair.json, run anchor keys list to confirm the new public key, and run anchor keys sync, whose help text says it syncs program declare_id! pubkeys with the program's actual pubkey. Check that Anchor.toml shows the same value for the clusters you deploy to, then rebuild and deploy. The -p option limits the sync to a single program in a multi-program workspace.


```sh
cp ./DexVanityKeypair.json target/deploy/my_program-keypair.json
anchor keys list
anchor keys sync            # or: anchor keys sync -p my_program
anchor build
anchor deploy --provider.cluster devnet

// programs/my_program/src/lib.rs after sync
declare_id!("Dex...your full program id...");
```


## Program ID keypair versus upgrade authority

Two different keys are involved and they are easy to confuse. The program ID keypair determines the address and signs only the initial deployment. The upgrade authority is a separate key, by default your configured CLI wallet, that can upgrade, close or transfer authority of the program afterwards. Losing the program ID keypair after deployment is harmless; losing or leaking the upgrade authority is not.

Production teams commonly move the upgrade authority to a multisig and eventually make the program immutable. Both actions use solana program set-upgrade-authority; adding --final removes upgradeability permanently. solana program show displays the current authority so users and auditors can verify it.


```sh
solana program set-upgrade-authority <PROGRAM_ID> --new-upgrade-authority <MULTISIG_ADDRESS>
# irreversible: make the program immutable
solana program set-upgrade-authority <PROGRAM_ID> --final
```


| Key | Determines | Needed when | If leaked |
| --- | --- | --- | --- |
| Program ID keypair | The program address | First deploy only | Before deploy: someone can take the address. After: no effect |
| Upgrade authority | Who can change the code | Every upgrade, close or authority change | Attacker can replace the program |
| Fee payer | Who pays deploy costs | Each deploy transaction | Only its SOL balance is at risk |


## Using the same program ID on devnet and mainnet

A program ID is just a keypair, so the same file can deploy the same address on localnet, devnet and mainnet-beta. Teams that want consistent IDs across clusters keep a single vanity keypair for the program, deploy to devnet first to test, and deploy the identical keypair to mainnet when ready. Anchor.toml can then list the same ID under every cluster section, which keeps client configuration simple.

Deployment costs on each cluster are driven by the size of the program, because the program data account must hold enough lamports for rent exemption. The vanity keypair does not change that cost. What it changes is preparation: the keypair must exist before the first deploy on each cluster, and once a cluster has a program at that address, deploying with the same keypair becomes an upgrade, which requires the upgrade authority rather than creating a new program.

If you already deployed to devnet with a random ID and now want a vanity ID for mainnet, the code must change: update declare_id!, regenerate IDLs and update clients. Do this before audits are finalized so the audited code references the production ID.


## Common pitfalls with custom program IDs

The most frequent failure is cloning a repository whose committed declare_id! does not match the keypair generated locally, then deploying to an address the code does not expect. Running anchor keys sync after cloning, or deliberately keeping a shared vanity keypair out of version control and distributing it securely, avoids this.

Program IDs differ from token mints and PDAs in how they are used, so read [wallet, mint and program addresses explained](https://www.customsoladdress.com/blog/solana-wallet-mint-program-address) if your team is deciding which address to brand. For the token side of a launch, [creating a custom token mint address](https://www.customsoladdress.com/blog/custom-solana-token-mint-address) uses the same keypair-first approach with spl-token.

- Deploying to devnet with a random ID first, then expecting mainnet to share the vanity ID: use the same keypair on both clusters.
- Committing the program keypair to a public repo before mainnet deploy: anyone can deploy to that address first.
- Forgetting to update clients and IDLs after changing declare_id!.
- Treating the program ID keypair as the upgrade key: upgrades require the upgrade authority.

## Continue the practical setup

- [Solana Wallet vs Token Mint vs Program Address: Which Can Be Custom?](https://www.customsoladdress.com/blog/solana-wallet-mint-program-address) — How Solana wallet addresses, token mints, token accounts, program IDs and PDAs differ, and which ones can carry a custom pattern.
- [Custom Solana Token Mint Address: Create a Branded Mint](https://www.customsoladdress.com/blog/custom-solana-token-mint-address) — Use a pre-generated keypair as your SPL token mint with spl-token create-token, for Token or Token-2022, plus metadata and mint authority.
- [Open the complete workflow guide](https://www.customsoladdress.com/guide) to place these checks in order.
- [Open the address generator](https://www.customsoladdress.com/) when you have chosen a compatible format and pattern.

## Frequently asked questions

### Can I change a Solana program's ID after deployment?

No. Upgrades replace the code but keep the program ID. To get a new ID you deploy a new program and migrate clients, so choose the custom ID before the first mainnet deploy.

### Where does Anchor store the program keypair?

In target/deploy/<program_name>-keypair.json. Replace that file with your vanity keypair, then run anchor keys sync so declare_id! matches.

### Do I need the program keypair to upgrade?

No. The CLI accepts a plain address for --program-id on upgrades. The upgrade authority must sign, not the program ID keypair.

### Can a program ID be a PDA?

Program IDs for programs deployed with the upgradeable loader come from a keypair on first deploy. PDAs are derived from a program ID and seeds, which is a different mechanism; see [account types explained](https://www.customsoladdress.com/blog/solana-wallet-mint-program-address).

### Does a custom program ID cost more to deploy?

No. Deployment cost depends on program size and rent for the program data account. The only extra effort is finding a matching keypair before the first deploy.

## Sources

- [Solana docs: Deploying programs](https://solana.com/docs/programs/deploying)

- [Anchor docs: CLI reference](https://www.anchor-lang.com/docs/references/cli)

- [Solana docs: Anchor program structure](https://solana.com/docs/programs/anchor/program-structure)

- [Solana Cookbook: generate a vanity address](https://solana.com/developers/cookbook/wallets/generate-vanity-address)



Editorial method: https://www.customsoladdress.com/about#publication-method
