Chain Abstraction
Chain Abstraction in WalletKit enables users with stablecoins on any network to spend them on-the-fly on a different network. Our Chain Abstraction solution provides a toolkit for wallet developers to integrate this complex functionality using WalletKit.
For example, when an app requests a 100 USDC payment on Base network but the user only has USDC on Arbitrum, WalletKit offers methods to detect this mismatch, generate necessary transactions, track the cross-chain transfer, and complete the original transaction after bridging finishes.
How It Works
Apps need to pass gas
as null, while sending a transaction to allow proper gas estimation by the wallet. Refer to this guide for more details.
When sending a transaction, you need to:
- Check if the required chain has enough funds to complete the transaction
- If not, use the
prepare
method to generate necessary bridging transactions - Sign routing and initial transaction hashes, prepared by the prepare method
- Use
execute
method to broadcast routing and initial transactions and wait for it to be completed
The following sequence diagram illustrates the complete flow of a chain abstraction operation, from the initial dapp request to the final transaction confirmation
Chain Abstraction Flow
Methods
The following methods from WalletKit are used in implementing chain abstraction.
Chain abstraction is currently in an early access phase and requires the @ChainAbstractionExperimentalApi
annotation.
Prepare
This method is used to check if chain abstraction is needed. If it is, it will return a PrepareSuccess.Available
object with the necessary transactions and funding information.
If it is not, it will return a PrepareSuccess.NotRequired
object with the original transaction.
Accounts field is a list of CAIP-20 accounts you are sourcing from e.g. Solana account
Execute
This method is used to execute the chain abstraction operation. It broadcasts the bridging and initial transactions and waits for them to be completed.
The method returns a ExecuteSuccess
object with the transaction hash and receipt.
Usage
When sending a transaction, first check if chain abstraction is needed using the prepare
method. If it is needed, you must sign all the fulfillment transactions and use the execute
method.
If the operation is successful, use execute
method and await the transaction hash and receipt.
If the operation is unsuccessful, send the JsonRpcError to the dapp and display the error to the user.
For example, check out implementation of chain abstraction in sample wallet with Kotlin.
Testing
To test Chain Abstraction, you can use the AppKit laboratory and try sending USDC/USDT with any chain abstraction supported wallet. You can also use this sample wallet for testing.
ProGuard rules
If you encounter issues with minification, add the below rules to your application:
Was this page helpful?