title | description |
---|---|
Guide: Display Frames in your app |
Frames.js is the react based framework for making frames. Debugger included. |
This guide shows you how to add frames rendering to your next.js + tailwind app using frames.js.
::::steps
Create a new Next.js app
npx create-next-app@latest my-project --ts --eslint --tailwind --app
cd my-project
Add @frames.js/render
to your project
yarn add @frames.js/render
export { GET, POST } from "@frames.js/render/next";
"use client";
import {
FrameUI,
fallbackFrameContext,
FrameContext,
} from "@frames.js/render";
import { signFrameAction, FarcasterSigner } from '@frames.js/render/farcaster'
import { FrameImageNext } from "@frames.js/render/next";
import { FrameButton } from "frames.js";
import { useFrame } from "@frames.js/render/use-frame";
export default function Page() {
// TODO: replace with your farcaster signer
const farcasterSigner: FarcasterSigner = {
fid: 1,
status: 'approved',
publicKey:
"0x00000000000000000000000000000000000000000000000000000000000000000",
privateKey:
"0x00000000000000000000000000000000000000000000000000000000000000000",
};
const frameState = useFrame({
// replace with your frame url
homeframeUrl:
"https://fc-polls.vercel.app/polls/73c6efda-bae7-4d46-8f36-3bb3b8377448",
// corresponds to the name of the route for POST in step 3
frameActionProxy: "/frames",
// corresponds to the name of the route for GET in step 3
frameGetProxy: "/frames",
frameContext: fallbackFrameContext,
// map to your identity if you have one
signerState: {
hasSigner: true,
signer: farcasterSigner,
onSignerlessFramePress: () => {
// Implement me
alert("A frame button was pressed without a signer. Perhaps you want to prompt a login");
},
signFrameAction: signFrameAction,
},
});
return (
<div className="w-[400px]">
<FrameUI frameState={frameState} theme={{}} FrameImage={FrameImageNext} />
</div>
);
}
In order for the styles to work, your project should have tailwind set up as well as the tailwind.config.js rule
const config = {
// ...
content: [
"./app/*.{ts,tsx,js,css}",
"./app/**/*.{ts,tsx,js,css}",
"./node_modules/frames.js/dist/render/next/*.{ts,tsx,js,css}",
"./node_modules/frames.js/dist/render/*.{ts,tsx,js,css}",
// ...
]
}
const nextConfig = {
images: {
remotePatterns: [
{
protocol: "https",
hostname: "**",
},
],
},
};
::::
If needed, you can implement FrameUI
yourself, using the FrameUI component as a template