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
Finish 8. Open your Solana program to EVM users. Lesson 7 covers the Solana lane this build uses, so read 7. Open your EVM app to Solana wallets 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.
Have the TypeScript SDK installed (Rome SDK) and Foundry or Hardhat (Deploy Solidity Contracts).
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:
Wrap some gas into wUSDC with
withdraw_to_ataon the Withdraw precompile.Grant the wrapper once, if
isEnabled(user)is false.approvethe vault on wUSDC.depositinto 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:
Provision the synthetic with
create_pda, once.Fund leg: move USDC from the wallet's token account into the synthetic's.
Grant the wrapper, if
isEnabledis false.approvethe vault.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.
Deposit from MetaMask. Deposit from the Solana wallet.
Read
balanceOfon the vault for both addresses. Each one shows its own deposit. For the Solana user, read at the synthetic address.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?
Next
Last updated
Was this helpful?