> 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/de/entwicklerleitfaden/call-solana-from-evm.md).

# Solana von EVM aus aufrufen

Rufe Solana-Programme aus Solidity über Roms CPI und Hilfs-Precompiles auf.

Romes Precompiles ermöglichen es Solidity-Contracts, Solana-Programme direkt aufzurufen. Dieser Leitfaden erklärt die Mechanik.

## Voraussetzungen

* Die Rome-Solidity-Interfaces aus dem öffentlichen [`rome-solidity`](https://github.com/rome-protocol/rome-solidity) Repo (von GitHub installiert, nicht über npm — siehe [Solidity bereitstellen](https://docs.rome.builders/de/entwicklerleitfaden/deploy-solidity.md#using-the-rome-solidity-sdk)) — die Precompile-Interfaces befinden sich in [`contracts/interface.sol`](https://github.com/rome-protocol/rome-solidity/blob/master/contracts/interface.sol)
* Ein bereitgestellter Rome-Contract (siehe [Solidity bereitstellen](https://docs.rome.builders/de/entwicklerleitfaden/deploy-solidity.md))

Binde jedes Interface an seine Precompile-Adresse:

```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);
```

## Das CpiProgram-Precompile

`CpiProgram` (`0xFF…08`) löst CPI aus (`invoke` / `invoke_signed`) plus Cross-State-Leseabkürzungen (`account_info`, `account_data_at`, `account_u64_at`, `account_lamports`, `pdas_batch_derive`):

```solidity
// Rufe ein Solana-Programm auf
CpiProgram.invoke(programId, accounts, instructionData);

// Aufruf mit PDA-Signatur: Das PDA mit externer Autorität deines Contracts signiert, plus ein
// gesalzenes Unter-PDA pro Eintrag in `salts` (Rome leitet ["EXTERNAL_AUTHORITY", contract, salt] ab)
CpiProgram.invoke_signed(programId, accounts, data, salts);
```

## Lamports übertragen

Für einfache Lamport- und SPL-Transfers verwende das HelperProgram-Precompile — kein manuell erstelltes CPI nötig. Ein Contract, der es aufruft, fungiert als **selbst**: Die folgenden Transfers bewegen die eigenen Lamports und Tokens des Contracts (sein PDA mit externer Autorität signiert), nicht die des Nutzers. Damit ein Contract die SPL-Token eines Nutzers in ein von ihm kontrolliertes Token-Konto zieht und weiß, wem sie gehören, erteilt der Nutzer eine SPL-Delegation. Ein ERC-20 `transfer` oder `transferFrom` an einen Contract schreibt nur dem Escrow-Ledger des Wrappers gut und gibt dem Contract kein Token-Konto, von dem er ausgeben kann — siehe [Integrieren Sie ein Solana-Programm](https://docs.rome.builders/de/entwicklerleitfaden/integrate-solana-program.md).

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

    // Übertrage Lamports vom PDA dieses Contracts an das PDA einer EVM-Adresse
    function transferSol(address to, uint64 lamports) external {
        Helper.transfer_lamports(to, lamports);
    }

    // Übertrage einen SPL-Token aus dem von diesem Contract-PDA gehaltenen Token-Konto
    function transferSpl(address to, uint64 tokens, bytes32 mint) external {
        Helper.transfer_spl(to, tokens, mint);
    }

    // Erstelle das ATA des Aufrufers für ein Mint
    function createAta(bytes32 mint) external {
        Helper.create_ata(msg.sender, mint);
    }
}
```

`transfer_spl` hat mehrere Überladungen (einschließlich einer Delegierten-Variante für `transferFrom` Flows); siehe `interface.sol`. Auf dem Cached-Track verwende `ISplCached` (`0xff…05`) / `IAssociatedSplCached` (`0xff…06`) stattdessen — ein Contract verwendet konsequent einen Track, und nur der Legacy-Track kann `invoke` ein benutzerdefiniertes Programm (siehe [Integrieren Sie ein Solana-Programm](https://docs.rome.builders/de/entwicklerleitfaden/integrate-solana-program.md)).

## Kontodaten lesen

Lies die Daten eines beliebigen Solana-Kontos über die CpiProgram-Leseabkürzungen:

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

## PDA-Ableitung

Finde Program Derived Addresses aus Solidity über das System-Precompile:

```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);
```

## Base58-Konvertierung

Konvertiere zwischen `bytes32` und Base58 (dem Adressformat von Solana):

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

## Benutzerdefinierte Solana-Programme aufrufen

Um ein beliebiges Solana-Programm aufzurufen, erstelle die Kontoliste und die Instruktionsdaten selbst:

```solidity
contract CustomCPI {
    ICrossProgramInvocation constant CpiProgram = ICrossProgramInvocation(0xFF00000000000000000000000000000000000008);
    bytes32 constant MY_PROGRAM = 0x0000000000000000000000000000000000000000000000000000000000000000; // deine Solana-Programm-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);
    }
}
```

## Wichtige Einschränkungen

1. **Alle Konten müssen im Voraus deklariert werden.** Die Solana-Transaktion muss jedes Konto enthalten, das das CPI berühren wird — eine dynamische Kontoerkennung innerhalb von CPI ist nicht möglich.
2. **CPI-Tiefenlimit: 4 Ebenen.** Rome-EVM → dein Ziel → der Aufruf des Ziels → noch einer. Plane deine Aufruftiefe.
3. **Solana-Public-Keys sind `bytes32`,** keine 20-Byte-Ethereum-Adressen.
4. **Instruktionsdaten sind rohe Bytes** im Format, das das Zielprogramm erwartet (typischerweise Borsh, Little-Endian).

## Wie es weitergeht

* **Sieh es in einer realen App** — [cardo](https://github.com/rome-protocol/cardo) sendet CPI-Aufrufe direkt aus der Wallet des Nutzers an das Precompile, ohne Adapter-Contract; [rome-dex](https://github.com/rome-protocol/rome-dex) (Dual-Lane-AMM) macht dasselbe und hat außerdem einen Router-Contract ohne Verwahrung; [aerarium](https://github.com/rome-protocol/aerarium) ist eine Lending-App, die keine Solana-Programme aus Solidity aufruft.
* [Integrieren Sie ein Solana-Programm](https://docs.rome.builders/de/entwicklerleitfaden/integrate-solana-program.md) — die Solana-Identität des Nutzers, das Signieren als diese, die Ein-Track-Regel und die Kontobereitstellung für ein echtes Programm auf der anderen Seite
* [Precompile-Referenz](https://docs.rome.builders/de/referenz/precompiles.md) — jeder Selektor auf jedem Precompile
* [EVM aus Solana aufrufen](https://docs.rome.builders/de/entwicklerleitfaden/call-evm-from-solana.md) — das Gegenteil: EVM-Contracts von einer Solana-Wallet aus steuern
* [Token-Interop](https://docs.rome.builders/de/kernkonzepte/token-interop.md) — wie ERC-20- und SPL-Token zusammenarbeiten
* [Beschränkungen](https://docs.rome.builders/de/kernkonzepte/constraints.md) — CPI-Tiefe und andere Grenzen


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rome.builders/de/entwicklerleitfaden/call-solana-from-evm.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
