> 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/rome-academy/09-build-a-dual-lane-app.md).

# 9. Build a dual-lane app

Build one vault contract that a MetaMask user and a Solana wallet user both deposit into and withdraw from, and see the same balance from both sides.

This is the build lesson ([2. What you can build](https://docs.rome.builders/rome-academy/02-what-you-can-build.md) lists the use case). You write one small USDC vault, deploy it once, and use it from two wallets: MetaMask and a Solana wallet. At the end both users have a balance in the same contract state.

## What you'll learn

* The shape of a dual-lane contract: a plain ERC-20 vault.
* The ordered steps each lane takes to deposit and withdraw.
* Why the Solana lane has a fund leg and a sweep leg, and the EVM lane does not.
* How to choose between a Solidity core and a Solana program core.
* How to measure what each step costs.

## Before you start

* Finish [8. Open your Solana program to EVM users](https://docs.rome.builders/rome-academy/08-open-your-solana-program-to-evm-users.md). Lesson 7 covers the Solana lane this build uses, so read [7. Open your EVM app to Solana wallets](https://docs.rome.builders/rome-academy/07-open-to-solana-wallets.md) first if you skipped it.
* Have MetaMask on Hadrian and a Solana wallet on Solana devnet that signs v1 transactions, both funded as in lesson 3 and [Faucets](https://docs.rome.builders/resources/faucets.md).
* Have the TypeScript SDK installed ([Rome SDK](https://docs.rome.builders/products/rome-sdk.md#typescript-sdk-rome-protocol-sdk)) and Foundry or Hardhat ([Deploy Solidity Contracts](https://docs.rome.builders/developer-guides/deploy-solidity.md)).

## The lesson

### Step 1. Pick your core

A dual-lane app keeps its core logic on one side. Either the core is Solidity and Solana users reach it through their synthetic address, or the core is a native Solana program and EVM users reach it through a thin router. Neither is the rule. Choose from the code you already have, your team and what the app does. [Choose your core](https://docs.rome.builders/core-concepts/choose-your-core.md) lists the trade-offs.

This course builds the first shape. It is the shorter path and uses standard EVM tooling. If you hold a Solana program instead, lesson 8 and [Integrate a Solana program](https://docs.rome.builders/developer-guides/integrate-solana-program.md) cover who signs, how tokens move and the one-track rule. Its key point carries over to this lesson: a contract cannot move a user's tokens by itself, so the user grants a right first.

### Step 2. Write the vault

The vault pulls a token with `transferFrom` and returns it with `transfer`. Nothing in it is specific to Rome.

```solidity
function deposit(uint256 amount) external {
    require(token.transferFrom(msg.sender, address(this), amount));
    balanceOf[msg.sender] += amount;
}
function withdraw(uint256 amount) external {
    balanceOf[msg.sender] -= amount;
    require(token.transfer(msg.sender, amount));
}
```

The constructor takes the wUSDC wrapper address. Deploy it to Hadrian as you did in lesson 3, then verify the source ([Verify Contracts](https://docs.rome.builders/developer-guides/verify-contracts.md)). The complete contract is in [Build a dual-lane app](https://docs.rome.builders/developer-guides/dual-lane-app.md).

### Step 3. Run the EVM lane

A MetaMask user holds USDC as native gas, and the vault takes wUSDC. So the lane has four steps, each a normal transaction:

1. Wrap some gas into wUSDC with `withdraw_to_ata` on the Withdraw precompile.
2. Grant the wrapper once, if `isEnabled(user)` is false.
3. `approve` the vault on wUSDC.
4. `deposit` into the vault.

There are no fund or sweep legs. The wrapped tokens already live at the user's EVM address. The code is in [The same app from MetaMask](https://docs.rome.builders/developer-guides/dual-lane-app.md#the-same-app-from-metamask). Precompile addresses are on [Precompiles](https://docs.rome.builders/reference/precompiles.md).

### Step 4. Run the Solana lane

The Solana user holds SOL and SPL USDC. Every step is a v1 transaction signed by that wallet:

1. Provision the synthetic with `create_pda`, once.
2. Fund leg: move USDC from the wallet's token account into the synthetic's.
3. Grant the wrapper, if `isEnabled` is false.
4. `approve` the vault.
5. `deposit`.

Withdrawing runs backward. `withdraw` returns the tokens to the synthetic, and the sweep leg moves them to the user's own wallet. After a full withdrawal and sweep, the synthetic's deposited token balance is back to zero. These are separate transactions, so if a deposit or a sweep fails, read the synthetic's token balance and let the user retry or sweep the rest back. The step-by-step code is in [Value IN](https://docs.rome.builders/developer-guides/dual-lane-app.md#value-in-deposit-step-by-step) and [Value OUT](https://docs.rome.builders/developer-guides/dual-lane-app.md#value-out-withdraw-step-by-step).

Keep the grant check in your app's first-deposit flow for both lanes. A token account has one delegate, so a later grant to another program, such as a bridge or a router, replaces the wrapper's grant. Check `isEnabled` before each deposit instead of assuming the earlier grant is still there ([One-time grant per wallet](https://docs.rome.builders/core-concepts/token-interop.md#one-time-grant-per-wallet)).

### Step 5. Measure each step

Read `computeUnitsConsumed` from the Solana receipt of each Solana-lane step, as in lesson 7. The guide lists the compute units, bytes and accounts that each step used on Hadrian. Every step in that table sits well under the atomic budget. Use those numbers as a baseline, then compare your own.

If a step lands near 1.4M compute units or 64 accounts, route it through the relay or simplify it. See [Constraints](https://docs.rome.builders/core-concepts/constraints.md) and [Compute Budget](https://docs.rome.builders/core-concepts/compute-budget.md).

## Check yourself

Do this on Hadrian and keep the links.

1. Deposit from MetaMask. Deposit from the Solana wallet.
2. Read `balanceOf` on the vault for both addresses. Each one shows its own deposit. For the Solana user, read at the synthetic address.
3. Open each transaction on the Hadrian explorer ([Hadrian](https://docs.rome.builders/networks/hadrian.md) has the link; [Via](https://docs.rome.builders/apps-on-rome/via.md) explains what it shows). For the Solana-lane deposit, follow Via's "Settled in" link to the Solana transaction; the Solana explorer shows its instructions and compute units.
4. Withdraw from both. The Solana user's USDC is back in their own wallet.

If a Solana-lane deposit reverts with SPL error `0x4`, the wrapper grant is missing.

Then answer:

* Which side of the app needs a fund leg, and why?
* What does the Solana user's synthetic hold after a full round trip?

<details>

<summary>Answers</summary>

* The Solana lane. The user's USDC starts in their wallet's token account. The fund leg moves it to the synthetic's token account, so the wrapper balance shows it. A MetaMask user's tokens are already at their EVM address.
* No deposited tokens. The sweep leg returns them to the user's wallet.

</details>

## Next

[10. Bring users and funds from other chains](https://docs.rome.builders/rome-academy/10-from-other-chains.md)


---

# 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/rome-academy/09-build-a-dual-lane-app.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.
