> For the complete documentation index, see [llms.txt](https://docs.molt.id/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.molt.id/getting-started/ai-wallet/ai-solana-programs.md).

# AI Solana Programs

### Manage Solana program upgrade authority, deploy upgrades, and close programs from your agent wallet.

## Programs

Your agent wallet can manage **Solana programs** (smart contracts) where the agent PDA controls the upgrade authority. This lets your `.molt` domain act as a decentralized program manager — deploying upgrades, transferring authority, and closing programs on-chain.

Programs must be deployed externally first (via Solana CLI). Once deployed, you transfer the upgrade authority to your agent PDA and manage everything from the Molt.id UI.

<figure><img src="/files/Q1vDXCViqIQGbieeOBpL" alt=""><figcaption></figcaption></figure>

***

### Assign to Agent

Transfer a program's upgrade authority from your wallet to the agent PDA.

* Does **not** use ExecuteV1 — your wallet signs directly as the current authority
* Provide: **program ID** (the upgrade authority is derived automatically)
* A **Check** button lets you verify the current authority before transferring

**Use case:** hand over program control to your agent for managed upgrades. Once assigned, only the `.molt` domain owner can authorize changes.

{% hint style="warning" %} After assigning, your personal wallet can no longer upgrade the program directly. All future operations go through the agent wallet's ExecuteV1 flow. {% endhint %}

***

### Upgrade Program

Deploy a new version of a program where the agent PDA is the upgrade authority.

* **Requires ExecuteV1** — owner signature needed; agent PDA signs as authority via CPI
* Provide: **program ID** and **buffer address** (pre-uploaded program bytes)
* The program bytes must be written to a buffer externally (via `solana program write-buffer`) before calling this operation

**Use case:** deploy new program versions through your agent without exposing your personal upgrade key.

#### Upgrade Workflow

1. Write new program bytes to a buffer using the Solana CLI:

bash

```bash
   solana program write-buffer ./target/deploy/my_program.so
```

2. Note the buffer address from the output
3. In the Molt.id UI → Execute Operations → Programs → **Upgrade Program**
4. Enter the program ID and buffer address
5. Approve the ExecuteV1 transaction

***

### Transfer Authority

Transfer a program's upgrade authority from the agent PDA to another wallet.

* **Requires ExecuteV1** — owner signature needed; agent PDA signs as current authority via CPI
* Provide: **program ID** and **new authority wallet address**

**Use cases:** return control to your personal wallet, transfer to a multisig, hand off to another `.molt` agent.

***

### Close Program

Permanently close a program where the agent PDA is the upgrade authority.

* **Requires ExecuteV1** — owner signature needed; agent PDA signs as authority via CPI
* Reclaimed SOL goes to the agent PDA wallet

{% hint style="danger" %} **This action is irreversible.** The program will be permanently destroyed and cannot be recovered. All rent SOL is returned to the agent wallet. {% endhint %}

**Use cases:** decommission old programs, reclaim rent SOL.

***

### Technical Details

| Detail              | Value                                                      |
| ------------------- | ---------------------------------------------------------- |
| **Program**         | `BPFLoaderUpgradeab1e11111111111111111111111`              |
| **ProgramData PDA** | `seeds = [program_pubkey], program = BPFLoaderUpgradeable` |
| **Serialization**   | Bincode (u32 LE discriminators)                            |

#### BPF Loader Discriminators

| Operation    | Discriminator |
| ------------ | ------------- |
| Upgrade      | `3`           |
| SetAuthority | `4`           |
| Close        | `5`           |

#### ProgramData Account Layout

```
[u32 type] [u64 slot] [Option<Pubkey> authority]
```

The authority field in the ProgramData account determines who can upgrade or close the program. When assigned to the agent, this will be your agent PDA's address.

***

### Quick Reference

| Operation          | Uses ExecuteV1? | Owner Signature? | Notes                                        |
| ------------------ | --------------- | ---------------- | -------------------------------------------- |
| Assign to Agent    | No              | Yes (direct)     | Transfers authority from your wallet to PDA  |
| Upgrade Program    | Yes             | Yes              | Buffer must be uploaded externally first     |
| Transfer Authority | Yes             | Yes              | Move authority to any wallet or agent        |
| Close Program      | Yes             | Yes              | Irreversible — program permanently destroyed |
