6. Tokens on both sides
How one SPL token appears as an ERC-20 wrapper for EVM wallets and as a token account for Solana wallets, and the one-time grant that lets contracts move it.
Tokens are the base of every use case in 2. What you can build: a pool, a vault or a lending market all move the same asset that Solana wallets hold. An SPL wrapper exposes an SPL mint through an ERC-20 interface. For tokens a wallet holds, the wrapper reads the balance in the wallet's Rome-derived token account, so Solana and Solidity see the same balance. This lesson explains how that works and the one grant every user must make before your contract can move their tokens.
What you'll learn
How an SPL wrapper exposes a wallet's Solana token balance through ERC-20 methods.
What the factory and the wrapper do, and which wrapper to use.
How tokens held by contracts differ from tokens held by wallets.
The one-time
approve_splgrant, how to check it and how it breaks.
Before you start
Finish 5. Call Solana from Solidity. You need the idea of the external-authority PDA and the Helper precompile.
Have a funded Hadrian wallet and a deployed contract. The canonical wrapper addresses are in the chain's
tokens.jsonin the registry: the entry withkind: "spl_wrapper"and symbolwUSDC. Hadrian links to the chain's registry folder.The USDC token account you created with
createMyAtain lesson 5. The grant needs it to exist.
One balance, two views
Every EVM address has an external-authority PDA on Solana, and that PDA owns the address's token accounts. The ERC-20 wrapper's balanceOf reads the wallet's token account directly. totalSupply reads the mint.
Inside Rome, a wallet's SPL token and its ERC-20 wrapper read the same token account. A Solana wallet that holds USDC and an EVM address that holds USDC both hold the same mint, and both trade against the same pool accounts. That is how liquidity stays in one place on Rome. The picture and the details are in Token interop.
Wallets and contracts hold tokens differently
The shared balance holds for wallets. Contracts differ. A contract cannot send the one-time grant described below on a user's behalf, so the ordinary wrappers hold a contract's tokens in an escrow token account and keep a ledger of what each contract owns. Hooked Token-2022 wrappers keep no ledger and use the contract's own token account.
Two things follow:
Two wrappers over the same mint show the same wallet balance. They can disagree about a contract's balance, because each keeps its own ledger.
For pools, vaults and lending markets, use the canonical wrapper that the registry names for each mint on each chain. Do not pick one by name.
A transfer to a contract through the wrapper credits that ledger. It does not give the contract a token account it can spend from. Flows that need the contract to act on Solana use the path in Integrate a Solana program.
The factory and the wrapper
ERC20SPLFactory deploys a wrapper for an SPL mint. Each factory allows one wrapper per mint. The wrapper gives a full ERC-20 interface:
balanceOfandtotalSupplyread Solana state.transferandtransferFrommove tokens on Solana.approveandallowancekeep ordinary ERC-20 allowances in EVM storage, because a token account has no such thing.
You rarely deploy a wrapper. Rome and the registry already carry the canonical ones for USDC, ETH and SOL. You deploy one only when you bring a new mint. Both factory calls are in The factory. The factory also handles Token-2022 mints, but their extensions change the integration: a hooked wrapper reverts plain transfer and transferFrom, and a transfer-fee mint can deliver less than you send. Read Token-2022 mints before using one in your vault.
Amounts must fit in uint64, because SPL amounts do, and the wrapper rejects anything larger. The gas token has its own decimals, and native gas balances use 18. Converting between them must be exact. The gas token on Hadrian and Rubicon is USDC.
The one-time grant
The wrapper moves a user's tokens as the SPL delegate of the user's token account. A token account has to name that delegate before the wrapper can move anything. The user does this once per wrapper with one call, for the maximum amount:
approve_spl(wrapper, type(uint64).max, mint) on the Helper precompile.
Four details matter in practice:
The user sends it. The grant is signed by the user's own account, sent straight to the Helper precompile. Your contract cannot send it for them. Build an "Enable" step into your front end.
It applies to everyone. MetaMask wallets and the synthetic addresses of Solana wallets both need it, for every wrapper whose tokens they want to move.
Check it first. The wrapper's
isEnabled(user)returnstrueonce the grant is in place. Read it before a transfer instead of assuming.Grant the maximum.
isEnabledstaystruewhile any part of a capped grant remains. A capped grant breaks ordinary transfers once it runs low, and your app will not know to ask again.
The mint to pass is mint_id() on the wrapper. A worked front-end version for both wallet types is in One-time: grant the wrapper.
How it breaks
A token account has one delegate. If the user grants a bridge or a router, that grant replaces the wrapper's, and the wrapper stops working for that user. The symptom is a revert with SPL error 0x4, an owner mismatch. The fix is to grant the wrapper again. So check isEnabled before a flow that depends on the wrapper, not once at sign-up.
A new factory version brings a new wrapper, and each wallet grants the new one in the same way.
Moving tokens out
Because the wrapper balance is already the SPL balance, moving a token out to Solana is an SPL transfer.
To another Solana wallet from an EVM wallet:
transfer_splsent straight from the wallet to the Helper precompile, orRomeBridgeWithdraw.bridgeOutToSolana, which also needs a grant for the bridge contract. Both need the recipient's token account to exist.To the wallet that signed the transaction:
transfer_spl_to_signer. It reaches the user's own wallet only on the wallet-signed Solana lane. From MetaMask the signer is Rome's proxy payer, so use the other two.For the gas token,
withdraw_to_ataanddeposit_from_ataconvert between native gas and the token in a token account.
On testnet, Solgate connects Solana assets to AggLayer EVM chains in both directions. SPL token registration is permissionless. USDC uses CCTP. Lesson 10 returns to inbound flows and the bridge. The method list is in Deposit and withdraw.
Check yourself
On Hadrian, with the wallet you funded:
Read
isEnabledfor your address on the canonical wUSDC wrapper from the registry.Make sure your USDC token account exists. The
createMyAtacall in lesson 5 created it. If you skipped that, wrap a little gas into wUSDC withwithdraw_to_ata, as in The same app from MetaMask.If
isEnabledisfalse, send theapprove_splgrant to the Helper precompile. Use the code in the dual-lane guide linked above.Read
isEnabledagain. It should now betrue.Find your grant transaction on the Via explorer. Look for the SPL Token
ApproveCheckedinstruction.
Next
Last updated
Was this helpful?