Ready-to-use components
<Swap />
: Swap assets directly within your app.<Earn />
: Generate yield directly within your app.<FundCard />
: Fund their wallets with fiat (via USDC, Apple Pay, or debit card) without leaving your appi<Buy />
: Purchase tokens directly within your app.
Swap
and Earn
components, your users don’t need to leave your app to execute these common actions. For users who lack onchain funds, the Fund
and Buy
components offer an integrated fiat-to-crypto onramp.
Swap Component Integration
TheSwap
component lets users exchange one token for another directly in your application. It fetches live quotes, builds transactions, and executes swaps—abstracting the underlying complexity.
Lets add the Swap
component to your app.
1
Install and Configure OnchainKit
Create a new OnchainKit app
Terminal
2
Import and Render the Swap Component
App.tsx
experimental.useAggregator
prop to true
.
Swap Settings
The Swap component comes preconfigured but is highly customizable. Just a couple of the settings you can customize:- Swap settings
- bidirectional or unidirectional swaps
- Gasless swaps with paymasters
Earn Component Integration
TheEarn
component enables users to deposit assets into yield-generating vaults and withdraw them later—all within your app. The Earn
component currently supports Morpho vaults on Base.
Get a vault addressYou can get a vault address from Morpho’s Vaults page. You will use this address when setting up the
Earn
component.Advanced Customizations
Similar to the Swap component, the Earn component is highly customizable. Lets customize our component to include custom deposit buttons for a streamlined user experience.useEarnContext
to access the component’s context values,EarnDeposit
andEarnDetails
DepositButton
to render custom deposit buttons
Onboarding Users in DeFi
In order to leverage the<FundCard/>
and <Buy />
components, users need to have funds in their wallet. If user’s don’t have funds, they’ll need to onramp fiat or buy tokens in order to transact. We’ll explore two out-of-the-box solutions from OnchainKit below.
The Fund
component (via <FundCard />
) offers a complete fiat onramp experience, allowing users to add funds to their wallet directly in your app. It provides:
- Amount input with fiat/crypto switching
- Payment method selection (Coinbase, Apple Pay, Debit Card)
- Automatic exchange rate updates
- Smart handling of payment method restrictions (based on country and subdivision)
To use the
FundCard
component, you’ll need to provide a Client API Key in OnchainKitProvider
. You can get one following our Getting Started steps.App.tsx
FundCard
component and its features, check out the FundCard docs.
The Buy
Component
The Buy
components provide a comprehensive interface for users to purchase Tokens.
The Buy
component supports token swaps from USDC and ETH by default with the option to provide an additional token of choice using the fromToken
prop. Users are able to purchase tokens using their Coinbase account, Apple Pay, or debit card.
This component requires a
projectId
to be set in the OnchainKitProvider
. You can find your projectId
on Coinbase Developer Platform.Note: This interface is for demonstration purposes only.Swap and Onramp flows will execute and work out of the box when you implement the component in your own app.
Next Steps
If you’re using these components, its likely you’ll benefit from the following components:-
<Transaction/>
: Provides a high-level transaction interface for executing custom onchain transactions. -
<TokenChip/>
: Offers utilities for token selection and display, ideal for building wallet-like interfaces. -
<WalletIsland/>
: An advanced, draggable wallet widget that consolidates wallet management (QR code, buy options, swap, portfolio view) in one interface.
Go Gasless
For the<Buy />
and <Swap/>
components, you can enable gasless transactions by setting the isSponsored
prop to true
.