This is a demo application showcasing the use of OnchainKit's Fund component, built with OnchainKit, and ready to be deployed to Vercel.
Explore the demo live at https://fund-component.vercel.app.
Enjoy building.
To ensure all components work seamlessly, set the following environment variables in your .env
file using .env.local.example
as a reference.
You can find the API key
and projectID
on the Coinbase Developer Portal's OnchainKit page. If you don't have an account, you will need to create one.
# See https://portal.cdp.coinbase.com/products/onchainkit
NEXT_PUBLIC_CDP_API_KEY="GET_FROM_COINBASE_DEVELOPER_PLATFORM"
# See https://cloud.walletconnect.com
NEXT_PUBLIC_WC_PROJECT_ID="GET_FROM_WALLET_CONNECT"
The <FundButton />
component provides a way for users to fund their wallet without leaving your app. It automatically detects the user's wallet type (EOA vs Smart Wallet) and directs them to the appropriate funding URL.
- Coinbase Smart Wallet: Provides access to the Coinbase Smart Wallet Fund flow, allowing users to buy and receive crypto or use their Coinbase balances onchain with Magic Spend.
- EOA Wallets: Provides access to Coinbase Onramp, enabling users to buy crypto using a fiat payment method or transfer existing crypto from their Coinbase account.
- Get your Project ID: Obtain your Project ID from the Coinbase Developer Platform Dashboard.
- Add your Project ID to your
.env
file:NEXT_PUBLIC_ONCHAINKIT_API_KEY=YOUR_PUBLIC_API_KEY NEXT_PUBLIC_CDP_PROJECT_ID=YOUR_CDP_PROJECT_ID
- Add Project ID to OnchainKitProvider:
<OnchainKitProvider apiKey={process.env.NEXT_PUBLIC_ONCHAINKIT_API_KEY} projectId={process.env.NEXT_PUBLIC_CDP_PROJECT_ID} chain={base} > {props.children} </OnchainKitProvider>
- Drop in the
<FundButton />
component:import { FundButton } from '@coinbase/onchainkit/fund'; <FundButton />
If you encounter a "something went wrong" error when navigating to pay.coinbase.com, ensure "enforce secure initialization" is disabled on the Onramp config page in the Coinbase Developer Platform Dashboard.
You can customize the Coinbase Onramp experience by providing your own Onramp URL to the <FundButton />
component. Use the getOnrampBuyUrl
utility to generate a tailored Coinbase Onramp URL.
import { FundButton, getOnrampBuyUrl } from '@coinbase/onchainkit/fund';
import { useAccount } from 'wagmi';
const projectId = 'YOUR_CDP_PROJECT_ID';
const { address } = useAccount();
const onrampBuyUrl = getOnrampBuyUrl({
projectId,
addresses: { address: ['base'] },
assets: ['USDC'],
presetFiatAmount: 20,
fiatCurrency: 'USD'
});
<FundButton fundingUrl={onrampBuyUrl} />
You can choose to have the funding URL open in a popup or a new tab using the openIn
prop.
<FundButton openIn={"tab"} />
Override the text on the fund button using the text
prop, and hide the icon with the hideIcon
prop.
<FundButton text="Onramp" hideIcon={true} />
Hide the text with the hideText
prop.
<FundButton hideText={true} />
See FundButtonReact
for the full list of customization options.
# Install bun in case you don't have it
curl -fsSL https://bun.sh/install | bash
# Install packages
bun i
# Run Next app
bun run dev
- OnchainKit documentation
- We use the OnchainKit Early Adopter contract written by neodaoist [X]
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or need help, feel free to reach out to us on Discord or open a Github issue or DMs us on Twitter on X at @onchainkit or @fkpxls.