-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
52 lines (45 loc) · 1.5 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const NEYNAR_API_KEY = process.env.NEYNAR_API_KEY;
export async function validateFrameRequest(data: string | undefined) {
if (!NEYNAR_API_KEY) throw new Error("NEYNAR_API_KEY is not set");
if (!data) throw new Error("No data provided");
const options = {
method: "POST",
headers: {
accept: "application/json",
api_key: NEYNAR_API_KEY,
"content-type": "application/json",
},
body: JSON.stringify({
message_bytes_in_hex: data,
cast_reaction_context: true,
follow_context: true,
}),
};
return await fetch(
`${process.env.NEYNAR_HTTP_URL}/v2/farcaster/frame/validate`,
options
)
.then((response) => response.json())
.catch((err) => console.error(err));
}
export async function getUserInformation(viewerFid: number) {
if (!NEYNAR_API_KEY) throw new Error("NEYNAR_API_KEY is not set");
if (!viewerFid) throw new Error("No ViewerFid provided");
const myFid = 17979;
const options = {
method: "GET",
headers: {
accept: "application/json",
api_key: NEYNAR_API_KEY,
"content-type": "application/json",
},
};
return await fetch(
`${
process.env.NEYNAR_HTTP_URL
}/v1/farcaster/user?fid=${myFid.toString()}&viewerFid=${viewerFid.toString()}`,
options
)
.then((response) => response.json())
.catch((err) => console.error(err));
}