For the complete documentation index, see llms.txt. This page is also available as Markdown.

5. Call Solana from Solidity

Use Rome's CPI and Helper precompiles to read Solana accounts, create token accounts and call Solana programs from a Solidity contract.

On Rome a Solidity contract can read Solana accounts and call Solana programs in the same transaction. You will read a Solana token balance, create a token account and learn how to build a program call.

What you'll learn

  • What a precompile is on Rome and which three you will use most.

  • Whose signature a Solana program sees when your contract calls it.

  • How to read Solana state and create a token account from Solidity.

  • The rules that decide whether a Solana call works: declared accounts, one track, atomic only.

Before you start

  • Finish 4. How Rome runs your code. The atomic budget and the 64-account cap matter here.

  • Have your Hadrian wallet funded and your deploy setup from lesson 3 working. Faucets are listed in Faucets.

  • Install the Rome Solidity interfaces from the rome-solidity repo, as described in Deploy Solidity.

Precompiles are the door

A precompile is a fixed address that runs native code instead of bytecode. Ethereum has a few, such as ecrecover. Rome adds precompiles whose job is to reach Solana. You call them like any contract, through an interface.

You will use three:

Precompile
What it gives you

CpiProgram

invoke and invoke_signed to call any Solana program, plus read-only views of Solana accounts

HelperProgram

Ready-made token and account operations: create a token account, transfer SPL tokens, derive addresses

System

PDA derivation and base58 conversion

The addresses are in Precompile reference and Contract addresses. You do not need to type them. Importing interface.sol from rome-solidity gives you ready-made constants named CpiProgram, HelperProgram and SystemProgram.

Who signs

When your contract calls a precompile, Solana sees your contract's own identity, not the user's. Every EVM address has a Solana program-derived address, its external-authority PDA. It owns that address's token accounts and signs on its behalf.

This is the same rule you know from ERC-20: a contract cannot move a user's assets unless the user allowed it. Lesson 6 shows how the user allows it on Rome. The rule and the three ways to hold a user's position are in Integrate a Solana program.

Step 1: read before you write

Start with reads. They change no state and work in atomic and iterative execution. Read before you mutate: once a cached call has run, legacy-track reads are refused for the rest of the transaction.

Solana addresses are bytes32 here, not 20-byte addresses. The other reads, account_info, account_data_at and account_u64_at, let you inspect any Solana account. See Reading account data.

Step 2: use a helper

For common jobs you need no hand-built instruction. The Helper creates token accounts, moves SPL tokens and lamports, and converts between gas and lamports. The signatures are in contracts/interface.sol, and a worked contract is in Transfer lamports.

A contract that calls the Helper acts as itself. The tokens it moves are its own, not the user's.

Step 3: call any Solana program

For a program the helpers do not cover, build the account list and the instruction bytes yourself and call invoke. Each account is a pubkey plus two flags, signer and writable. The instruction data is whatever the target program expects, usually Borsh.

The full contract is in Calling custom Solana programs. invoke_signed adds salted sub-PDAs when the target needs more than one signer from your contract. To get a PDA's address inside Solidity, use find_program_address on the System precompile; see PDA derivation.

The rules that decide whether it works

  • Declare every account. Solana needs the full account list before the call runs. The proxy finds it by emulating your transaction first, so each account must be derivable from inputs the contract has. The total must stay within the 64-address cap.

  • Stay atomic. A call that makes a legacy-track CPI cannot run iteratively. It has to fit one atomic transaction, so keep each action to one token movement and one CPI.

  • Pick one track. Rome has two families of precompiles that change Solana state: legacy (CpiProgram, HelperProgram, Withdraw) and cached (the ...Cached set). A transaction uses one family. Only the legacy track can call a custom program. Read the table in Integrate a Solana program.

  • Keep depth shallow. Your call to a Solana program uses CPI levels, and so does every program it calls in turn. Solana's depth limit is low. Constraints explains the levels.

  • No calls back into Rome. A CPI cannot name or call the Rome program. It cannot name the Solana fee payer except in a plain System transfer instruction.

Check yourself

Add createMyAta to SolanaPeek and deploy it to Hadrian. Then:

  1. Call myTokenAccount and myBalance with a read call from your wallet address.

  2. Send a transaction that calls createMyAta.

  3. Open the transaction on the Hadrian explorer. See Via explorer.

You should see the Solana instruction behind your call and its compute units. A call that reaches Solana shows a Solana program in the explorer, not only an EVM call.

1. A contract calls HelperProgram.transfer_spl. Whose tokens move?

The contract's own. The signer is the contract's external-authority PDA. To move a user's tokens the user must grant a right first.

2. Why must a call that uses invoke fit one atomic transaction?

Legacy-track CPIs are refused inside an iterative transaction. If the call needs more than one Solana transaction, it fails.

3. Which reads can you rely on in any execution mode?

The read-only views: account_info, account_data_at, account_u64_at, account_lamports, pdas_batch_derive and the Helper reads such as user_balance. They have no side effects. Run them before any cached mutation in the same transaction.

Next

6. Tokens on both sides

Last updated

Was this helpful?