getFrameMessage
Returns a FrameActionData
object from the message trusted data, as well as FrameActionHubContext
when fetchHubContext
option is not opted out of
Usage
import { getFrameMessage } from 'frames.js';
const frameMessage = await getFrameMessage(frameActionPayload);
console.log(frameMessage);
/**
{
buttonIndex: 2,
castId: { fid: 1, hash: '0x0000000000000000000000000000000000000000' },
inputText: '',
requesterFid: 1689,
isValid: true,
address: '0x8d25687829d6b85d9e0020b8c89e3ca24de20a89',
casterFollowsRequester: false,
requesterFollowsCaster: false,
likedCast: false,
recastedCast: false,
requesterVerifiedAddresses: [ '0x8d25687829d6b85d9e0020b8c89e3ca24de20a89' ],
requesterCustodyAddress: '0x2738B21cB9520338F9A375c3b971B1778ae1004a',
requesterUserData: {
profileImage: 'https://lh3.googleusercontent.com/-S5cdhOpZtJ_Qzg9iPWELEsRTkIsZ7qGYmVlwEORgFB00WWAtZGefRnS4Bjcz5ah40WVOOWeYfU5pP9Eekikb3cLMW2mZQOMQHlWhg',
displayName: 'David Furlong',
username: 'df',
bio: 'Building open source software for /frames, to help Farcaster and decentralized social win'
}
}
**/
import { frameMessage } from 'frames.js';
// skip a hub roundtrip by opting out of fetching the hub context
const frameMessage = await getFrameMessage(frameActionPayload, { fetchHubContext: false });
console.log(frameMessage);
/**
{
buttonIndex: 2,
castId: { fid: 1, hash: '0x0000000000000000000000000000000000000000' },
inputText: '',
requesterFid: 1689,
address: '0x8d25687829d6b85d9e0020b8c89e3ca24de20a89'
}
**/
type FrameActionData = {
buttonIndex: number;
requesterFid: number;
castId?: {
fid: number;
hash: `0x${string}`;
};
inputText?: string;
/** Only available in payloads of buttons with action `tx` **/
address: string;
};
If the fetchHubContext
option is enabled, it will also validate the message and fetch additional context of type FrameActionHubContext
from a Farcaster Hub.
type FrameActionHubContext = {
isValid: boolean;
requesterFollowsCaster: boolean;
casterFollowsRequester: boolean;
likedCast: boolean;
recastedCast: boolean;
requesterVerifiedAddresses: string[];
requesterCustodyAddress: string;
};