Skip to content

Make Uniswap a frame#2

Merged
horsefacts merged 3 commits intomainfrom
farcaster-frame
Dec 16, 2024
Merged

Make Uniswap a frame#2
horsefacts merged 3 commits intomainfrom
farcaster-frame

Conversation

@horsefacts
Copy link
Copy Markdown
Owner

@horsefacts horsefacts commented Dec 16, 2024

GeDePj5boAE5evS

Farcaster Frames are now web apps. That means if you have an existing web app that connects to a wallet, you can turn it into a frame that will:

  • Display an interactive embed in the feed
  • Launch your app with the user's mobile wallet already connected
  • Enable users to save your app to their Farcaster client
  • Surface your app in search and explore listings
  • Allow you to send in-app notifications

Let's make Uniswap a frame.

1. Install Frame SDK and Wagmi connector packages

yarn add @farcaster/frame-sdk @farcaster/frame-wagmi-connector

2. Load SDK and call ready()

Load the Frame SDK and call ready() when your app loads.

apps/web/src/index.tsx:

import FrameSDK from '@farcaster/frame-sdk'
import farcasterFrame from '@farcaster/frame-wagmi-connector'
import { wagmiConfig } from 'components/Web3Provider/wagmiConfig'
import { connect } from 'wagmi/actions'

function FarcasterFrameProvider({ children }: PropsWithChildren) {
  useEffect(() => {
    const init = async () => {
      const context = await FrameSDK.context

      // Autoconnect if running in a frame.
      if (context?.client.clientFid) {
        connect(wagmiConfig, { connector: farcasterFrame() })
      }

      // Hide splash screen after UI renders.
      setTimeout(() => {
        FrameSDK.actions.ready()
      }, 500)
    }
    init()
  }, [])

  return <>{children}</>
}

Add to your provider stack:

<FarcasterFrameProvider>
  <App />
</FarcasterFrameProvider>

3. Set up Wagmi connector

Add the farcasterFrame connector to your Wagmi config.

apps/web/src/components/Web3Provider/wagmiConfig.ts

import { farcasterFrame } from '@farcaster/frame-wagmi-connector'

export const wagmiConfig = createConfig({
  chains: [getChainInfo(UniverseChainId.Mainnet), ...ALL_CHAIN_IDS.map(getChainInfo)],
  connectors: [
    farcasterFrame(),
    injectedWithFallback(),
    walletConnect(WC_PARAMS),
    coinbaseWallet({
      appName: 'Uniswap',
      // CB SDK doesn't pass the parent origin context to their passkey site
      // Flagged to CB team and can remove UNISWAP_WEB_URL once fixed
      appLogoUrl: `${UNISWAP_WEB_URL}${UNISWAP_LOGO}`,
      reloadOnDisconnect: false,
      enableMobileWalletLink: true,
    }),
    safe(),
  ],
  client({ chain }) {
    return createClient({
      chain,
      batch: { multicall: true },
      pollingInterval: 12_000,
      transport: http(chain.rpcUrls.interface.http[0]),
    })
  },
})

4. Add frame <meta> tags

Add a frame <meta> tag to any page URL you want to frame-ify. This one adds an embed to the homepage that launches into the "swap" page.

apps/web/public/index.html

    <meta name="fc:frame" content='{
      "version": "next",
      "imageUrl": "https://uniframe.org/images/1200x630_Rich_Link_Preview_Image.png",
      "button":{
        "title": "Swap",
        "action": {
          "type": "launch_frame",
          "name": "Uniframe",
          "url": "https://uniframe.org/swap",
          "splashImageUrl": "https://uniframe.org/favicon.png",
          "splashBackgroundColor": "#131313"
        }
      }
    }' data-rh="true">

5. OPTIONAL: Add a farcaster.json file

Optional but recommended: generate a farcaster.json manifest file from the Warpcast dev tools and serve it at /.well-known/farcaster.json.

This associates your Farcaster account with the frame app, allows users to save it to their Farcaster client, and gives you access to in-app notifications.

apps/web/public/.well-known/farcaster.json

{
    "accountAssociation": {
      "header": "eyJmaWQiOjM2MjEsInR5cGUiOiJjdXN0b2R5Iiwia2V5IjoiMHgyY2Q4NWEwOTMyNjFmNTkyNzA4MDRBNkVBNjk3Q2VBNENlQkVjYWZFIn0",
      "payload": "eyJkb21haW4iOiJ1bmlmcmFtZS5vcmcifQ",
      "signature": "MHgxZTZlZTkyNmRiZjU5ZDljZjM4MGI1YTU0ZTI2YzUxYjEyN2MyZjM2NTM3ZDJhYWI5ZGZjOTBiMDVlMjRjY2U4MzYxZDk5YmRhOGZmYWU0NjliZTY0ZWNlZTVhZTA5MjYzNWM5NjVlYzFmZmRjNDEwOGZiNjJlNmRmYmRiM2VkNDFi"
    },
    "frame": {
      "name": "Uniframe",
      "version": "0.0.1",
      "iconUrl": "https://uniframe.org/favicon.png",
      "homeUrl": "https://uniframe.org/#/swap",
      "splashImageUrl": "https://uniframe.org/favicon.png",
      "splashBackgroundColor": "#131313"
    }
  }

@vercel
Copy link
Copy Markdown

vercel bot commented Dec 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
uniframe 🔄 Building (Inspect) Visit Preview Dec 16, 2024 2:52am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant