Repository: Zizzamia/a-frame-in-100-lines
Branch: main
Commit: 525089eaff58
Files: 14
Total size: 16.4 KB
Directory structure:
gitextract_f7tggf9_/
├── .gitignore
├── LICENSE
├── README.md
├── app/
│ ├── _contracts/
│ │ └── BuyMeACoffeeABI.ts
│ ├── api/
│ │ ├── frame/
│ │ │ └── route.ts
│ │ ├── tx/
│ │ │ └── route.ts
│ │ └── tx-success/
│ │ └── route.ts
│ ├── config.ts
│ ├── layout.tsx
│ └── page.tsx
├── next-env.d.ts
├── package.json
├── prettier.config.js
└── tsconfig.json
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
node_modules
.DS_STORE
.next/
yarn.lock
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2024 Leonardo Zizzamia
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/Zizzamia/a-frame-in-100-lines/blob/main/public/park-4.png">
<img alt="OnchainKit logo vibes" src="https://github.com/Zizzamia/a-frame-in-100-lines/blob/main/public/park-4.png" width="auto">
</picture>
</p>
# 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](https://onchainkit.xyz/frame/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](https://warpcast.com/zizzamia) or [X](https://twitter.com/Zizzamia).
<br />
Have fun! ⛵️
<br />
## App Routing files
- app/
- [config.ts](https://github.com/Zizzamia/a-frame-in-100-lines?tab=readme-ov-file#appconfigts)
- [layout.tsx](https://github.com/Zizzamia/a-frame-in-100-lines?tab=readme-ov-file#applayouttsx)
- [page.tsx](https://github.com/Zizzamia/a-frame-in-100-lines?tab=readme-ov-file#apppagetsx)
- api/
- frame/
- [route.ts](https://github.com/Zizzamia/a-frame-in-100-lines?tab=readme-ov-file#appapiframeroutets)
<br />
### `app/page.tsx`
```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`
```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`
```ts
export const NEXT_PUBLIC_URL = 'https://zizzamia.xyz';
```
### `app/api/frame/route.ts`
```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';
```
<br />
## Resources
- [Official Farcaster Frames documentation](https://docs.farcaster.xyz/learn/what-is-farcaster/frames)
- [Official Farcaster Frame specification](https://docs.farcaster.xyz/reference/frames/spec)
- [OnchainKit documentation](https://onchainkit.xyz)
<br />
## Community ☁️ 🌁 ☁️
Check out the following places for more OnchainKit-related content:
- Follow @zizzamia ([X](https://twitter.com/zizzamia), [Farcaster](https://warpcast.com/zizzamia)) for project updates
- Join the discussions on our [OnchainKit warpcast channel](https://warpcast.com/~/channel/onchainkit)
## Authors
- [@zizzamia](https://github.com/zizzamia.png) ([X](https://twitter.com/Zizzamia))
- [@cnasc](https://github.com/cnasc.png) ([warpcast](https://warpcast.com/cnasc))
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
================================================
FILE: app/_contracts/BuyMeACoffeeABI.ts
================================================
/**
* This ABI is trimmed down to just the functions we expect to call for the
* sake of minimizing bytes downloaded.
*/
const abi = [
{ type: 'constructor', inputs: [], stateMutability: 'nonpayable' },
{ type: 'receive', stateMutability: 'payable' },
{
type: 'function',
name: 'buyCoffee',
inputs: [
{ name: 'numCoffees', type: 'uint256', internalType: 'uint256' },
{ name: 'message', type: 'string', internalType: 'string' },
],
outputs: [],
stateMutability: 'payable',
},
{
type: 'function',
name: 'getMemos',
inputs: [
{ name: 'index', type: 'uint256', internalType: 'uint256' },
{ name: 'size', type: 'uint256', internalType: 'uint256' },
],
outputs: [
{
name: '',
type: 'tuple[]',
internalType: 'struct Memo[]',
components: [
{ name: 'numCoffees', type: 'uint256', internalType: 'uint256' },
{ name: 'message', type: 'string', internalType: 'string' },
{ name: 'time', type: 'uint256', internalType: 'uint256' },
{ name: 'userAddress', type: 'address', internalType: 'address' },
],
},
],
stateMutability: 'view',
},
{
type: 'function',
name: 'memos',
inputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
outputs: [
{ name: 'numCoffees', type: 'uint256', internalType: 'uint256' },
{ name: 'message', type: 'string', internalType: 'string' },
{ name: 'time', type: 'uint256', internalType: 'uint256' },
{ name: 'userAddress', type: 'address', internalType: 'address' },
],
stateMutability: 'view',
},
{
type: 'function',
name: 'modifyMemoMessage',
inputs: [
{ name: 'index', type: 'uint256', internalType: 'uint256' },
{ name: 'message', type: 'string', internalType: 'string' },
],
outputs: [],
stateMutability: 'nonpayable',
},
{
type: 'function',
name: 'owner',
inputs: [],
outputs: [{ name: '', type: 'address', internalType: 'address payable' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'price',
inputs: [],
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'removeMemo',
inputs: [{ name: 'index', type: 'uint256', internalType: 'uint256' }],
outputs: [],
stateMutability: 'nonpayable',
},
{
type: 'function',
name: 'setPriceForCoffee',
inputs: [{ name: '_price', type: 'uint256', internalType: 'uint256' }],
outputs: [],
stateMutability: 'nonpayable',
},
{
type: 'function',
name: 'withdrawTips',
inputs: [],
outputs: [],
stateMutability: 'nonpayable',
},
{
type: 'event',
name: 'BuyMeACoffeeEvent',
inputs: [
{ name: 'buyer', type: 'address', indexed: true, internalType: 'address' },
{ name: 'price', type: 'uint256', indexed: false, internalType: 'uint256' },
],
anonymous: false,
},
{
type: 'event',
name: 'NewMemo',
inputs: [
{ name: 'userAddress', type: 'address', indexed: true, internalType: 'address' },
{ name: 'time', type: 'uint256', indexed: false, internalType: 'uint256' },
{ name: 'numCoffees', type: 'uint256', indexed: false, internalType: 'uint256' },
{ name: 'message', type: 'string', indexed: false, internalType: 'string' },
],
anonymous: false,
},
{ type: 'error', name: 'InsufficientFunds', inputs: [] },
{
type: 'error',
name: 'InvalidArguments',
inputs: [{ name: 'message', type: 'string', internalType: 'string' }],
},
{ type: 'error', name: 'OnlyOwner', inputs: [] },
] as const;
export default abi;
================================================
FILE: 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> {
const body: FrameRequest = await req.json();
const { isValid, message } = await getFrameMessage(body, { neynarApiKey: 'NEYNAR_ONCHAIN_KIT' });
if (!isValid) {
return new NextResponse('Message not valid', { status: 500 });
}
const text = message.input || '';
let state = {
page: 0,
};
try {
state = JSON.parse(decodeURIComponent(message.state?.serialized));
} catch (e) {
console.error(e);
}
/**
* Use this code to redirect to a different page
*/
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: `State: ${state?.page || 0}`,
},
{
action: 'link',
label: 'OnchainKit',
target: 'https://onchainkit.xyz',
},
{
action: 'post_redirect',
label: 'Dog pictures',
},
],
image: {
src: `${NEXT_PUBLIC_URL}/park-1.png`,
},
postUrl: `${NEXT_PUBLIC_URL}/api/frame`,
state: {
page: state?.page + 1,
time: new Date().toISOString(),
},
}),
);
}
export async function POST(req: NextRequest): Promise<Response> {
return getResponse(req);
}
export const dynamic = 'force-dynamic';
================================================
FILE: app/api/tx/route.ts
================================================
import { FrameRequest, getFrameMessage } from '@coinbase/onchainkit/frame';
import { NextRequest, NextResponse } from 'next/server';
import { encodeFunctionData, parseEther } from 'viem';
import { baseSepolia } from 'viem/chains';
import BuyMeACoffeeABI from '../../_contracts/BuyMeACoffeeABI';
import { BUY_MY_COFFEE_CONTRACT_ADDR } from '../../config';
import type { FrameTransactionResponse } from '@coinbase/onchainkit/frame';
async function getResponse(req: NextRequest): Promise<NextResponse | Response> {
const body: FrameRequest = await req.json();
// Remember to replace 'NEYNAR_ONCHAIN_KIT' with your own Neynar API key
const { isValid } = await getFrameMessage(body, { neynarApiKey: 'NEYNAR_ONCHAIN_KIT' });
if (!isValid) {
return new NextResponse('Message not valid', { status: 500 });
}
const data = encodeFunctionData({
abi: BuyMeACoffeeABI,
functionName: 'buyCoffee',
args: [parseEther('1'), 'Coffee all day!'],
});
const txData: FrameTransactionResponse = {
chainId: `eip155:${baseSepolia.id}`,
method: 'eth_sendTransaction',
params: {
abi: [],
data,
to: BUY_MY_COFFEE_CONTRACT_ADDR,
value: parseEther('0.00004').toString(), // 0.00004 ETH
},
};
return NextResponse.json(txData);
}
export async function POST(req: NextRequest): Promise<Response> {
return getResponse(req);
}
export const dynamic = 'force-dynamic';
================================================
FILE: app/api/tx-success/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> {
const body: FrameRequest = await req.json();
const { isValid } = await getFrameMessage(body);
if (!isValid) {
return new NextResponse('Message not valid', { status: 500 });
}
return new NextResponse(
getFrameHtmlResponse({
buttons: [
{
label: `Tx: ${body?.untrustedData?.transactionId || '--'}`,
},
],
image: {
src: `${NEXT_PUBLIC_URL}/park-4.png`,
},
}),
);
}
export async function POST(req: NextRequest): Promise<Response> {
return getResponse(req);
}
export const dynamic = 'force-dynamic';
================================================
FILE: app/config.ts
================================================
// use NODE_ENV to not have to change config based on where it's deployed
export const NEXT_PUBLIC_URL =
process.env.NODE_ENV == 'development' ? 'http://localhost:3000' : 'https://zizzamia.xyz';
export const BUY_MY_COFFEE_CONTRACT_ADDR = '0xcD3D5E4E498BAb2e0832257569c3Fd4AE439dD6f';
================================================
FILE: 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>
);
}
================================================
FILE: 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: 'tx',
label: 'Send Base Sepolia',
target: `${NEXT_PUBLIC_URL}/api/tx`,
postUrl: `${NEXT_PUBLIC_URL}/api/tx-success`,
},
],
image: {
src: `${NEXT_PUBLIC_URL}/park-3.png`,
aspectRatio: '1:1',
},
input: {
text: 'Tell me a 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>
</>
);
}
================================================
FILE: next-env.d.ts
================================================
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
================================================
FILE: package.json
================================================
{
"name": "a-frame-in-100-lines",
"version": "0.14.0",
"scripts": {
"build": "rm -rf .next && next build",
"dev": "next dev",
"format": "prettier --log-level warn --write .",
"start": "next start",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "https://twitter.com/Zizzamia",
"license": "MIT",
"dependencies": {
"@coinbase/onchainkit": "^0.27.0",
"next": "13.5.6",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^20.11.8",
"@types/react": "18.2.48",
"prettier": "^3.2.4",
"typescript": "^5.3.3"
}
}
================================================
FILE: prettier.config.js
================================================
module.exports = {
arrowParens: 'always',
bracketSameLine: false,
jsxSingleQuote: false,
plugins: [],
printWidth: 100,
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'all',
useTabs: false,
};
================================================
FILE: tsconfig.json
================================================
{
"compilerOptions": {
"target": "es2020",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": ["custom.d.ts", "next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["contracts", "node_modules"],
}
gitextract_f7tggf9_/ ├── .gitignore ├── LICENSE ├── README.md ├── app/ │ ├── _contracts/ │ │ └── BuyMeACoffeeABI.ts │ ├── api/ │ │ ├── frame/ │ │ │ └── route.ts │ │ ├── tx/ │ │ │ └── route.ts │ │ └── tx-success/ │ │ └── route.ts │ ├── config.ts │ ├── layout.tsx │ └── page.tsx ├── next-env.d.ts ├── package.json ├── prettier.config.js └── tsconfig.json
SYMBOL INDEX (10 symbols across 6 files)
FILE: app/api/frame/route.ts
function getResponse (line 5) | async function getResponse(req: NextRequest): Promise<NextResponse> {
function POST (line 61) | async function POST(req: NextRequest): Promise<Response> {
FILE: app/api/tx-success/route.ts
function getResponse (line 5) | async function getResponse(req: NextRequest): Promise<NextResponse> {
function POST (line 27) | async function POST(req: NextRequest): Promise<Response> {
FILE: app/api/tx/route.ts
function getResponse (line 9) | async function getResponse(req: NextRequest): Promise<NextResponse | Res...
function POST (line 37) | async function POST(req: NextRequest): Promise<Response> {
FILE: app/config.ts
constant NEXT_PUBLIC_URL (line 2) | const NEXT_PUBLIC_URL =
constant BUY_MY_COFFEE_CONTRACT_ADDR (line 4) | const BUY_MY_COFFEE_CONTRACT_ADDR = '0xcD3D5E4E498BAb2e0832257569c3Fd4AE...
FILE: app/layout.tsx
function RootLayout (line 6) | function RootLayout({ children }: { children: React.ReactNode }) {
FILE: app/page.tsx
function Page (line 40) | function Page() {
Condensed preview — 14 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (18K chars).
[
{
"path": ".gitignore",
"chars": 40,
"preview": "node_modules\n.DS_STORE\n.next/\nyarn.lock\n"
},
{
"path": "LICENSE",
"chars": 1074,
"preview": "MIT License\n\nCopyright (c) 2024 Leonardo Zizzamia\n\nPermission is hereby granted, free of charge, to any person obtaining"
},
{
"path": "README.md",
"chars": 4854,
"preview": "<p align=\"center\">\n <picture>\n <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://github.com/Zizzamia/a-fr"
},
{
"path": "app/_contracts/BuyMeACoffeeABI.ts",
"chars": 3739,
"preview": "/**\n * This ABI is trimmed down to just the functions we expect to call for the\n * sake of minimizing bytes downloaded.\n"
},
{
"path": "app/api/frame/route.ts",
"chars": 1670,
"preview": "import { FrameRequest, getFrameMessage, getFrameHtmlResponse } from '@coinbase/onchainkit/frame';\nimport { NextRequest, "
},
{
"path": "app/api/tx/route.ts",
"chars": 1415,
"preview": "import { FrameRequest, getFrameMessage } from '@coinbase/onchainkit/frame';\nimport { NextRequest, NextResponse } from 'n"
},
{
"path": "app/api/tx-success/route.ts",
"chars": 856,
"preview": "import { FrameRequest, getFrameMessage, getFrameHtmlResponse } from '@coinbase/onchainkit/frame';\nimport { NextRequest, "
},
{
"path": "app/config.ts",
"chars": 286,
"preview": "// use NODE_ENV to not have to change config based on where it's deployed\nexport const NEXT_PUBLIC_URL =\n process.env.N"
},
{
"path": "app/layout.tsx",
"chars": 239,
"preview": "export const viewport = {\n width: 'device-width',\n initialScale: 1.0,\n};\n\nexport default function RootLayout({ childre"
},
{
"path": "app/page.tsx",
"chars": 919,
"preview": "import { getFrameMetadata } from '@coinbase/onchainkit/frame';\nimport type { Metadata } from 'next';\nimport { NEXT_PUBLI"
},
{
"path": "next-env.d.ts",
"chars": 201,
"preview": "/// <reference types=\"next\" />\n/// <reference types=\"next/image-types/global\" />\n\n// NOTE: This file should not be edite"
},
{
"path": "package.json",
"chars": 646,
"preview": "{\n \"name\": \"a-frame-in-100-lines\",\n \"version\": \"0.14.0\",\n \"scripts\": {\n \"build\": \"rm -rf .next && next build\",\n "
},
{
"path": "prettier.config.js",
"chars": 224,
"preview": "module.exports = {\n arrowParens: 'always',\n bracketSameLine: false,\n jsxSingleQuote: false,\n plugins: [],\n printWid"
},
{
"path": "tsconfig.json",
"chars": 584,
"preview": "{\n \"compilerOptions\": {\n \"target\": \"es2020\",\n \"lib\": [\"dom\", \"dom.iterable\", \"esnext\"],\n \"allowJs\": true,\n "
}
]
About this extraction
This page contains the full source code of the Zizzamia/a-frame-in-100-lines GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 14 files (16.4 KB), approximately 5.0k tokens, and a symbol index with 10 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.