> For the complete documentation index, see [llms.txt](https://wiki.solaxy.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.solaxy.io/using-custom-code/deploying-programs.md).

# Deploying Programs

To deploy the programs please use the RPC method. TPU clients are not supported.\
Use the following command if using Anchor: `anchor deploy -- --use-rpc` or `solana program deploy --use-rpc`

\
Alternatively, it can be done with Rust:

{% code overflow="wrap" %}

```rust
pub(crate) async fn deploy_program(
    client: &TestClient,
    payer: &Keypair,
    bytecode: &[u8],
) -> anyhow::Result<Keypair> {
    let program_keypair = Keypair::new();
    let program_pubkey = program_keypair.pubkey();

    let program_data_pubkey = get_program_data_address(&program_pubkey);

    let latest_blockhash = client
        .svm_get_latest_blockhash()
        .await
        .map_err(|e| anyhow!("Failed to retrieve the latest blockhash: {e}"))?;

    let buffer_lamports = client
        .get_minimum_balance_for_rent_exemption(
            bytecode.len() + UpgradeableLoaderState::size_of_buffer_metadata(),
        )
        .await
        .map_err(|e| anyhow!("Failed to get a rent exempt balance: {e}"))?;

    let deploy_txs = create_deploy_program_transactions(
        payer,
        &program_keypair,
        payer,
        bytecode.to_vec(),
        buffer_lamports,
        latest_blockhash,
    )
    .map_err(|e| anyhow!("Failed to initialize transactions for program deployment: {e}"))?;

    for tx in deploy_txs {
        let tx_hash = client
            .svm_send_transaction(&tx)
            .await
            .map_err(|e| anyhow!("Failed to send a transaction: {e}"))?
            .to_string();
    }

    sleep(Duration::from_secs(SLEEP_DURATION_SECONDS)).await;

    let program_account = client
        .svm_get_account_info(program_pubkey)
        .await
        .map_err(|e| anyhow!("Failed to retrieve a program account: {e}"))?;

    let program_account_data: UpgradeableLoaderState = bincode::deserialize(&program_account.data)
        .map_err(|e| anyhow!("Failed to deserialize program account data: {e}"))?;

    if let UpgradeableLoaderState::Program {
        programdata_address,
    } = program_account_data
    {
        assert_eq!(
            programdata_address, program_data_pubkey,
            "Expected programdata_address from program account's metadata to match \
            program_data_pubkey derived for program's pubkey"
        );
    }

    let program_data_account = client
        .svm_get_account_info(program_data_pubkey)
        .await
        .map_err(|e| anyhow!("Failed to retrieve a program data account: {e}"))?;

    let program_data_account_metadata: UpgradeableLoaderState = bincode::deserialize(
        &program_data_account.data[..UpgradeableLoaderState::size_of_programdata_metadata()],
    )
    .map_err(|e| anyhow!("Failed to deserialize program data account metadata: {e}"))?;

    if let UpgradeableLoaderState::ProgramData {
        upgrade_authority_address,
        ..
    } = program_data_account_metadata
    {
        let authority = upgrade_authority_address
            .expect("Expected program data account to have a program authority");
    }

    Ok(program_keypair)
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.solaxy.io/using-custom-code/deploying-programs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
