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

Add wallet address executing the tx documentation #291

Merged
merged 4 commits into from
Apr 5, 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
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
Loading