Skip to main content
Purpose of this guide is to teach you how to build a blink from scratch using the NextJS framework and TypeScript. You will learn the basic project setup and how a blink is structured. At the end, you have a blink that send a tip to a wallet and can be implemented by a blink client. This guide will not show you how to implement a blink client. If you are looking for a guide, that explains how to integrate an existing blink, checkout our blink integration guide.
Level: BeginnerRequirements: Basic understanding of TypeScript and NextJS

Prerequisite

Initial Setup

Start by setting up a new NextJS project and add some basic configuration.

Initialize the project

In your terminal, run the following command.
When prompted, configure your project with these settings:

Install extra packages

Run the following command to install missing dependencies.

Start development server

The development server is used to start a local test environment that runs on your computer. It is perfect to test and develop your blink, before you ship it to production.

Coding Time 🚀

Now that we have our basic setup finished, it is time to open the editor and start coding.

Create an endpoint

To write a blink provider, you have to create an endpoint. Thanks to NextJS, this all works pretty straightforward. All you have to do is to create the following folder structure:

Create actions.json

Finally, you have to create the actions.json file which will be hosted in the root directory of our application. This file is needed to tell other applications which blink providers are available on your website. Think of it as a sitemap for blinks.
Every blink has an image that is rendered on top. If you have your image already hosted somewhere, you can skip this step but if you haven’t you can just create a public folder in your NextJS project and copy/paste an image there. In our example we will paste a file called tip-mon.png into this public folder. Screenshot of public folder in NextJS project

Create environment variables

Our repositories are public and we don’t expose any sensitive data such as wallet addresses, RPC data, etc. in there. All this information is kept in environment variables.
Depending on the example repository you cloned, there is either a .env.example or a .env-file. If you find a .env.example-file, make sure to rename it to .env.
Once that’s done, update your .env variables, in this case the NEXT_PUBLIC_RPC_URL.

OPTIONS endpoint, headers and basic config

Enables CORS for cross-origin requests and standard headers for the API endpoints. This is standard configuration you do for every blink.

GET endpoint

GET returns the Blink metadata and UI configuration. It describes:
  • How the Action appears in Blink clients
  • What parameters users need to provide
  • How the Action should be executed
Note: dial.to currently supports only GET previews for EVM. To test your POST endpoint, please follow the tutorial to the end, where we implement the blink client in the frontend.
Visit dial.to and type in the link to your blink to see if it works. If your server runs on localhost:3000 the url should be like this: http://localhost:3000/api/actions/tip-mon Screenshot of a blink rendered on dial.to

POST endpoint

POST handles the actual MON transfer transaction.

POST request to the endpoint

Create the post request structure and add the necessary imports as well as the destinationWallet on top of the file.

Extract data from request

The request contains the URL, which contains the amount param.

Create the transaction

Create a new transaction with all the necessary data and add it below in the POST request.

Finalize

Create ActionPostResponse and return it to the client.

Conclusion

In this tutorial, you learned, how to create a simple blink that tips another wallet. The main focus was to get you familiar with the concept of the blink provider. There is more functionalities, that you can add to your blinks, such as multi steps, input fields, and much more. The next step is to get your blink deployed for use, and then register your blink. By registering your blink, it gets added to our library, giving you extra distribution and exposure. It also ensures that your blink will unfurl and be usable on X. In the next tutorial, you will learn how you can implement the blink client, that renders your blink in the frontend.