Skip to content

Instantly share code, notes, and snippets.

@neocho
Last active June 14, 2022 03:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neocho/f675e4955bddda29ded789faa9e86ee2 to your computer and use it in GitHub Desktop.
Save neocho/f675e4955bddda29ded789faa9e86ee2 to your computer and use it in GitHub Desktop.
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