or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
On-Chain Basic Base Frames Workshop
Overview
This is a comprehensive educational workshop for aspiring Frame developers.
Note: a tremendous amount of the subsequent writing is ripped directly from the Frame official documentation found here.
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →Complete Frame Guide
WTF is a Frame?
Frame Speedrun
If you are already super comfortable with full-stack applications; check out the speedrun video:
Frame Repo Structure
Frames have two key distinct code components; the front end app, back end api. Here's an example of a Frame's codebase structure:
Folders
Files
.tsx
extension indicates this is a TypeScript file with JSX syntax.layout.tsx
likely is the Frame's React layout component. It serves as a template or structure for the UI, including common elements like headers, body and footers.Initial Frame
A frame is an HTML web application that lives at a URL (e.g. foo.com/app) on a web server. We'll refer to this web server as the "frame server."
The frame server:
Response Frames
When a user clicks a button on a frame, the app makes a POST request to the frame server with a frame signature which proves that the request came from the user. The server must respond with a new frame that is sent back to the user.
When a frame server receives a POST request:
Best Practices
Follow these best practices to work around the limitations of frames:
Rendering Frames
A frame enters Farcaster when a user creates a cast and embeds the frame URL in it. An app that wants to support frames must:
Constructing A Frame
A frame must include required properties and may contain optional properties. Frames can be validated using the Frame Validator tool provided by Warpcast.
Frame Properties
A frame property is a meta tag with a property and a content value. The properties are always prefixed with fc:frame.
Required Properties
fc:frame
A valid frame version string. The string must be a release date (e.g. 2020-01-01) or vNext. Apps must ignore versions they do not understand. Currently, the only valid version is vNext.fc:frame:image
An image which should have an aspect ratio of 1.91:1 or 1:1og:image
An image which should have an aspect ratio of 1.91:1. Fallback for clients that do not support frames.Optional Properties
fc:frame:post_url
A 256-byte string which contains a valid URL to send the Signature Packet to.fc:frame:button:$idx
A 256-byte string which is the label of the button at position $idx. A page may contain 0 to 4 buttons. If more than 1 button is present, the idx values must be in sequence starting from 1 (e.g., 1, 2, 3). If a broken sequence is present (e.g., 1, 2, 4), the frame is invalid.`fc:frame:button:$idx:action
Must be post, post_redirect, link, mint or tx. Defaults to post if not specified. See Button Actions for details on each action.fc:frame:button:$idx:target
A 256-byte string which determines the target of the action.fc:frame:button:$idx:post_url
A 256-byte string that defines a button-specific URL to send the Signature Packet to. If set, this overrides fc:frame:post_url.fc:frame:input:text
Adding this property enables the text field. The content is a 32-byte label that is shown to the user (e.g., Enter a message).fc:frame:image:aspect_ratio
Must be either 1.91:1 or 1:1. Defaults to 1.91:1fc:frame:state
A string containing serialized state (e.g. JSON) passed to the frame server. May be up to 4096 bytes. Serialized state just means that an object like a JSON has been serialized into bytes; which is ready to transmit server for reconstruction into the same JSON object.Button Actions
There are several different kinds of button actions that are used to drive the mechanics of a Frame. Here's a quick look at how Frame Button Actions are handled and authenticated:
post
What is a post?
The
fc:frame:post_url
meta tag describes the content URL.The post action sends an HTTP POST request to the frame or button post_url. This is the default button type.
The frame server receives a Signature Packet in the POST body, which includes information about which button was clicked, text input, and the cast context. The frame server must respond with a 200 OK and another frame.
post_redirect
What is a post redirect?
The post_redirect action sends an HTTP POST request to the frame or button post_url. You can use this action to redirect to a URL based on frame state or user input.
The frame server receives a Signature Packet in the POST body. The frame server must respond with a 302 Found and Location header that starts with http:// or https://.
link
The link action redirects the user to an external URL. You can use this action to redirect to a URL without handling a POST request to the frame server.
Clients do not make a request to the frame server for link actions. Instead, they redirect the user to the target URL.
mint
What is a CAIP-10 address?
The mint action allows the user to mint an NFT. Clients that support relaying or initiating onchain transactions may enhance the mint button by relaying a transaction or interacting with the user's walletl. Clients that do not fall back to linking to an external URL.
The target property must be a valid CAIP-10 address, plus an optional token ID. In this case the CAIP-10 address is the address of the NFT contract. Crawling the provided contract address yields an easter egg.
tx
What is eth_send huh?
The tx action allows a frame to send a transaction request to the user's connected wallet. Unlike other action types, tx actions have several steps.
First, the client makes a POST request to the target URL to fetch data about the transaction. The frame server receives a Signature Packet in the POST body, including the address of the connected wallet. The frame server must respond with a 200 OK and a JSON response describing the transaction:
The client forwards this transaction data to the user's wallet. If the user signs the transaction, the client makes a POST request to the post_url with a Signature Packet that includes the transaction hash. The frame server must respond with a 200 OK and another frame. The frame server must monitor the transaction hash to determine if the transaction succeeds, reverts, or times out.
Transaction Data Response Type
A transaction data response must match the following TransactionTargetResponse type with:
Ethereum Params
If the method is eth_sendTransaction and the chain is an Ethereum EVM chain, the param must be of type EthSendTransactionParams:
Images
There are a few rules for serving images in fc:frame:image tags:
Frame servers can use cache headers to refresh images and offer more dynamic first frame experiences:
Frame servers can use the max-age directive in the HTTP Cache-Control header to ensure images in the initial frame refresh automatically. A lower max-age ensures images update regularly without user interactions.
App developers should respect cache headers set by the original frame image, and their image proxy implementations should not interfere with durations.
Securing Frames
There are important security concerns that must be addressed by both frame developers and apps that implement frames.
WTF does this mean!?
Data Structures
Frame Signature
What is a protobuf?
A Frame signature proves that a user clicked a frame button. It is created by the Farcaster app, signed by the user's account and sent to the Frame server.
When a frame button is clicked, the Farcaster app must generate a FrameAction protobuf. A FrameAction is a new type of Farcaster message. Like all FC messages, it must be signed with an active Ed25519 account key (aka signer) that belongs to the user.
A FrameActionBody in a message m is valid only if it passes these validations:
Frame Signature Packet
A signature packet is a JSON object sent to the Frame server when a button is clicked. It contains two objects:
Signed Message — an authenticated protobuf that represents the user action. This message must be unpacked by a farcaster hub to read the data inside.
Unsigned Message — an unathenticated JSON object that represents the user action. can be read directly.
Unsigned messages can be spoofed and should usually be ignored. It is only safe to use them if you are performing an unauthenticated request.
If you are unsure, always read the signed message by sending it into the validateMessage endpoint on hubs and only trust the data it returns.
The Signed Message can be validated by calling the validateMessage API on Hubs. See the Hub HTTP API for reference. The hub (assuming it’s fully in sync) will validate the following:
Onchain Frames
Here's a nice tutorial for utilizing CoinBase's onchainkit for building on-chain capable Frames:
Workflow Notes
These are specific notes for the tutorial which can be found here.
Deploy to Vercel directly from Github
Add a
.env
file and.env*
to GitIgnoreCreate .env.local and add:
Images must have a 1.91 to 1 aspect ratio
Raid Guild Frames Resources
Resources:
Open Source Frames: