Coder Social home page Coder Social logo

zizzamia / a-frame-in-100-lines Goto Github PK

View Code? Open in Web Editor NEW
222.0 4.0 256.0 3.95 MB

Farcaster Frames in less than 100 lines, and ready to be deployed to Vercel.

Home Page: https://onchainkit.xyz

License: MIT License

TypeScript 97.60% JavaScript 2.40%

a-frame-in-100-lines's Introduction

OnchainKit logo vibes

A Frame in 100 lines (or less)

Farcaster Frames in less than 100 lines, and ready to be deployed to Vercel.

To test a deployed Frame, use: https://warpcast.com/~/developers/frames.

To test a localhost Frame, use: Framegear. A simple tool that allows you to run and test your frames locally:

  • without publishing
  • without casting
  • without spending warps

And let us know what you build by either mentioning @zizzamia on Warpcast or X.


Have fun! ⛵️


App Routing files


app/page.tsx

import { getFrameMetadata } from '@coinbase/onchainkit/frame';
import type { Metadata } from 'next';
import { NEXT_PUBLIC_URL } from './config';

const frameMetadata = getFrameMetadata({
  buttons: [
    {
      label: 'Story time!',
    },
    {
      action: 'link',
      label: 'Link to Google',
      target: 'https://www.google.com',
    },
    {
      label: 'Redirect to pictures',
      action: 'post_redirect',
    },
  ],
  image: {
    src: `${NEXT_PUBLIC_URL}/park-3.png`,
    aspectRatio: '1:1',
  },
  input: {
    text: 'Tell me a boat story',
  },
  postUrl: `${NEXT_PUBLIC_URL}/api/frame`,
});

export const metadata: Metadata = {
  title: 'zizzamia.xyz',
  description: 'LFG',
  openGraph: {
    title: 'zizzamia.xyz',
    description: 'LFG',
    images: [`${NEXT_PUBLIC_URL}/park-1.png`],
  },
  other: {
    ...frameMetadata,
  },
};

export default function Page() {
  return (
    <>
      <h1>zizzamia.xyz</h1>
    </>
  );
}

app/layout.tsx

export const viewport = {
  width: 'device-width',
  initialScale: 1.0,
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>{children}</body>
    </html>
  );
}

app/config.ts

export const NEXT_PUBLIC_URL = 'https://zizzamia.xyz';

app/api/frame/route.ts

import { FrameRequest, getFrameMessage, getFrameHtmlResponse } from '@coinbase/onchainkit/frame';
import { NextRequest, NextResponse } from 'next/server';
import { NEXT_PUBLIC_URL } from '../../config';

async function getResponse(req: NextRequest): Promise<NextResponse> {
  let accountAddress: string | undefined = '';
  let text: string | undefined = '';

  const body: FrameRequest = await req.json();
  const { isValid, message } = await getFrameMessage(body, { neynarApiKey: 'NEYNAR_ONCHAIN_KIT' });

  if (isValid) {
    accountAddress = message.interactor.verified_accounts[0];
  }

  if (message?.input) {
    text = message.input;
  }

  if (message?.button === 3) {
    return NextResponse.redirect(
      'https://www.google.com/search?q=cute+dog+pictures&tbm=isch&source=lnms',
      { status: 302 },
    );
  }

  return new NextResponse(
    getFrameHtmlResponse({
      buttons: [
        {
          label: `🌲 ${text} 🌲`,
        },
      ],
      image: {
        src: `${NEXT_PUBLIC_URL}/park-1.png`,
      },
      postUrl: `${NEXT_PUBLIC_URL}/api/frame`,
    }),
  );
}

export async function POST(req: NextRequest): Promise<Response> {
  return getResponse(req);
}

export const dynamic = 'force-dynamic';

Resources


Community ☁️ 🌁 ☁️

Check out the following places for more OnchainKit-related content:

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

a-frame-in-100-lines's People

Contributors

jfrankfurt avatar limone-eth avatar samuellhuber avatar zizzamia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

a-frame-in-100-lines's Issues

Bug: When running it in conjunction with framegear an error occurs when handling the submit from "Story time" action

Steps to reproduce

  1. clone this repo
  2. npm install
  3. npm run dev to run a-frame-in-100-lines app
  4. clone onchainkit repo
  5. cd /framegear
  6. npm install
  7. npm run dev
  8. get url provided in 3 and paste it into the input field on framegear website and then press Fetch button
  9. the frame will be presented on framegear website
  10. enter any text in the input field of the frame being rendered and then press "Story time"
  11. you will see an error on the backend of a-frame-in-100-lines app

The error message

FetchError: non-200 status returned from neynar : 400
    at Object.postDataToNeynar (webpack-internal:///(rsc)/./node_modules/@coinbase/onchainkit/lib/utils/neynar/postDataToNeynar.js:18:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.neynarFrameValidation (webpack-internal:///(rsc)/./node_modules/@coinbase/onchainkit/lib/utils/neynar/frame/neynarFrameValidation.js:7:26)
    at async getFrameMessage (webpack-internal:///(rsc)/./node_modules/@coinbase/onchainkit/lib/frame/getFrameMessage.js:20:22)
    at async getResponse (webpack-internal:///(rsc)/./app/api/frame/route.ts:14:34)
    at async /home/claudio/src/cartesi/a-frame-in-100-lines/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:62499

Extra comments

This repo is using onchainkit library 0.14.1 and the framegear app on onchainkit's repo is using onchainkit library version 0.15.0.
I updated this repo to version 0.15.0, but the error is the same.

action type "tx"?

{
action: 'tx',
label: 'Send Base Sepolia',
target: `${NEXT_PUBLIC_URL}/api/send-ether`,
},

Hi, I have not seen "tx" anywhere in the documentation, where do you get this from? Few weeks ago, I learned about the mint action from your example too, when it was still not documented either.

thank you

action: link is wrong?

According to the docs, it seems that only post and post_redirect is supported, but it seems that type link also works. Can you support this with some resources?

{
action: 'link',
label: 'Link to Google',
target: 'https://www.google.com',
},

It also gives TS error
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.