Setting Up Your Codebase

First, we need to get our codebase set up, which begins with creating a Next app through the CLI.

npx create-next-app <your-action-codebase-name>

Then, we'll cd into the directory to make a few necessary changes.

cd <your-action-codebase-name>

Within the src/app file, create a directory called api/actions. In it, create a folder with the name of the action you want to make (eg: api/actions/donate-sol) and put a route.ts in that file. This is what your file directory should look like:

The route.ts is the file that contains Action API logic. In the next few sections, we will examine this in more detail.

With that done, the next step is to install the Solana Actions SDK by running the following commands:

# npm
npm i @solana/actions

# yarn
yarn add @solana/actions

At the top of the route.ts file, you need to import the following from the @solana/actions SDK:

import {
  ActionPostResponse,
  createActionHeaders,
  createPostResponse,
  ActionGetResponse,
  ActionPostRequest,
} from "@solana/actions";

Congratulations! In the next section, we'll discuss the header information required to work with Actions.

Last updated