Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 0ced4f7

Browse files
authored
chore: docs mini-apps, helpers (#512)
1 parent edd1199 commit 0ced4f7

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Client-Side Helpers
2+
3+
As you may know, Frog was initially built as a backend-only library.
4+
With the recent features in Farcaster, Composer Actions and Mini Apps were introduced.
5+
6+
To keep up with the changes, Frog adds helpers for your web application to communicate with the parent iFrame.
7+
8+
[See the spec](https://warpcast.notion.site/Miniapp-Transactions-1216a6c0c10180b7b9f4eec58ec51e55)
9+
10+
## Creating a Cast (Composer Actions)
11+
12+
```tsx twoslash
13+
// @noErrors
14+
import { createCast } from 'frog/web'
15+
16+
export function App() {
17+
return (
18+
<button
19+
onClick={() =>
20+
createCast({
21+
text: 'Hi!',
22+
embeds: []
23+
})
24+
}
25+
>
26+
create cast
27+
</button>
28+
)
29+
}
30+
```
31+
32+
## Requesting a transaction
33+
34+
```tsx twoslash
35+
// @noErrors
36+
import { contractTransaction, sendTransaction } from 'frog/web'
37+
import { erc20Abi } from 'viem'
38+
39+
export function ContractTransactionApp() {
40+
return (
41+
<button
42+
onClick={() =>
43+
contractTransaction({
44+
abi: erc20Abi,
45+
functionName: 'approve',
46+
args: ['0x0000000000000000000000000000000000000000', 1n],
47+
address: '0x0000000000000000000000000000000000000000'
48+
})
49+
}
50+
>
51+
contract tx
52+
</button>
53+
)
54+
}
55+
56+
export function SendTransactionApp() {
57+
return (
58+
<button
59+
onClick={() =>
60+
sendTransaction({
61+
to: '0x0000000000000000000000000000000000000000',
62+
value: 1n
63+
})
64+
}
65+
>
66+
send tx
67+
</button>
68+
)
69+
}
70+
```
71+
72+
## Requesting a signature
73+
74+
```tsx twoslash
75+
// @noErrors
76+
import { signTypedData } from 'frog/web'
77+
78+
export function SignTypedDataApp() {
79+
return (
80+
<button
81+
onClick={() =>
82+
signTypedData({
83+
chainId: 'eip155:84532',
84+
types: {
85+
Swamp: [{ name: 'frog', type: 'string' }],
86+
},
87+
primaryType: 'Swamp',
88+
message: {
89+
frog: 'Robert',
90+
},
91+
})
92+
}
93+
>
94+
sign data
95+
</button>
96+
)
97+
}
98+
```

site/pages/concepts/composer-actions.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ app.composerAction(
5454
### Client-Side Helpers
5555
Frog exports `createCast` helper to post the message to the `window.parent`.
5656

57+
Check other helpers [here](/concepts/client-side-helpers).
58+
5759
```tsx twoslash [src/index.tsx]
5860
// @noErrors
5961
import { createCast } from 'frog/web'

site/pages/concepts/mini-apps.mdx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Mini-Apps
2+
3+
Mini-Apps act the same as [Composer Actions](/concepts/composer-actions), with a difference
4+
that such can be linked in a frame via deeplink.
5+
6+
## Overview
7+
8+
At a glance:
9+
10+
1. User sees a frame in the App client's feed or direct message.
11+
2. The frame has a deeplink button that shows the Mini-App on click.
12+
13+
:::warning
14+
Since Frog is not a Client-Side Framework, we recommend using a separate Frontend for the actual Mini-App.
15+
16+
If you want to keep both Frog and Mini-App in one project, we recommend starting with [Next.JS](/platforms/next).
17+
:::
18+
19+
## Example
20+
21+
Here is a trivial example of how to expose a Mini-App with a frame. We will break it down below.
22+
23+
```tsx twoslash [src/index.tsx]
24+
// @noErrors
25+
/** @jsxImportSource hono/jsx */
26+
// ---cut---
27+
import { Frog, Button } from 'frog'
28+
29+
export const app = new Frog({ title: 'Frog Frame' })
30+
31+
app.frame((c) => {
32+
return c.res({
33+
image: '...',
34+
intents: [<Button.MiniApp href="https://link-to-my-mini-app"/>]
35+
})
36+
})
37+
```
38+
39+
You can also add `prompt` param to the props to hint the App Client to render the Mini-App without opening
40+
it in full-scren in-app browser, but as a drawer.
41+
42+
### Client-Side Helpers
43+
Frog exports various helper to post the message to the `window.parent`.
44+
45+
Check other helpers [here](/concepts/client-side-helpers).
46+
47+
```tsx twoslash [src/index.tsx]
48+
// @noErrors
49+
import { sendTransaction, contractTransaction, signTypedData } from 'frog/web'
50+
51+
function App() {
52+
return (
53+
<>
54+
<button onClick={() => sendTransaction({/**/})}>
55+
Send Tx
56+
</button>
57+
<button onClick={() => contractTransaction({/**/})}>
58+
Contract Tx
59+
</button>
60+
<button onClick={() => signTypedData({/**/})}>
61+
Sign typed data
62+
</button>
63+
</>
64+
)
65+
}
66+
```

site/vocs.config.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ export default defineConfig({
153153
text: 'Cast Actions',
154154
link: '/concepts/cast-actions',
155155
},
156+
{
157+
text: 'Client-Side Helpers',
158+
link: '/concepts/client-side-helpers',
159+
},
156160
{
157161
text: 'Composer Actions',
158162
link: '/concepts/composer-actions',
@@ -161,6 +165,10 @@ export default defineConfig({
161165
text: 'Multi-step Cast Actions',
162166
link: '/concepts/multi-step-cast-actions',
163167
},
168+
{
169+
text: 'Mini-Apps',
170+
link: '/concepts/mini-apps',
171+
},
164172
{
165173
text: 'Error Handling',
166174
link: '/concepts/error-handling',

0 commit comments

Comments
 (0)