> For the complete documentation index, see [llms.txt](https://docs.rome.builders/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rome.builders/id/panduan-pengembang/call-solana-from-evm.md).

# Panggil Solana dari EVM

Precompile Rome memungkinkan kontrak Solidity memanggil program Solana secara langsung. Panduan ini membahas mekanismenya.

## Prasyarat

* Antarmuka Rome Solidity dari publik [`rome-solidity`](https://github.com/rome-protocol/rome-solidity) repositori (publikasi npm tertunda) — antarmuka precompile berada di [`contracts/interface.sol`](https://github.com/rome-protocol/rome-solidity/blob/master/contracts/interface.sol)
* Kontrak Rome yang telah dideploy (lihat [Penerapan Solidity](/id/panduan-pengembang/deploy-solidity.md))

Tautkan setiap antarmuka ke alamat precompilenya:

```solidity
import {ICrossProgramInvocation, ISystemProgram, IHelperProgram}
    from "@rome-protocol/rome-solidity/contracts/interface.sol";

ICrossProgramInvocation constant CpiProgram    = ICrossProgramInvocation(0xFF00000000000000000000000000000000000008);
ISystemProgram          constant SystemProgram = ISystemProgram(0xFF00000000000000000000000000000000000007);
IHelperProgram          constant Helper        = IHelperProgram(0xFF00000000000000000000000000000000000009);
```

## Precompile CpiProgram

`CpiProgram` (`0xFF…08`) menjalankan CPI (`invoke` / `invoke_signed`) plus pintasan baca lintas-state (`account_info`, `account_data_at`, `account_u64_at`, `account_lamports`, `pdas_batch_derive`):

```solidity
// Panggil program Solana
CpiProgram.invoke(programId, accounts, instructionData);

// Panggil dengan penandatanganan PDA (kontrak Anda menandatangani sebagai PDA)
CpiProgram.invoke_signed(programId, accounts, data, seeds);
```

## Transfer lamport

Untuk transfer SOL/lamport dan SPL sederhana dari PDA pemanggil, gunakan precompile HelperProgram — tidak perlu CPI buatan tangan:

```solidity
contract Transfers {
    IHelperProgram constant Helper = IHelperProgram(0xFF00000000000000000000000000000000000009);

    // Transfer lamport ke PDA alamat EVM
    function transferSol(address to, uint64 lamports) external {
        Helper.transfer_lamports(to, lamports);
    }

    // Transfer token SPL dari PDA pemanggil
    function transferSpl(address to, uint64 tokens, bytes32 mint) external {
        Helper.transfer_spl(to, tokens, mint);
    }

    // Buat ATA pemanggil untuk sebuah mint
    function createAta(bytes32 mint) external {
        Helper.create_ata(msg.sender, mint);
    }
}
```

`transfer_spl` memiliki beberapa overload (termasuk varian delegate untuk `transferFrom` alur); lihat `interface.sol`. Pada jalur cached, gunakan `ISplCached` (`0xff…05`) / `IAssociatedSplCached` (`0xff…06`) sebagai gantinya — kontrak menggunakan satu jalur secara konsisten.

## Membaca data akun

Baca data akun Solana apa pun melalui pintasan baca CpiProgram:

```solidity
(
    uint64 lamports,
    bytes32 owner,
    bool isSigner,
    bool isWritable,
    bool executable,
    bytes memory data
) = CpiProgram.account_info(accountPubkey);
```

## Derivasi PDA

Temukan Program Derived Address dari Solidity melalui precompile System:

```solidity
ISystemProgram.Seed[] memory seeds = new ISystemProgram.Seed[](2);
seeds[0] = ISystemProgram.Seed("my-program-seed");
seeds[1] = ISystemProgram.Seed(abi.encodePacked(someValue));

(bytes32 pda, uint8 bump) = SystemProgram.find_program_address(targetProgramId, seeds);
```

## Konversi Base58

Konversi antara `bytes32` dan base58 (format alamat Solana):

```solidity
bytes memory base58Str = SystemProgram.bytes32_to_base58(pubkey);
bytes32 pubkey = SystemProgram.base58_to_bytes32(base58Bytes);
```

## Memanggil program Solana kustom

Untuk memanggil program Solana apa pun, buat sendiri daftar akun dan data instruksinya:

```solidity
contract CustomCPI {
    ICrossProgramInvocation constant CpiProgram = ICrossProgramInvocation(0xFF00000000000000000000000000000000000008);
    bytes32 constant MY_PROGRAM = 0x0000000000000000000000000000000000000000000000000000000000000000; // your Solana program ID

    function callMyProgram(bytes32 account1, bytes32 account2, bytes calldata ixData) external {
        ICrossProgramInvocation.AccountMeta[] memory accounts = new ICrossProgramInvocation.AccountMeta[](2);
        accounts[0] = ICrossProgramInvocation.AccountMeta(account1, false, true);
        accounts[1] = ICrossProgramInvocation.AccountMeta(account2, false, false);

        CpiProgram.invoke(MY_PROGRAM, accounts, ixData);
    }
}
```

## Batasan Utama

1. **Semua akun harus dideklarasikan sejak awal.** Transaksi Solana harus menyertakan setiap akun yang akan disentuh CPI — penemuan akun dinamis di dalam CPI tidak dimungkinkan.
2. **Batas kedalaman CPI: 4 tingkat.** Rome EVM → target Anda → panggilan target → satu lagi. Rencanakan kedalaman panggilan Anda.
3. **Pubkey Solana adalah `bytes32`,** bukan alamat Ethereum berukuran 20 byte.
4. **Data instruksi adalah byte mentah** dalam format yang diharapkan program target (biasanya Borsh, little-endian).

## Apa Selanjutnya

* **Lihat di aplikasi nyata** — [rome-dex](https://github.com/rome-protocol/rome-dex) (AMM dua jalur), [cardo](https://github.com/rome-protocol/cardo) (rute CPI ke Meteora / Marinade / Mango / Jupiter), dan [aerarium](https://github.com/rome-protocol/aerarium) memanggil Solana dari Solidity dalam produksi.
* [Panggil EVM dari Solana](/id/panduan-pengembang/call-evm-from-solana.md) — kebalikannya: kendalikan kontrak EVM dari dompet Solana
* [Interoperabilitas Token](/id/konsep-inti/token-interop.md) — cara ERC-20 dan token SPL bekerja bersama
* [Kendala](/id/konsep-inti/constraints.md) — kedalaman CPI dan batasan lainnya


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.rome.builders/id/panduan-pengembang/call-solana-from-evm.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
