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

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 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

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 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 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.

The constructor takes the wUSDC wrapper address. Deploy it to Hadrian as you did in lesson 3, then verify the source (Verify Contracts). The complete contract is in Build a dual-lane app.

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. Precompile addresses are on Precompiles.

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 and Value OUT.

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).

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 and Compute Budget.

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 has the link; Via 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?

Answers
  • 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.

Next

10. Bring users and funds from other chains

Last updated

Was this helpful?