Skip to content

Instantly share code, notes, and snippets.

@joe-rlo
Created December 21, 2023 04:13
Show Gist options
  • Select an option

  • Save joe-rlo/fd3ae831ca990d8bc97fe27fdb3f51d6 to your computer and use it in GitHub Desktop.

Select an option

Save joe-rlo/fd3ae831ca990d8bc97fe27fdb3f51d6 to your computer and use it in GitHub Desktop.
Calculate whether someone has collected 5+ ShardDogs on separate days
function isFrequentUser(nftData) {
const uniqueDays = new Set();
nftData.forEach(nft => {
const date = convertTimestampToDate(nft.minted_timestamp);
uniqueDays.add(date);
});
return uniqueDays.size >= 5;
}
function convertTimestampToDate(timestamp) {
// Assuming the timestamp is in milliseconds
const date = new Date(timestamp);
return date.toISOString().split('T')[0]; // Converts to YYYY-MM-DD format
}
async function fetchNFTData(walletName) {
const graphqlQuery = {
query: `
query MyQuery {
mb_views_nft_tokens(
where: {owner: {_eq: "${walletName}"}, _and: {burned_timestamp: {_is_null: true}, last_transfer_timestamp: {_is_null: false}}, nft_contract: {id: {_eq: "mint.sharddog.near"}}}
) {
token_id
minted_timestamp
}
}`
};
const response = await fetch('https://graph.mintbase.xyz/mainnet', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'mb-api-key': 'anon' // Replace with your actual API key, if required
},
body: JSON.stringify(graphqlQuery)
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
const jsonResponse = await response.json();
return jsonResponse.data.mb_views_nft_tokens;
}
// Example usage
fetchNFTData("orangejoe.near").then(nftData => {
const result = isFrequentUser(nftData);
console.log('Is frequent user:', result);
}).catch(error => {
console.error('Error fetching NFT data:', error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment