đQuickstart
Learn how to quickly build your first Farcaster Cast Actions using Airstack Frog Recipes in Node.js.
In this tutorial, you will learn how to create a simple upthumbed-like cast action called GM, where with each click you "GM" a person.
You have the option to directly clone the project through automatic installation or manually follow it step-by-step through manual installation.
Automatic Installation
You can find the Airstack Farcaster Cast Actions Starter Code using Airstack Frog Recipes in our GitHub here.
To clone the repository, run the following command:
Manual Installation
Step 1: Install Dependencies & Environment Variables
To get started, simply install all the necessary dependencies:
Then, get your Airstack API key and add it as an environment variable:
Step 2: Build Your 1st Cast Actions
To create your 1st Farcaster cast actions, create a new file index.tsx
under api
folder and add the following code to create a new Frog
instance from @airstack/frog
:
Once you have the Frog instance instantiated, define a POST route /gm
that will be the post_url of your cast actions. For the cast action, you only need to return the message
text in the 1st response (in JSON format) with the response status code in the 2nd response:
Step 3: Configure TSConfig
Add the following fields into your tsconfig.json
:
If you don't have tsconfig.json
in your project, then run the following command first:
Run Development Server
Add dev
script to your package.json
as shown below:
To start the development server, simply run one of the following command to run the dev
script:
Then, you can access the cast actions by making POST request to the http://localhost:5173/api/gm
. You can do this either by making a CURL POST request:
Or tunnel your local server through ngrok:
and test your cast action with the Farcaster official cast action playground.
đĨŗ Congratulations, you've just built your 1st Farcaster Cast Actions using Airstack Frog Recipes!
Bonus: Deployment & Add Database
To keep track the number of time user GM someone, you can add a simple Redis DB to store the number. For this, Vercel provide Vercel KV that you can easily use in your project.
To use Vercel KV in your cast actions, install @vercel/kv
as a dependency:
Then, add this gm
function code to your project and import it to api/index.tsx
:
Once the code is added, you can have the database setup for your project. To setup a new KV database, you will first need to setup and deploy your project on Vercel.
To deploy, first add some of the following additional scripts to your package.json
:
Then, compile the poject by running the following command:
If run successfully, you should have a new .vercel
folder generated. With this you can deploy the compiled build into Vercel by running:
Before running the command, make sure that you have vercel
CLI within your machine and have it connected to your account by running vercel auth
.
Once deployed successfully, you can go to the Vercel Dashboard to create a new Vercel KV database (follow steps here) have your Airstack API key added to your environment variables.
Key | Value |
---|---|
|
Then, access the live Farcaster cast actions from a custom vercel link with the following format https://<CAST_ACTIONS_VERCEL_PROJECT>.vercel.app/api/gm
, which you can use to test with the Farcaster official cast action playground.
đĨŗ Congratulations, you've just deployed your 1st Farcaster cast actions built usng Airstack Frog Recipes into Vercel!
Next Steps
Now that you have your 1st Farcaster cast actions running, you can also learn more on how to use Airstack Frog Recipes to build your 1st Farcaster Frame here to company your cast actions.
In addition, you can also check out all the Airstack features available in Airstack Frog Recipes to enrich your Farcaster cast actions or Farcaster Frames with various onchain data offered:
Developer Support
If you have any questions or need help regarding integrating onchain data to your Farcaster cast actions using the Airstack Frog Recipe, please join our Airstack's Telegram group.
More Resources
Last updated