> For the complete documentation index, see [llms.txt](https://docs.qorechain.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.qorechain.io/developer-guide/svm-development.md).

# SVM Development

QoreChain includes a **Solana Virtual Machine (SVM)** execution environment, allowing developers to deploy and execute BPF programs using familiar Solana tooling. The SVM module exposes a Solana-compatible JSON-RPC interface on **port 8899**.

***

## Overview

The `x/svm` module provides:

* BPF program deployment and execution
* Data account creation and management
* A Solana-compatible JSON-RPC endpoint
* Bidirectional address mapping between QoreChain and Solana address formats
* Compute budget metering and rent-based storage economics

***

## JSON-RPC Endpoint

| Property      | Value                    |
| ------------- | ------------------------ |
| Default URL   | `http://localhost:8899`  |
| Compatibility | Solana JSON-RPC (subset) |

### Supported Methods

| Method                              | Description                               |
| ----------------------------------- | ----------------------------------------- |
| `getAccountInfo`                    | Retrieve account data and lamport balance |
| `getBalance`                        | Get account balance in lamports           |
| `getSlot`                           | Current slot number                       |
| `getMinimumBalanceForRentExemption` | Minimum balance for a given data size     |
| `getVersion`                        | SVM runtime version info                  |
| `getHealth`                         | Health check for the SVM endpoint         |

***

{% stepper %}
{% step %}

### Deploy a BPF Program

Compile your Solana program to a BPF shared object, then deploy it to QoreChain:

{% code title="Deploy the compiled program" %}

```bash
qorechaind tx svm deploy-program ./my_program.so \
  --from mykey \
  --gas auto \
  --gas-adjustment 1.3 \
  -y
```

{% endcode %}

The transaction response includes the **program ID** in base58 format.
{% endstep %}

{% step %}

### Execute an Instruction

Call an on-chain BPF program with instruction data:

{% code title="Execute instruction" %}

```bash
qorechaind tx svm execute <program-id-base58> <data-hex> \
  --from mykey \
  --gas auto \
  -y
```

{% endcode %}

| Parameter           | Format            | Description                    |
| ------------------- | ----------------- | ------------------------------ |
| `program-id-base58` | Base58 string     | The deployed program's address |
| `data-hex`          | Hex-encoded bytes | Serialized instruction data    |
| {% endstep %}       |                   |                                |

{% step %}

### Create a Data Account

Programs often need accounts to store state. Create one with a specified size and owner:

{% code title="Create data account" %}

```bash
qorechaind tx svm create-account <owner-base58> <space> <lamports> \
  --from mykey \
  --gas auto \
  -y
```

{% endcode %}

| Parameter      | Description                                        |
| -------------- | -------------------------------------------------- |
| `owner-base58` | The program that owns this account (base58)        |
| `space`        | Size of the data field in bytes                    |
| `lamports`     | Initial balance (must meet rent exemption minimum) |

Query the minimum rent-exempt balance for a given size:

{% code title="RPC: getMinimumBalanceForRentExemption" %}

```bash
curl -X POST http://localhost:8899 \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getMinimumBalanceForRentExemption",
    "params": [1024]
  }'
```

{% endcode %}
{% endstep %}

{% step %}

### Using @solana/web3.js

The Solana JavaScript SDK works directly with the QoreChain SVM endpoint:

{% code title="Example using @solana/web3.js" %}

```javascript
import { Connection, PublicKey } from "@solana/web3.js";

const connection = new Connection("http://localhost:8899");

// Check health
const health = await connection.getHealth();
console.log("SVM health:", health);

// Get slot
const slot = await connection.getSlot();
console.log("Current slot:", slot);

// Get account info
const pubkey = new PublicKey("YourBase58ProgramId...");
const accountInfo = await connection.getAccountInfo(pubkey);
console.log("Account data:", accountInfo);

// Get balance
const balance = await connection.getBalance(pubkey);
console.log("Balance (lamports):", balance);
```

{% endcode %}
{% endstep %}
{% endstepper %}

***

## Address Mapping

QoreChain maintains a **bidirectional address mapping** between native Bech32 addresses (`qor1...`) and Solana-style base58 addresses:

| Direction     | Example                                                    |
| ------------- | ---------------------------------------------------------- |
| Native to SVM | `qor1abc...xyz` maps to a deterministic base58 address     |
| SVM to Native | Base58 program addresses map back to `qor1...` equivalents |

The mapping is deterministic and managed by the `x/svm` module. Both representations refer to the same underlying account.

***

## Rent Model

The SVM module uses a **rent-based storage model** to prevent state bloat:

| Parameter                  | Value      |
| -------------------------- | ---------- |
| Lamports per byte per year | `3,480`    |
| Rent exemption multiplier  | `2.0`      |
| Collection frequency       | Each epoch |

* Accounts with a balance **above** `2 * (data_size * 3480 / seconds_per_year)` in lamports are **rent-exempt** and are never charged.
* Accounts **below** the rent-exemption threshold are charged rent each epoch. If the balance reaches zero, the account is purged.

{% hint style="info" %}
**Best practice:** Always fund data accounts above the rent-exemption minimum to avoid unexpected account deletion.
{% endhint %}

***

## Compute Budget

Each instruction execution is metered with compute units:

| Parameter                                | Value       |
| ---------------------------------------- | ----------- |
| Max compute units per instruction        | `1,400,000` |
| Max CPI (cross-program invocation) depth | `4`         |
| Max program size                         | `10 MB`     |
| Max account data size                    | `10 MB`     |

Programs that exceed the compute budget are halted and the transaction is reverted.

***

## Parameters Summary

| Parameter                   | Value        |
| --------------------------- | ------------ |
| `max_program_size`          | 10 MB        |
| `max_account_data_size`     | 10 MB        |
| `compute_budget_max`        | 1,400,000 CU |
| `max_cpi_depth`             | 4            |
| `lamports_per_byte_year`    | 3,480        |
| `rent_exemption_multiplier` | 2.0          |
| JSON-RPC port               | 8899         |

***

## Cross-VM Interoperability

SVM programs can communicate with EVM and CosmWasm contracts through the **asynchronous** cross-VM message path:

{% code title="Cross-VM call example" %}

```bash
qorechaind tx crossvm call \
  --source-vm svm \
  --target-vm evm \
  --target-contract 0x1234...abcd \
  --payload '...' \
  --from mykey \
  -y
```

{% endcode %}

Messages are queued and processed by the EndBlocker. See [Cross-VM Interoperability](broken://pages/f230af5f198d32323f97e29863d5cc9146006931) for details on the message lifecycle and timeout behavior.

***

## Next Steps

* [Cross-VM Interoperability](broken://pages/f230af5f198d32323f97e29863d5cc9146006931) -- Communication between SVM, EVM, and CosmWasm
* [EVM Development](broken://pages/77165eb8a7fa0ade0820d31a8f8919bf39b28c9f) -- Solidity smart contracts on QoreChain
* [CosmWasm Development](broken://pages/8894f12b6421761a58febee12189d32313210767) -- Rust-based WebAssembly contracts


---

# 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://docs.qorechain.io/developer-guide/svm-development.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.
