[
  {
    "path": ".gitignore",
    "content": "node_modules\n.DS_STORE\n.next/\nyarn.lock\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2024 Leonardo Zizzamia\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "<p align=\"center\">\n  <picture>\n    <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://github.com/Zizzamia/a-frame-in-100-lines/blob/main/public/park-4.png\">\n    <img alt=\"OnchainKit logo vibes\" src=\"https://github.com/Zizzamia/a-frame-in-100-lines/blob/main/public/park-4.png\" width=\"auto\">\n  </picture>\n</p>\n\n# A Frame in 100 lines (or less)\n\nFarcaster Frames in less than 100 lines, and ready to be deployed to Vercel.\n\nTo test a **deployed** Frame, use: https://warpcast.com/~/developers/frames.\n\nTo test a **localhost** Frame, use: [Framegear](https://onchainkit.xyz/frame/framegear).\nA simple tool that allows you to run and test your frames locally:\n\n- without publishing\n- without casting\n- without spending warps\n\nAnd let us know what you build by either mentioning @zizzamia on [Warpcast](https://warpcast.com/zizzamia) or [X](https://twitter.com/Zizzamia).\n\n<br />\n\nHave fun! ⛵️\n\n<br />\n\n## App Routing files\n\n- app/\n  - [config.ts](https://github.com/Zizzamia/a-frame-in-100-lines?tab=readme-ov-file#appconfigts)\n  - [layout.tsx](https://github.com/Zizzamia/a-frame-in-100-lines?tab=readme-ov-file#applayouttsx)\n  - [page.tsx](https://github.com/Zizzamia/a-frame-in-100-lines?tab=readme-ov-file#apppagetsx)\n- api/\n  - frame/\n    - [route.ts](https://github.com/Zizzamia/a-frame-in-100-lines?tab=readme-ov-file#appapiframeroutets)\n\n<br />\n\n### `app/page.tsx`\n\n```tsx\nimport { getFrameMetadata } from '@coinbase/onchainkit/frame';\nimport type { Metadata } from 'next';\nimport { NEXT_PUBLIC_URL } from './config';\n\nconst frameMetadata = getFrameMetadata({\n  buttons: [\n    {\n      label: 'Story time!',\n    },\n    {\n      action: 'link',\n      label: 'Link to Google',\n      target: 'https://www.google.com',\n    },\n    {\n      label: 'Redirect to pictures',\n      action: 'post_redirect',\n    },\n  ],\n  image: {\n    src: `${NEXT_PUBLIC_URL}/park-3.png`,\n    aspectRatio: '1:1',\n  },\n  input: {\n    text: 'Tell me a boat story',\n  },\n  postUrl: `${NEXT_PUBLIC_URL}/api/frame`,\n});\n\nexport const metadata: Metadata = {\n  title: 'zizzamia.xyz',\n  description: 'LFG',\n  openGraph: {\n    title: 'zizzamia.xyz',\n    description: 'LFG',\n    images: [`${NEXT_PUBLIC_URL}/park-1.png`],\n  },\n  other: {\n    ...frameMetadata,\n  },\n};\n\nexport default function Page() {\n  return (\n    <>\n      <h1>zizzamia.xyz</h1>\n    </>\n  );\n}\n```\n\n### `app/layout.tsx`\n\n```tsx\nexport const viewport = {\n  width: 'device-width',\n  initialScale: 1.0,\n};\n\nexport default function RootLayout({ children }: { children: React.ReactNode }) {\n  return (\n    <html lang=\"en\">\n      <body>{children}</body>\n    </html>\n  );\n}\n```\n\n### `app/config.ts`\n\n```ts\nexport const NEXT_PUBLIC_URL = 'https://zizzamia.xyz';\n```\n\n### `app/api/frame/route.ts`\n\n```ts\nimport { FrameRequest, getFrameMessage, getFrameHtmlResponse } from '@coinbase/onchainkit/frame';\nimport { NextRequest, NextResponse } from 'next/server';\nimport { NEXT_PUBLIC_URL } from '../../config';\n\nasync function getResponse(req: NextRequest): Promise<NextResponse> {\n  let accountAddress: string | undefined = '';\n  let text: string | undefined = '';\n\n  const body: FrameRequest = await req.json();\n  const { isValid, message } = await getFrameMessage(body, { neynarApiKey: 'NEYNAR_ONCHAIN_KIT' });\n\n  if (isValid) {\n    accountAddress = message.interactor.verified_accounts[0];\n  }\n\n  if (message?.input) {\n    text = message.input;\n  }\n\n  if (message?.button === 3) {\n    return NextResponse.redirect(\n      'https://www.google.com/search?q=cute+dog+pictures&tbm=isch&source=lnms',\n      { status: 302 },\n    );\n  }\n\n  return new NextResponse(\n    getFrameHtmlResponse({\n      buttons: [\n        {\n          label: `🌲 ${text} 🌲`,\n        },\n      ],\n      image: {\n        src: `${NEXT_PUBLIC_URL}/park-1.png`,\n      },\n      postUrl: `${NEXT_PUBLIC_URL}/api/frame`,\n    }),\n  );\n}\n\nexport async function POST(req: NextRequest): Promise<Response> {\n  return getResponse(req);\n}\n\nexport const dynamic = 'force-dynamic';\n```\n\n<br />\n\n## Resources\n\n- [Official Farcaster Frames documentation](https://docs.farcaster.xyz/learn/what-is-farcaster/frames)\n- [Official Farcaster Frame specification](https://docs.farcaster.xyz/reference/frames/spec)\n- [OnchainKit documentation](https://onchainkit.xyz)\n\n<br />\n\n## Community ☁️ 🌁 ☁️\n\nCheck out the following places for more OnchainKit-related content:\n\n- Follow @zizzamia ([X](https://twitter.com/zizzamia), [Farcaster](https://warpcast.com/zizzamia)) for project updates\n- Join the discussions on our [OnchainKit warpcast channel](https://warpcast.com/~/channel/onchainkit)\n\n## Authors\n\n- [@zizzamia](https://github.com/zizzamia.png) ([X](https://twitter.com/Zizzamia))\n- [@cnasc](https://github.com/cnasc.png) ([warpcast](https://warpcast.com/cnasc))\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n"
  },
  {
    "path": "app/_contracts/BuyMeACoffeeABI.ts",
    "content": "/**\n * This ABI is trimmed down to just the functions we expect to call for the\n * sake of minimizing bytes downloaded.\n */\nconst abi = [\n  { type: 'constructor', inputs: [], stateMutability: 'nonpayable' },\n  { type: 'receive', stateMutability: 'payable' },\n  {\n    type: 'function',\n    name: 'buyCoffee',\n    inputs: [\n      { name: 'numCoffees', type: 'uint256', internalType: 'uint256' },\n      { name: 'message', type: 'string', internalType: 'string' },\n    ],\n    outputs: [],\n    stateMutability: 'payable',\n  },\n  {\n    type: 'function',\n    name: 'getMemos',\n    inputs: [\n      { name: 'index', type: 'uint256', internalType: 'uint256' },\n      { name: 'size', type: 'uint256', internalType: 'uint256' },\n    ],\n    outputs: [\n      {\n        name: '',\n        type: 'tuple[]',\n        internalType: 'struct Memo[]',\n        components: [\n          { name: 'numCoffees', type: 'uint256', internalType: 'uint256' },\n          { name: 'message', type: 'string', internalType: 'string' },\n          { name: 'time', type: 'uint256', internalType: 'uint256' },\n          { name: 'userAddress', type: 'address', internalType: 'address' },\n        ],\n      },\n    ],\n    stateMutability: 'view',\n  },\n  {\n    type: 'function',\n    name: 'memos',\n    inputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],\n    outputs: [\n      { name: 'numCoffees', type: 'uint256', internalType: 'uint256' },\n      { name: 'message', type: 'string', internalType: 'string' },\n      { name: 'time', type: 'uint256', internalType: 'uint256' },\n      { name: 'userAddress', type: 'address', internalType: 'address' },\n    ],\n    stateMutability: 'view',\n  },\n  {\n    type: 'function',\n    name: 'modifyMemoMessage',\n    inputs: [\n      { name: 'index', type: 'uint256', internalType: 'uint256' },\n      { name: 'message', type: 'string', internalType: 'string' },\n    ],\n    outputs: [],\n    stateMutability: 'nonpayable',\n  },\n  {\n    type: 'function',\n    name: 'owner',\n    inputs: [],\n    outputs: [{ name: '', type: 'address', internalType: 'address payable' }],\n    stateMutability: 'view',\n  },\n  {\n    type: 'function',\n    name: 'price',\n    inputs: [],\n    outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],\n    stateMutability: 'view',\n  },\n  {\n    type: 'function',\n    name: 'removeMemo',\n    inputs: [{ name: 'index', type: 'uint256', internalType: 'uint256' }],\n    outputs: [],\n    stateMutability: 'nonpayable',\n  },\n  {\n    type: 'function',\n    name: 'setPriceForCoffee',\n    inputs: [{ name: '_price', type: 'uint256', internalType: 'uint256' }],\n    outputs: [],\n    stateMutability: 'nonpayable',\n  },\n  {\n    type: 'function',\n    name: 'withdrawTips',\n    inputs: [],\n    outputs: [],\n    stateMutability: 'nonpayable',\n  },\n  {\n    type: 'event',\n    name: 'BuyMeACoffeeEvent',\n    inputs: [\n      { name: 'buyer', type: 'address', indexed: true, internalType: 'address' },\n      { name: 'price', type: 'uint256', indexed: false, internalType: 'uint256' },\n    ],\n    anonymous: false,\n  },\n  {\n    type: 'event',\n    name: 'NewMemo',\n    inputs: [\n      { name: 'userAddress', type: 'address', indexed: true, internalType: 'address' },\n      { name: 'time', type: 'uint256', indexed: false, internalType: 'uint256' },\n      { name: 'numCoffees', type: 'uint256', indexed: false, internalType: 'uint256' },\n      { name: 'message', type: 'string', indexed: false, internalType: 'string' },\n    ],\n    anonymous: false,\n  },\n  { type: 'error', name: 'InsufficientFunds', inputs: [] },\n  {\n    type: 'error',\n    name: 'InvalidArguments',\n    inputs: [{ name: 'message', type: 'string', internalType: 'string' }],\n  },\n  { type: 'error', name: 'OnlyOwner', inputs: [] },\n] as const;\n\nexport default abi;\n"
  },
  {
    "path": "app/api/frame/route.ts",
    "content": "import { FrameRequest, getFrameMessage, getFrameHtmlResponse } from '@coinbase/onchainkit/frame';\nimport { NextRequest, NextResponse } from 'next/server';\nimport { NEXT_PUBLIC_URL } from '../../config';\n\nasync function getResponse(req: NextRequest): Promise<NextResponse> {\n  const body: FrameRequest = await req.json();\n  const { isValid, message } = await getFrameMessage(body, { neynarApiKey: 'NEYNAR_ONCHAIN_KIT' });\n\n  if (!isValid) {\n    return new NextResponse('Message not valid', { status: 500 });\n  }\n\n  const text = message.input || '';\n  let state = {\n    page: 0,\n  };\n  try {\n    state = JSON.parse(decodeURIComponent(message.state?.serialized));\n  } catch (e) {\n    console.error(e);\n  }\n\n  /**\n   * Use this code to redirect to a different page\n   */\n  if (message?.button === 3) {\n    return NextResponse.redirect(\n      'https://www.google.com/search?q=cute+dog+pictures&tbm=isch&source=lnms',\n      { status: 302 },\n    );\n  }\n\n  return new NextResponse(\n    getFrameHtmlResponse({\n      buttons: [\n        {\n          label: `State: ${state?.page || 0}`,\n        },\n        {\n          action: 'link',\n          label: 'OnchainKit',\n          target: 'https://onchainkit.xyz',\n        },\n        {\n          action: 'post_redirect',\n          label: 'Dog pictures',\n        },\n      ],\n      image: {\n        src: `${NEXT_PUBLIC_URL}/park-1.png`,\n      },\n      postUrl: `${NEXT_PUBLIC_URL}/api/frame`,\n      state: {\n        page: state?.page + 1,\n        time: new Date().toISOString(),\n      },\n    }),\n  );\n}\n\nexport async function POST(req: NextRequest): Promise<Response> {\n  return getResponse(req);\n}\n\nexport const dynamic = 'force-dynamic';\n"
  },
  {
    "path": "app/api/tx/route.ts",
    "content": "import { FrameRequest, getFrameMessage } from '@coinbase/onchainkit/frame';\nimport { NextRequest, NextResponse } from 'next/server';\nimport { encodeFunctionData, parseEther } from 'viem';\nimport { baseSepolia } from 'viem/chains';\nimport BuyMeACoffeeABI from '../../_contracts/BuyMeACoffeeABI';\nimport { BUY_MY_COFFEE_CONTRACT_ADDR } from '../../config';\nimport type { FrameTransactionResponse } from '@coinbase/onchainkit/frame';\n\nasync function getResponse(req: NextRequest): Promise<NextResponse | Response> {\n  const body: FrameRequest = await req.json();\n  // Remember to replace 'NEYNAR_ONCHAIN_KIT' with your own Neynar API key\n  const { isValid } = await getFrameMessage(body, { neynarApiKey: 'NEYNAR_ONCHAIN_KIT' });\n\n  if (!isValid) {\n    return new NextResponse('Message not valid', { status: 500 });\n  }\n\n  const data = encodeFunctionData({\n    abi: BuyMeACoffeeABI,\n    functionName: 'buyCoffee',\n    args: [parseEther('1'), 'Coffee all day!'],\n  });\n\n  const txData: FrameTransactionResponse = {\n    chainId: `eip155:${baseSepolia.id}`,\n    method: 'eth_sendTransaction',\n    params: {\n      abi: [],\n      data,\n      to: BUY_MY_COFFEE_CONTRACT_ADDR,\n      value: parseEther('0.00004').toString(), // 0.00004 ETH\n    },\n  };\n  return NextResponse.json(txData);\n}\n\nexport async function POST(req: NextRequest): Promise<Response> {\n  return getResponse(req);\n}\n\nexport const dynamic = 'force-dynamic';\n"
  },
  {
    "path": "app/api/tx-success/route.ts",
    "content": "import { FrameRequest, getFrameMessage, getFrameHtmlResponse } from '@coinbase/onchainkit/frame';\nimport { NextRequest, NextResponse } from 'next/server';\nimport { NEXT_PUBLIC_URL } from '../../config';\n\nasync function getResponse(req: NextRequest): Promise<NextResponse> {\n  const body: FrameRequest = await req.json();\n  const { isValid } = await getFrameMessage(body);\n\n  if (!isValid) {\n    return new NextResponse('Message not valid', { status: 500 });\n  }\n\n  return new NextResponse(\n    getFrameHtmlResponse({\n      buttons: [\n        {\n          label: `Tx: ${body?.untrustedData?.transactionId || '--'}`,\n        },\n      ],\n      image: {\n        src: `${NEXT_PUBLIC_URL}/park-4.png`,\n      },\n    }),\n  );\n}\n\nexport async function POST(req: NextRequest): Promise<Response> {\n  return getResponse(req);\n}\n\nexport const dynamic = 'force-dynamic';\n"
  },
  {
    "path": "app/config.ts",
    "content": "// use NODE_ENV to not have to change config based on where it's deployed\nexport const NEXT_PUBLIC_URL =\n  process.env.NODE_ENV == 'development' ? 'http://localhost:3000' : 'https://zizzamia.xyz';\nexport const BUY_MY_COFFEE_CONTRACT_ADDR = '0xcD3D5E4E498BAb2e0832257569c3Fd4AE439dD6f';\n"
  },
  {
    "path": "app/layout.tsx",
    "content": "export const viewport = {\n  width: 'device-width',\n  initialScale: 1.0,\n};\n\nexport default function RootLayout({ children }: { children: React.ReactNode }) {\n  return (\n    <html lang=\"en\">\n      <body>{children}</body>\n    </html>\n  );\n}\n"
  },
  {
    "path": "app/page.tsx",
    "content": "import { getFrameMetadata } from '@coinbase/onchainkit/frame';\nimport type { Metadata } from 'next';\nimport { NEXT_PUBLIC_URL } from './config';\n\nconst frameMetadata = getFrameMetadata({\n  buttons: [\n    {\n      label: 'Story time',\n    },\n    {\n      action: 'tx',\n      label: 'Send Base Sepolia',\n      target: `${NEXT_PUBLIC_URL}/api/tx`,\n      postUrl: `${NEXT_PUBLIC_URL}/api/tx-success`,\n    },\n  ],\n  image: {\n    src: `${NEXT_PUBLIC_URL}/park-3.png`,\n    aspectRatio: '1:1',\n  },\n  input: {\n    text: 'Tell me a story',\n  },\n  postUrl: `${NEXT_PUBLIC_URL}/api/frame`,\n});\n\nexport const metadata: Metadata = {\n  title: 'zizzamia.xyz',\n  description: 'LFG',\n  openGraph: {\n    title: 'zizzamia.xyz',\n    description: 'LFG',\n    images: [`${NEXT_PUBLIC_URL}/park-1.png`],\n  },\n  other: {\n    ...frameMetadata,\n  },\n};\n\nexport default function Page() {\n  return (\n    <>\n      <h1>zizzamia.xyz</h1>\n    </>\n  );\n}\n"
  },
  {
    "path": "next-env.d.ts",
    "content": "/// <reference types=\"next\" />\n/// <reference types=\"next/image-types/global\" />\n\n// NOTE: This file should not be edited\n// see https://nextjs.org/docs/basic-features/typescript for more information.\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"a-frame-in-100-lines\",\n  \"version\": \"0.14.0\",\n  \"scripts\": {\n    \"build\": \"rm -rf .next && next build\",\n    \"dev\": \"next dev\",\n    \"format\": \"prettier --log-level warn --write .\",\n    \"start\": \"next start\",\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"keywords\": [],\n  \"author\": \"https://twitter.com/Zizzamia\",\n  \"license\": \"MIT\",\n  \"dependencies\": {\n    \"@coinbase/onchainkit\": \"^0.27.0\",\n    \"next\": \"13.5.6\",\n    \"react\": \"^18.2.0\",\n    \"react-dom\": \"^18.2.0\"\n  },\n  \"devDependencies\": {\n    \"@types/node\": \"^20.11.8\",\n    \"@types/react\": \"18.2.48\",\n    \"prettier\": \"^3.2.4\",\n    \"typescript\": \"^5.3.3\"\n  }\n}\n"
  },
  {
    "path": "prettier.config.js",
    "content": "module.exports = {\n  arrowParens: 'always',\n  bracketSameLine: false,\n  jsxSingleQuote: false,\n  plugins: [],\n  printWidth: 100,\n  semi: true,\n  singleQuote: true,\n  tabWidth: 2,\n  trailingComma: 'all',\n  useTabs: false,\n};\n"
  },
  {
    "path": "tsconfig.json",
    "content": "{\n  \"compilerOptions\": {\n    \"target\": \"es2020\",\n    \"lib\": [\"dom\", \"dom.iterable\", \"esnext\"],\n    \"allowJs\": true,\n    \"skipLibCheck\": true,\n    \"strict\": true,\n    \"noEmit\": true,\n    \"esModuleInterop\": true,\n    \"module\": \"esnext\",\n    \"moduleResolution\": \"bundler\",\n    \"resolveJsonModule\": true,\n    \"isolatedModules\": true,\n    \"jsx\": \"preserve\",\n    \"incremental\": true,\n    \"plugins\": [\n      {\n        \"name\": \"next\"\n      }\n    ]\n  },\n  \"include\": [\"custom.d.ts\", \"next-env.d.ts\", \"**/*.ts\", \"**/*.tsx\", \".next/types/**/*.ts\"],\n  \"exclude\": [\"contracts\", \"node_modules\"],\n}\n"
  }
]