Skip to content

Instantly share code, notes, and snippets.

@bustardcelly
Created April 8, 2021 11:29
Show Gist options
  • Save bustardcelly/73fc34a74446f460d03b6158e7cf1e33 to your computer and use it in GitHub Desktop.
Save bustardcelly/73fc34a74446f460d03b6158e7cf1e33 to your computer and use it in GitHub Desktop.
Access token ID of OBJKT
async function getTokenId (account, date) {
try {
let response = await fetch(`https://staging.api.tzkt.io/v1/accounts/${account}/operations?type=transaction`, { method: 'GET' })
let json = await response.json()
const filter = json.filter(t => {
if (t.type === 'transaction') {
if (t.timestamp.match(date)) {
if (t.parameter && t.parameter.entrypoint === 'mint') {
return t
}
}
}
return null
})
const map = filter.map(t => {
return t.parameter.value.token_id
})
return map.length > 0 ? map[0] : undefined
} catch (e) {
console.error(e)
}
}
getTokenId('tz1hhaDW6YghBcdCVWkUBu76HKWzD9d1tf2i', /2021-04-04/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment