Skip to content

Commit

Permalink
Merge pull request #291 from SamuelLHuber/patch-1
Browse files Browse the repository at this point in the history
docs: connectedAddress tx docs
  • Loading branch information
stephancill authored Apr 5, 2024
2 parents ceb9cf7 + ffe9de1 commit 814b4ce
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-moons-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"docs": patch
---

fix: add connectedAddress docs
41 changes: 34 additions & 7 deletions docs/pages/guides/transactions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,39 @@ Frames can initiate transactions that apps that integrate Frames can complete, c
An example snippet can be found below.

```tsx
// ...
buttons: [
<Button action="tx" target="/txdata" post_url="/frames">
Buy a unit
</Button>
]
// ...
buttons: [
<Button action="tx" target="/txdata" post_url="/frames">
Buy a unit
</Button>,
];
```

Use the [Transactions starter](https://github.com/framesjs/frames.js/tree/main/examples/framesjs-starter/app/examples/new-api-transaction) as a template to build your transaction Frames.
Use the [Transactions starter](https://github.com/framesjs/frames.js/tree/main/examples/framesjs-starter/app/examples/new-api-transaction) as a template to build your transaction Frames.

## Using the connected wallet address

The client will include the user's connected wallet address that will be executing the transaction in the frame action payload in the when a frame button with `action="tx"` set is pressed.

The address is available in the context under the key `connectedAddress`.

Note:

- The address is only available when the user has connected a wallet to the client the frame button pressed is has a `tx` action.
- `connectedAddress` differs from the `requesterVerifiedAddresses` returned by the [`farcasterHubContext`](/middleware/farcasterHubContext) middleware.

```tsx [./app/frames/tx-data/route.tsx]
import { frames } from "../frames";

export const POST = frames(async (ctx) => {
if (!ctx.message) {
throw new Error("No message");
}

const userAddress = ctx.message.connectedAddress;

// Do something with the user's connected address that will be executing the tx

return txData;
});
```
8 changes: 6 additions & 2 deletions docs/pages/reference/js/getFrameMessage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Returns a `FrameActionData` object from the message trusted data, as well as `Fr
## Usage

```ts
import { frameMessage } from 'frames.js';
import { getFrameMessage } from 'frames.js';

const frameMessage = await getFrameMessage(frameActionPayload);
console.log(frameMessage);
Expand All @@ -16,6 +16,7 @@ console.log(frameMessage);
inputText: '',
requesterFid: 1689,
isValid: true,
connectedAddress: '0x8d25687829d6b85d9e0020b8c89e3ca24de20a89',
casterFollowsRequester: false,
requesterFollowsCaster: false,
likedCast: false,
Expand All @@ -42,7 +43,8 @@ console.log(frameMessage);
buttonIndex: 2,
castId: { fid: 1, hash: '0x0000000000000000000000000000000000000000' },
inputText: '',
requesterFid: 1689
requesterFid: 1689,
connectedAddress: '0x8d25687829d6b85d9e0020b8c89e3ca24de20a89'
}
**/
```
Expand All @@ -57,6 +59,8 @@ type FrameActionData = {
hash: `0x${string}`;
};
inputText?: string;
/** Only available in payloads of buttons with action `tx` **/
connectedAddress: string;
};
```

Expand Down

0 comments on commit 814b4ce

Please sign in to comment.