CustomSol Logo
CustomSOLAddress generator
Menu

Buy us a coffee

Our free tools run entirely on donations. Your support helps maintain the website and develop the tools. Generation runs locally on your device. If we helped you today, a small donation helps keep this service free for everyone.

SOL · Solana network
FTF4fa9So3VjNNcLk7MCtpPFYF36zVFsq2DQTw2QpJaA

Thank you for keeping us running! ❤️

Developers

Custom Solana Program ID: Deploy With a Vanity Keypair

Give a Solana program a recognizable ID: deploy with --program-id, set declare_id! in Anchor, sync keys and separate upgrade authority.

By Updated 7 min readRead as Markdown

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.
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.Open full-size diagram (SVG)Download diagram (PNG)About these visual guides
Short answer: 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 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 explains. Check characters against Base58 before you start. Prefixes of up to six characters can also be found with the CustomSolAddress search form.

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.

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.

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.

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
KeyDeterminesNeeded whenIf leaked
Program ID keypairThe program addressFirst deploy onlyBefore deploy: someone can take the address. After: no effect
Upgrade authorityWho can change the codeEvery upgrade, close or authority changeAttacker can replace the program
Fee payerWho pays deploy costsEach deploy transactionOnly 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 if your team is deciding which address to brand. For the token side of a launch, creating a custom 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

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.

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 and editorial method

The technical references below support the concepts discussed in this article. Examples and comparison worksheets are explanatory, not measured service benchmarks.

Read how these articles are prepared.