> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Deploying Programs

> Complete guide to building, deploying, and managing Solana programs using the Solana CLI.

This section walks through the basic process of deploying a Solana program using
the Solana CLI.

## CLI Command Reference

| Task                               | Command                                                                                       |
| ---------------------------------- | --------------------------------------------------------------------------------------------- |
| Build program                      | `cargo build-sbf`                                                                             |
| Deploy new program                 | `solana program deploy <path_to_program.so>`                                                  |
| Update existing program            | `solana program deploy <path_to_program.so>` (same as deploy)                                 |
| Show program info                  | `solana program show <program-id>`                                                            |
| Transfer program authority         | `solana program set-upgrade-authority <program-id> --new-upgrade-authority <path_to_keypair>` |
| Make program immutable             | `solana program set-upgrade-authority <program-id> --final`                                   |
| Close program                      | `solana program close <program-id> --bypass-warning`                                          |
| Check wallet balance               | `solana balance`                                                                              |
| Request airdrop (localhost)        | `solana airdrop 2` (on devnet, use [faucet.solana.com](https://faucet.solana.com))            |

## Key Concepts

Before diving in, let's clarify some terminology:

- **Program ID**: The onchain address of your program. Users interact with your
  program by referencing the Program ID.
- **Program Account**: The onchain account that stores your program's metadata.
  The program account's address is the Program ID. The program account also
  stores the address of the ProgramData Account.
- **ProgramData Account**: The onchain account that stores your program's
  deployed executable code.
- **Program Authority**: The account that has permission to update or close the
  program. By default, this is your CLI wallet.

## Prerequisites

<Steps titleSize="h3">

<Step title="Install the Solana CLI">

First, [install the Solana CLI](/developers/docs/quickstart).

</Step>

<Step title="Set Up Wallet">

After installation, create a local keypair wallet. The address of this wallet is
set as the default program authority when deploying programs:

```bash Terminal
solana-keygen new
```

This creates a keypair at `~/.config/solana/id.json` by default.

</Step>

<Step title="Configure Cluster">

Choose which Solana cluster to deploy to. Use the `solana config get` command to
check your current configuration:

```bash Terminal
solana config get
```

```text Output
Config File: ~/.config/solana/cli/config.yml
RPC URL: http://localhost:8899
WebSocket URL: ws://localhost:8900/ (computed)
Keypair Path: ~/.config/solana/id.json
Commitment: confirmed
```

Switch between clusters as needed:

```bash Terminal
solana config set --url mainnet-beta
solana config set --url devnet
solana config set --url localhost
solana config set --url testnet
solana config set --url "https://your-rpc-url.com"
```

</Step>

<Step title="Fund Wallet">

You'll need SOL to pay for program deployments. The amount depends on your
program size.

On devnet, get free devnet SOL from the
[Solana Faucet](https://faucet.solana.com): paste the address that
`solana address` prints and request SOL. The devnet RPC faucet is closed, so
`solana airdrop` works only on a local validator. On localhost, fund your
wallet with the `solana airdrop` command:

```bash Terminal
solana airdrop 2
```

```text Output
Requesting airdrop of 2 SOL
Signature: 5zQKxvRdgJDA8fRGPdKfGxRLnLpwmNnMXGYxfBqFSUPqc5BTmFPrTG8vnC4HvKDVY8zQ8aQxZxcEE7WFpGhZGVAA
2 SOL
```

Check your wallet balance:

```bash Terminal
solana balance
```

```text Output
2 SOL
```

</Step>

</Steps>

## Basic Operations

### Build Program

To build a program, use the `cargo build-sbf` command:

```bash Terminal
cargo build-sbf
```

<Steps>
  <Step title="Example Program">
    Here is a minimal Solana program that prints "Hello, Solana!" to the program
    logs.

    ```rs src/lib.rs
    use solana_program::{
        account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, msg, pubkey::Pubkey,
    };

    entrypoint!(process_instruction);

    pub fn process_instruction(
        _program_id: &Pubkey,
        _accounts: &[AccountInfo],
        _instruction_data: &[u8],
    ) -> ProgramResult {
        msg!("Hello, Solana!");
        Ok(())
    }
    ```

    ```toml Cargo.toml
    [package]
    name = "hello_world"
    version = "0.1.0"
    edition = "2021"

    [lib]
    crate-type = ["cdylib", "lib"]

    [dependencies]
    solana-program = "2.2.0"
    ```
  </Step>

  <Step title="Build Output">
    Build your program using the `cargo build-sbf` command:

    ```bash Terminal
    cargo build-sbf
    ```

    This creates two important files in `target/deploy/`:

    1. `hello_world-keypair.json`: A keypair file whose public key will be used as
       your Program ID
    2. `hello_world.so`: The compiled program executable

    ```json target/deploy/hello_world-keypair.json
    [
      203, 253, 43, 62, 165, 111, 94, 222, 105, 225, 218, 85, 143, 9, 114, 96, 243,
      181, 114, 89, 72, 230, 124, 85, 59, 165, 198, 23, 240, 212, 23, 154, 229, 241,
      153, 61, 153, 105, 79, 204, 193, 163, 33, 65, 82, 183, 49, 240, 224, 137, 248,
      24, 128, 25, 192, 197, 118, 235, 239, 67, 85, 156, 219, 231
    ]
    ```

    ```txt target/deploy/hello_world.so
    [binary executable file]
    ```
  </Step>
</Steps>

### Check Program Size and Cost

Deploying a program requires SOL to be allocated to the program account based on
the size of the program. Larger programs cost more SOL to deploy.

Check your program's size:

```bash Terminal
wc -c < ./target/deploy/hello_world.so
```

```text Output
18504
```

Calculate the required SOL for this size (bytes):

```bash Terminal
solana rent 18504
```

```text Output
Rent-exempt minimum: 0.09465056 SOL
```

This output uses the mainnet rate as of October 2026 (5,080 lamports per
byte). Local test networks use an older, higher rate.

<Info>
  You'll need slightly more SOL than shown to cover deployment transaction fees.
</Info>

### Deploy Program

Use the `solana program deploy` command to deploy your program:

```bash Terminal
solana program deploy ./target/deploy/hello_world.so
```

```text Output
Program Id: 7NxQjW8H8hVcqBKgXbVDWqGQCovHbqDW9p1SJJwUyTpE
Signature: 2BYwsqRP7ZwBNQvJp3S8bphTJ4zKW5JBPVMqCTE5KyLkP8xHzAyUEeC4LdTgjJdGBKHWNCkRF8Mf1T1WkLFyEu8W
```

The **Program Id** shown is your program's permanent address on the network.

<Note>

To deploy with a specific Program ID (instead of the auto-generated one), use:

```bash Terminal
solana program deploy ./target/deploy/hello_world.so --program-id ./custom-keypair.json
```

You can generate new keypairs using the `solana-keygen` command:

```bash Terminal
solana-keygen new -o ./custom-keypair.json
```

</Note>

### Update Program

Update your program using the same `solana program deploy` command:

1. Make changes to your program code
2. Rebuild your program: `cargo build-sbf`
3. Deploy the update:

```bash Terminal
solana program deploy ./target/deploy/hello_world.so
```

```text Output
Program Id: 7NxQjW8H8hVcqBKgXbVDWqGQCovHbqDW9p1SJJwUyTpE
Signature: 3zKnXDfEm1R8hVcEmTnNFYUaFjVVbLJrKdFj5hBMXoBRfz8xGyDhCYgKr9YY5KxKYPEUQQVfwEPNz9hQGvYhLNBJ
```

<Info>

If your updated program requires more space (bytes) than currently allocated,
the deployment will automatically extend the program account. This happens when
your new program is larger than the previous version. The program account needs
additional bytes to store the new program. The CLI will calculate the required
SOL and deduct it from your wallet automatically.

You can also manually extend a program to allocate more bytes. The minimum
extension is 10,240 bytes (10 KiB), unless you are extending to the maximum
program size
([SIMD-0431](https://github.com/solana-foundation/solana-improvement-documents/blob/main/proposals/0431-minimum-extend-program-size.md)):

```bash Terminal
solana program extend 7NxQjW8H8hVcqBKgXbVDWqGQCovHbqDW9p1SJJwUyTpE 10240
```

```text Output
Extended Program Id 7NxQjW8H8hVcqBKgXbVDWqGQCovHbqDW9p1SJJwUyTpE by 10240 bytes
```

</Info>

## Program Management

Once your program is deployed, there are several common commands to manage the
program account.

### View Program Metadata

To check your program metadata, use the `solana program show` command:

```bash Terminal
solana program show 7NxQjW8H8hVcqBKgXbVDWqGQCovHbqDW9p1SJJwUyTpE
```

Example output:

```txt
$ solana program show 7283x8k8fyBcfaFLyPsxbd2VV1AMmZFP7FNoyTXVKJw7
Program Id: 7283x8k8fyBcfaFLyPsxbd2VV1AMmZFP7FNoyTXVKJw7
Owner: BPFLoaderUpgradeab1e11111111111111111111111
ProgramData Address: Gqn7YQVCP8NtYV1qkEqR4Udhj8EJ3fkikvS7HskCNQ7c
Authority: 5kh6HxYZiAebF8HWLsUWod2EaQQ6iWHpHYCz8UcmFbM1
Last Deployed In Slot: 6573
Data Length: 18504 (0x4848) bytes
Balance: 0.09487916 SOL
```

<Note>
  **`Program Id`**

  The Program ID is the onchain address of your program account. Users and other
  programs invoke your program by referencing this ID in their transactions.

  **`Owner`**

  The Owner identifies which loader was used to deploy this program. For most
  programs, this will be the BPF Upgradeable Loader.

  **`ProgramData Address`**

  The ProgramData Address points to the separate account that stores your
  program's executable code.

  **`Authority`**

  The Authority is the account that has permission to upgrade or close this
  program. Only the authority can deploy updates or close the program to reclaim
  the program's allocated SOL.

  **`Last Deployed In Slot`**

  The Last Deployed In Slot indicates when this program was last updated.

  **`Data Length`**

  The Data Length shows the total bytes allocated to this program. This space can
  accommodate future updates that may be larger than the current program size.

  **`Balance`**

  The Balance displays the SOL allocated to the program account to store its data.
</Note>

### Transfer Program Authority

To transfer the program authority to a different account, use the
`solana program set-upgrade-authority` command:

```bash Terminal
solana program set-upgrade-authority 7NxQjW8H8hVcqBKgXbVDWqGQCovHbqDW9p1SJJwUyTpE --new-upgrade-authority ./new-authority-keypair.json
```

<Warning>
  After transferring the program authority, you can no longer update the program
  unless you have access to the new authority keypair.
</Warning>

### Make Your Program Immutable

To make your program immutable, use the `solana program set-upgrade-authority`
command with the `--final` flag to remove the program authority:

```bash Terminal
solana program set-upgrade-authority 7NxQjW8H8hVcqBKgXbVDWqGQCovHbqDW9p1SJJwUyTpE --final
```

```text Output
Account Type: Program
Authority: none
```

<Warning>
  Once a program is immutable, it can never be updated or closed.
</Warning>

### Close Your Program

To close your program and reclaim the SOL allocated to the program account, use
the `solana program close` command:

```bash Terminal
solana program close 7NxQjW8H8hVcqBKgXbVDWqGQCovHbqDW9p1SJJwUyTpE --bypass-warning
```

```text Output
Closed Program Id 7NxQjW8H8hVcqBKgXbVDWqGQCovHbqDW9p1SJJwUyTpE, 0.09487916 SOL reclaimed
```

<Warning>
  Once closed, the Program ID can not be reused. You cannot deploy a new program
  to the same address.
</Warning>

## Utility Commands

### List All Programs

View all programs where your current wallet is the authority:

```bash Terminal
solana program show --programs
```

Example output (abbreviated):

```txt
Program Id                                       | Slot       | Authority                                      | Balance
7NxQjW8H8hVcqBKgXbVDWqGQCovHbqDW9p1SJJwUyTpE     | 249885434  | 5kh6HxYZiAebF8HWLsUWod2EaQQ6iWHpHYCz8UcmFbM1   | 0.09487916 SOL
3KSGCk4m5hqJkTjPHBXUCPcqMwJnK3VmkqEsFUKKGJPK     | 249883212  | 5kh6HxYZiAebF8HWLsUWod2EaQQ6iWHpHYCz8UcmFbM1   | 0.2091436 SOL
```

### Download a Deployed Program

To download a deployed program, use the `solana program dump` command:

```bash Terminal
solana program dump 7NxQjW8H8hVcqBKgXbVDWqGQCovHbqDW9p1SJJwUyTpE ./downloaded_program.so
```

```text Output
Wrote program to ./downloaded_program.so
```

## Advanced Options

### Deployment Flags

When the Solana network is congested, use these flags to help with program
deployment.

Example Usage:

```bash Terminal
solana program deploy ./target/deploy/hello_world.so \
    --with-compute-unit-price 10000 \
    --max-sign-attempts 10 \
    --use-rpc
```

Options explained:

- **`--with-compute-unit-price`**: Set priority fee in micro-lamports (1
  micro-lamport = 0.000001 lamport) per compute unit. Check
  [Helius Priority Fee API](https://docs.helius.dev/guides/priority-fee-api) for
  current rates. A priority fee is an additional fee that is paid to the current
  leader to prioritize your transaction.
- **`--max-sign-attempts`**: Number of times to retry with a new blockhash if
  transactions expire. (Default: 5)
- **`--use-rpc`**: Send transactions to the configured RPC. This flag requires a
  [stake-weighted](/developers/docs/defi/stake-weighted-qos) RPC connection from providers
  such as [Triton](https://triton.one/) or [Helius](https://www.helius.dev/).
