Guides
Cross-Chain

NextJS

6min

Introduction

You can use NextJS API paths to define and expose your Cross-Chain Sherry Link and publish it on Vercel (or other provider).

Next.js provides built-in API routes, making it an excellent choice for projects that combine frontend and backend functionality.

Initial Setup

Create a new Next.js project

terminal


Install the SDK

npm
yarn


Open the project in your preferred editor. For example VSCode

terminal


Creating the Endpoint

Navigate to the pages/api/example folder and create a file named route.ts

For educational purposes, we use "Access-Control-Allow-Origin": "*", but in a production environment, you must restrict allowed origins to the official Sherry domains: staging.sherry.social and app.sherry.social.This enhances the security of your infrastructure and prevents potential unnecessary costs caused by unauthorized requests.

route.ts
corsHeaders


Save the file and start the development server:

  • http://localhost:3000/api/example

Deploying to Production

  1. Deploy your project to Vercel
  2. One deployed, the metadata endpoint will be accesible at a URL like:
    1. https://your-domain.vercel.app/api/example

Catching Errors

In the example we have implemented a try-catch to catch any run-time errors. You can create an instance of all the errors that could occur during the execution of createMetadata.

Updated 30 Jan 2025
Doc contributor
Did this page help you?