forked from Phala-Network/phat-function-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
43 lines (42 loc) · 1.23 KB
/
index.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
import '@phala/pink-env'
export default function main() {
/*
You may need to call multiple APIs at once,
this would require you to use the `pink.batchHttpRequest()` function to ensure
you do not timeout (timeouts for Phat Contract is 10 seconds) on your response.
The `args` and returned `Object` are the same as `pink.httpRequest()`,
but instead you can create an array of HTTP requests within the function.
*/
const responses = pink.batchHttpRequest([
{
url: 'https://httpbin.org/ip',
method: 'GET',
returnTextBody: true,
},
{
url: 'https://api-mumbai.lens.dev/',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'phat-contract',
},
body: JSON.stringify({
query: `query Profile {
profile(request: { profileId: "0x01" }) {
stats {
totalFollowers
totalFollowing
totalPosts
totalComments
totalMirrors
totalPublications
totalCollects
}
}
}`
}),
returnTextBody: true,
}
])
return responses[0].body
}