Skip to content

Instantly share code, notes, and snippets.

@robertcedwards
Forked from neocho/widget.js
Last active June 14, 2022 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertcedwards/352cb40f75a2e371165ec9da453e3c2f to your computer and use it in GitHub Desktop.
Save robertcedwards/352cb40f75a2e371165ec9da453e3c2f 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: "0x133a5b56017a9c8e0c02019ce985c449d71ddce6", tokenId: "257"}}
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