Docs
Farcaster

Farcaster

This is the lambda function that generates the Farcaster Frame for the token.

Overview

The lambdas/farcaster/ is an AWS Lambda@Edge function designed to dynamically generate Farcaster Frame for tokens. It will generate the required <head> for the Farcaster Frame and merge it with the original <body> from S3. You can share your link to Wrapcast or other social media platforms which support Farcaster Frame.

Build

To set up the lambda function, follow these steps:

  1. Install dependencies:

    pnpm i
  2. Build the project:

    pnpm build
  3. Package the lambda function:

    pnpm package

This process will generate a token-kit-farcaster-lambda.zip file that can be uploaded to AWS Lambda.

Deploy

To deploy the lambda function, follow these steps:

  1. Create a new AWS Lambda function in us-east-1 using the token-kit-farcaster-lambda.zip file generated in the previous step.
  2. Set the property permissions to AWS Lambda Basic Execution Role (with S3 access).
  3. Publish to your CloudFront Origin request function associations.

For more informations about Lambda@Edge, please follow the document Customize at the edge with Lambda@Edge

How it works

Request  ---->  [CloudFront] [Lambda@Edge] <--- S3 (original html <body>)
Response <----                         ^----- farcaster frame service API (html <head>)

The Lambda@Edge function will merge the original html <body> from S3 with the html <head> from the farcaster frame service API response.

Since Lambda@Edge cannot get the response from the origin (See: Work with requests and responses), so we read the original html from S3 and replace the <head> with the <head> from the farcaster frame service API response.

We expect you use S3 + CloudFront to serve your static files with SPA. If your static files structure is different, you may need to modify the code.

And we expect the URL parameters are:

  • chainId (number): the chainId of the network, like 1, 137, and so on
  • contract (string): the contract address of the token (0x....)
  • tokenId (number): the tokenId of the token

Full request URL example: https://example.com/?chainId=1&contract=0x1234567890123456789012345678901234567890&tokenId=1