# Set up an emeddable onramp integration Use this guide to fully customize the embeddable onramp. To integrate with the onramp SDK: 1. [Install the SDK and client library](#install). 1. [Generate a crypto onramp session](#onramp-session) on your backend. 1. [Render the onramp UI](#onramp-ui) on your website. 1. [View your integration’s usage in the Stripe Dashboard](#dashboard). ## Install the SDK and client library ### Client-side Include the following scripts using script tags within the `` element of your HTML. These scripts must always load directly from Stripe’s domains (https://js.stripe.com and https://crypto-js.stripe.com) for compatibility and *PCI compliance*. Don’t include the scripts in a bundle or host a copy yourself. If you do, your integration might break without warning. ```html Onramp ``` ### Use the Onramp JS SDK as a module Use the npm package to load the onramp JS SDK as an [ES module](https://docs.stripe.com/crypto/onramp/esmodule.md). The package includes Typescript type definitions. ``` npm install --save @stripe/stripe-js @stripe/crypto ``` ### Server-side Our official libraries don’t contain built-in support for the API endpoints because the onramp API is in limited beta. As a result, our examples use curl for backend interactions. ## Generate a crypto onramp session Generate a [crypto onramp session](https://docs.stripe.com/crypto/onramp/api-reference.md#api-reference) by running the following curl command in your terminal: ```bash curl -X POST https://api.stripe.com/v1/crypto/onramp_sessions \ -u <>: \ -d "wallet_addresses[ethereum]"="0xB00F0759DbeeF5E543Cc3E3B07A6442F5f3928a2" # add as many parameters as you'd like ``` You receive a response similar to the following: ```json { "id": "cos_0MYfrA589O8KAxCGEDdIVYy3", "object": "crypto.onramp_session", "client_secret": "cos_0MYfrA589O8KAxCGEDdIVYy3_secret_rnpnWaxQbYQOvp6nVMvEeczx300NRU4hErZ", "created": 1675732824, "livemode": false, "status": "initialized", "transaction_details": { "destination_currency": null, "destination_amount": null, "destination_network": null, "fees": null, "lock_wallet_address": false, "source_currency": null, "source_amount": null, "destination_currencies": [ "btc", "eth", "sol", "usdc" ], "destination_networks": [ "bitcoin", "ethereum", "solana" ], "transaction_id": null, "wallet_address": null, "wallet_addresses": { "bitcoin": null, "ethereum": "0xB00F0759DbeeF5E543Cc3E3B07A6442F5f3928a2", "polygon": null, "solana": null } } } ``` See the [Onramp API reference](https://docs.stripe.com/crypto/onramp/api-reference.md#api-reference) for the full parameter list you can pass in when creating a session. ## Render the Onramp UI Import both the StripeJS and the OnrampJS bundles: ```html Crypto Onramp
``` Use the *client\_secret* from your server-side call in the previous step to initiate and mount the onramp session: ```javascript const stripeOnramp = StripeOnramp("<>"); initialize(); // Initialize the onramp element with a client secret function initialize() { // IMPORTANT: replace the following with your logic of how to mint/retrieve the client secret const clientSecret = "cos_1Lb6vsAY1pjOSNXVWF3nUtkV_secret_8fuPvTzBaxj3XRh14C6tqvdl600rpW7hG4G"; const onrampSession = stripeOnramp.createSession({clientSecret}); onrampSession .mount("#onramp-element"); } ``` To use the onramp in React, define two components: `CryptoElements` and `OnrampElement`. `CryptoElements` is a [React context](https://reactjs.org/docs/context.html) provider for an initialized `StripeOnramp` instance. The `OnrampElement` component renders the onramp UI using the *client\_secret* from the server-side call, shown in the previous step. ```jsx import {loadStripeOnramp} from '@stripe/crypto'; import {CryptoElements, OnrampElement} from './StripeCryptoElements'; const stripeOnrampPromise = loadStripeOnramp("<>"); export default () => { // IMPORTANT: replace with your logic of how to mint/retrieve client secret const clientSecret = "cos_1Lb6vsAY1pjOSNXVWF3nUtkV_secret_8fuPvTzBaxj3XRh14C6tqvdl600rpW7hG4G"; return ( ); } ``` ```jsx import React, { ReactNode } from 'react'; // ReactContext to simplify access of StripeOnramp object const CryptoElementsContext = React.createContext(null); export const CryptoElements = ({ stripeOnramp, children, }) => { const [ctx, setContext] = React.useState(() => ({ onramp: null })); React.useEffect(() => { let isMounted = true; Promise.resolve(stripeOnramp).then((onramp) => { if (onramp && isMounted) { setContext((ctx) => (ctx.onramp ? ctx : { onramp })); } }); return () => { isMounted = false; }; }, [stripeOnramp]); return ( {children} ); }; // React hook to get StripeOnramp from context export const useStripeOnramp = () => { const context = React.useContext(CryptoElementsContext); return context?.onramp; }; // React element to render Onramp UI export const OnrampElement = ({ clientSecret, appearance, ...props }) => { const stripeOnramp = useStripeOnramp(); const onrampElementRef = React.useRef(null); React.useEffect(() => { const containerRef = onrampElementRef.current; if (containerRef) { containerRef.innerHTML = ''; if (clientSecret && stripeOnramp) { stripeOnramp .createSession({ clientSecret, appearance, }) .mount(containerRef) } } }, [clientSecret, stripeOnramp]); return
; }; ``` After running the script, the onramp renders the following dialog: ![Stripe's fiat-to-crypto onramp being embedded into a third-party application](images/crypto/crypto-onramp-overview.png) Stripe’s fiat-to-crypto onramp embedded within a third-party application ### Sandbox values Sandbox transaction amounts are overridden by our pre-decided limits. Use the following values to complete an onramp transaction in *sandbox*: - On the OTP screen, use `000000` for the verification code. - On the personal information screen, use `000000000` for the SSN and `address_full_match` for address line 1. - On the payment details screen, use the test credit card number `4242424242424242`. ## View integration usage After you’ve launched the onramp, you can view customized usage reports in the [Stripe Dashboard](https://dashboard.stripe.com/crypto-onramp/reports). You can also return to the [onboarding page](https://dashboard.stripe.com/crypto-onramp/onboarding) to update the domains where you plan to host the onramp, and check the status of any onboarding tasks.