Say Hello to Onramp: Your New Crypto Wingman at PayDirect

Say Hello to Onramp: Your New Crypto Wingman at PayDirect

PD

PayDirect Team

Mar 17, 2026·4 min read

Say Hello to Onramp: Your New Crypto Wingman at PayDirect

Hey coding warriors and crypto enthusiasts! 🚀 Grab your keyboards (and maybe a coffee), 'cause we've just dropped a feature that's gonna change the way you roll in the crypto landscape. Yup, you read that right. PayDirect has upped its game with the mighty Onramp feature, now live on Base (Ethereum L2). 🎉

Why You Should Care

Let's face it, dealing with crypto isn't always smooth sailing, especially when it comes to funding your adventures. But what if we told you that your fiat-to-crypto voyages just got a whole lot easier? Enter the Onramp feature—your new best friend for buying crypto using your credit card or bank transfer. And guess what? The moolah hits your workspace wallet on Base faster than you can say "blockchain". 🏦💸

The Lowdown on Onramp

So, what exactly is Onramp doing under the hood? Let's break down the deets with some juicy code snippets.

Check out this new API route for creating Onramp sessions:

export async function POST(request: NextRequest) {
  const auth = await authenticateApiKey(request)
  if (isAuthError(auth)) return auth

  const rateLimited = checkRateLimit(auth)
  if (rateLimited) return rateLimited

  try {
    if (auth.environment === "sandbox") {
      logApiResponse(auth, 400, undefined, "Onramp not available in sandbox")
      return NextResponse.json(
        { error: "Coinbase Onramp is only available in live environment. Use a live API key to create onramp sessions." },
        { status: 400, headers: getRateLimitHeaders(auth) }
      )
    }

    const body = await request.json().catch(() => ({}))
    const asset = body.asset?.toUpperCase()
    
    if (asset && !["USDC", "ETH"].includes(asset)) {
      logApiResponse(auth, 400, undefined, `Unsupported onramp asset: ${asset}`)
      return NextResponse.json(
        { error: "Unsupported asset. Supported: USDC, ETH" },
        { status: 400, headers: getRateLimitHeaders(auth) }
      )
    }
    
    const fiatAmount = typeof body.fiatAmount === "number" ? body.fiatAmount : undefined
    if (fiatAmount !== undefined && (fiatAmount <= 0 || fiatAmount > 10000)) {
      logApiResponse(auth, 400, undefined, "Invalid fiat amount")
      return NextResponse.json(
        { error: "fiatAmount must be between 0 and 10000" },
        { status: 400, headers: getRateLimitHeaders(auth) }
      )
    }

    let wallet = await resolveWorkspaceWallet(auth.workspaceId)
    const result = await OnrampService.createSessionToken({
      walletAddress: wallet.address,
      blockchains: body.blockchains || ["base"],
      assets: body.assets || ["USDC", "ETH"],
      defaultAsset: asset,
      presetFiatAmount: fiatAmount,
      fiatCurrency: body.fiatCurrency || "USD",
      defaultNetwork: "base",
    })
    
    WebhookEngine.deliverEvent(
      auth.workspaceId,
      "onramp.session.created",
      {
        walletAddress: result.walletAddress,
        channelId: result.channelId,
        expiresIn: result.expiresIn,
      }
    ).catch(() => {})

    logApiResponse(auth, 200, {
      walletAddress: result.walletAddress,
      channelId: result.channelId,
    })

    return NextResponse.json(
      {
        onramp: result,
        timestamp: new Date().toISOString(),
      },
      { status: 200, headers: getRateLimitHeaders(auth) }
    )
  } catch (err: any) {
    console.error("[API] POST /v1/onramp/session error:", err)
    logApiResponse(auth, 500, undefined, err.message || "Onramp session failed")

    return NextResponse.json(
      { error: err.message || "Failed to create onramp session" },
      { status: 500, headers: getRateLimitHeaders(auth) }
    )
  }
}

The Magic Sauce

Here's the deal—this new endpoint lets you POST a request with the fiat amount and desired assets, and boom, you're all set. But don't try this in a sandbox environment, folks! Onramp’s party is strictly a live-event kind of deal. 💎

And speaking of assets, we’re currently showing love to USDC and ETH. Keep your fiat amounts between $1 and $10,000 (let’s not go overboard, okay?), and enjoy a seamless experience that'll make your digital heart sing.

Middleware and Cors: The Unsung Heroes

We've also buffed up the middleware for CORS support. You know, so your browser and server can be BFFs without all that cross-origin drama. It's all about letting the dev flow like a well-oiled machine, and we're here for it.

The Path to Crypto Bliss

You'll find these new pathways in app/api/v1/onramp/session/route.ts, empowering developers everywhere with scalable onramp solutions. Dive into the full potential of crypto transactions without the hassle. Because why make it complicated when it can be this smooth?

And That's a Wrap!

Now it's your turn. Unleash the power of Onramp by hitting up the docs, playing around with it in your projects, and letting us know what you think. The future of crypto transactions is here, and it's waiting for you to dive in. Don't wait—get your hands on the Onramp feature and take your projects to the next level. Happy coding! 🌟

Stay savvy, stay curious, and as always, keep it decentralized!


Feeling the FOMO? Head over to the docs to dig deeper and start swinging your magic wand with Onramp. Let's go! 👩‍💻👨‍💻🚀

Tip the Author

Powered by PayDirect on Base

Enjoyed this post? Send a tip using crypto. We eat our own dog food.

USDC

More from PayDirect

Powered by ContentAgent