Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: docs mini-apps, helpers #512

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions site/pages/concepts/client-side-helpers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Client-Side Helpers

As you may know, Frog was initially built as a backend-only library.
With the recent features in Farcaster, Composer Actions and Mini Apps were introduced.

To keep up with the changes, Frog adds helpers for your web application to communicate with the parent iFrame.

[See the spec](https://warpcast.notion.site/Miniapp-Transactions-1216a6c0c10180b7b9f4eec58ec51e55)

## Creating a Cast (Composer Actions)

```tsx twoslash
// @noErrors
import { createCast } from 'frog/web'

export function App() {
return (
<button
onClick={() =>
createCast({
text: 'Hi!',
embeds: []
})
}
>
create cast
</button>
)
}
```

## Requesting a transaction

```tsx twoslash
// @noErrors
import { contractTransaction, sendTransaction } from 'frog/web'
import { erc20Abi } from 'viem'

export function ContractTransactionApp() {
return (
<button
onClick={() =>
contractTransaction({
abi: erc20Abi,
functionName: 'approve',
args: ['0x0000000000000000000000000000000000000000', 1n],
address: '0x0000000000000000000000000000000000000000'
})
}
>
contract tx
</button>
)
}

export function SendTransactionApp() {
return (
<button
onClick={() =>
sendTransaction({
to: '0x0000000000000000000000000000000000000000',
value: 1n
})
}
>
send tx
</button>
)
}
```

## Requesting a signature

```tsx twoslash
// @noErrors
import { signTypedData } from 'frog/web'

export function SignTypedDataApp() {
return (
<button
onClick={() =>
signTypedData({
chainId: 'eip155:84532',
types: {
Swamp: [{ name: 'frog', type: 'string' }],
},
primaryType: 'Swamp',
message: {
frog: 'Robert',
},
})
}
>
sign data
</button>
)
}
```
2 changes: 2 additions & 0 deletions site/pages/concepts/composer-actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ app.composerAction(
### Client-Side Helpers
Frog exports `createCast` helper to post the message to the `window.parent`.

Check other helpers [here](/concepts/client-side-helpers).

```tsx twoslash [src/index.tsx]
// @noErrors
import { createCast } from 'frog/web'
Expand Down
66 changes: 66 additions & 0 deletions site/pages/concepts/mini-apps.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Mini-Apps

Mini-Apps act the same as [Composer Actions](/concepts/composer-actions), with a difference
that such can be linked in a frame via deeplink.

## Overview

At a glance:

1. User sees a frame in the App client's feed or direct message.
2. The frame has a deeplink button that shows the Mini-App on click.

:::warning
Since Frog is not a Client-Side Framework, we recommend using a separate Frontend for the actual Mini-App.

If you want to keep both Frog and Mini-App in one project, we recommend starting with [Next.JS](/platforms/next).
:::

## Example

Here is a trivial example of how to expose a Mini-App with a frame. We will break it down below.

```tsx twoslash [src/index.tsx]
// @noErrors
/** @jsxImportSource hono/jsx */
// ---cut---
import { Frog, Button } from 'frog'

export const app = new Frog({ title: 'Frog Frame' })

app.frame((c) => {
return c.res({
image: '...',
intents: [<Button.MiniApp href="https://link-to-my-mini-app"/>]
})
})
```

You can also add `prompt` param to the props to hint the App Client to render the Mini-App without opening
it in full-scren in-app browser, but as a drawer.

### Client-Side Helpers
Frog exports various helper to post the message to the `window.parent`.

Check other helpers [here](/concepts/client-side-helpers).

```tsx twoslash [src/index.tsx]
// @noErrors
import { sendTransaction, contractTransaction, signTypedData } from 'frog/web'

function App() {
return (
<>
<button onClick={() => sendTransaction({/**/})}>
Send Tx
</button>
<button onClick={() => contractTransaction({/**/})}>
Contract Tx
</button>
<button onClick={() => signTypedData({/**/})}>
Sign typed data
</button>
</>
)
}
```
8 changes: 8 additions & 0 deletions site/vocs.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export default defineConfig({
text: 'Cast Actions',
link: '/concepts/cast-actions',
},
{
text: 'Client-Side Helpers',
link: '/concepts/client-side-helpers',
},
{
text: 'Composer Actions',
link: '/concepts/composer-actions',
Expand All @@ -161,6 +165,10 @@ export default defineConfig({
text: 'Multi-step Cast Actions',
link: '/concepts/multi-step-cast-actions',
},
{
text: 'Mini-Apps',
link: '/concepts/mini-apps',
},
{
text: 'Error Handling',
link: '/concepts/error-handling',
Expand Down
Loading