Last active
June 14, 2022 03:25
-
-
Save neocho/f675e4955bddda29ded789faa9e86ee2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let widget = await createWidget() | |
if (config.runsInWidget) { | |
Script.setWidget(widget) | |
} else { | |
widget.presentMedium() | |
} | |
Script.complete() | |
async function createWidget() { | |
const nftImage = await getImageData(); | |
let widget = new ListWidget(); | |
widget.backgroundImage = await loadImage(nftImage); | |
return widget | |
} | |
async function getImageData() { | |
let url = 'https://api.zora.co/graphql'; | |
const req = new Request(url); | |
req.method = "POST" | |
req.body = JSON.stringify({ | |
query: ` | |
query Tokens { | |
tokens( | |
where: { tokens: {address: "0x8d04a8c79ceb0889bdd12acdf3fa9d207ed3ff63", tokenId: "393"}} | |
pagination: {limit: 1} | |
) { | |
nodes { | |
token { | |
name | |
image { | |
url | |
} | |
} | |
} | |
} | |
}` | |
}) | |
req.headers = {"Content-Type":"application/json"} | |
const res = await req.loadJSON(); | |
const data = res.data.tokens.nodes[0] | |
const imageData = data.token.image.url | |
return imageData; | |
} | |
async function loadImage(imageUrl) { | |
let req = new Request(imageUrl) | |
let image = await req.loadImage() | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment