Build and Earn! Check out the bounties!

Running Lilypad in a Front End

Setting up a feeless frontend for Lilypad

What We'll Do

In this tutorial, we will review how to create a feeless front end for a Lilypad module. To do so, we will:

  1. Create a new NextJS project.

  2. Create a CLI Wrapper to run the module.

  3. Create a server to handle requests from the browser.

  4. Create our user interface to allow a user to enter a prompt to run the module.

  5. Run the front end.

Install Next JS

Create a new Next JS project by running the following:

npx create-next-app@latest

Prepare your CLI Wrapper

In your project folder, create a new file named .env to manage your environment variables. Paste in the following, and replace “<your-private-key-here>” with the private key of the wallet that will be charged for all of the jobs.

WEB3_PRIVATE_KEY=<your-private-key-here>

Install dotenv to access your environment variables:

In your app folder, create a folder for pages, then a folder for API, and in that folder, create a file named cliWrapper.js. Paste the following code into cliWrapper.js:

Prepare your server

Install Express and CORS:

In your app folder, create a file named server.js and paste the following code:

Prepare your front end

In the App folder, delete the default content on the Page.tsx file and paste in the following code:

Running your front end

To run your front end on your local host, you will need to update the next.config.js file. Open the file and paste the following:

Now you're ready to test your front end!

Open two terminals, one to run your server and another to run your front end. In both terminals, navigate to your App folder. For your server terminal, run the following:

You should see “Server listening at http://localhost:3001”.

In your second terminal, run your front end with the following command:

You should see something like this.

In your browser, navigate to http://localhost:3000/ and you should now be able to see your front end. It should look like this.

Type in a prompt and click on the enter button. If you look at the terminal running your server, you’ll notice that it says “Lilypad Starting…”. Lilypad will print to the console once the job is complete, and it should look something like this.

Now check your browser, and you should see your image.

Congrats! You have successfully integrated Lilypad into your front end.

Share your custom front ends with us!

If you were able to complete the tutorial, share your front end with us on Twitter!

If you need any help or have any feedback, hop into our Discord!

View the source code.

Last updated

Was this helpful?