Created
January 25, 2023 14:48
-
-
Save JhonatanHern/61dbd5541146a23eb90dcc5bb59380f1 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
import { ImmutableX, Config, ListTransfersResponse } from '@imtbl/core-sdk'; | |
import { ethers } from 'ethers'; | |
const client = new ImmutableX(Config.PRODUCTION); | |
// fetch all of the transactions where an address has received a specific token | |
const listTransfersOfAssetPerUser = async (user: string, tokenId: string) => { | |
let results: any[] = [], | |
transactionResult: ListTransfersResponse | undefined; | |
do { | |
transactionResult = await client.listTransfers({ | |
receiver: user, | |
tokenType: 'ERC20', | |
assetId: tokenId, | |
cursor: transactionResult?.cursor | |
}); | |
results = results.concat(transactionResult?.result || []); | |
console.log(`length: ${results.length}`); | |
} while (transactionResult?.cursor); | |
return results; | |
} | |
const detectAuthenticTokens = async (verifiedMinter: string, user: string, tokenId: string) => { | |
const res = await listTransfersOfAssetPerUser(user, tokenId); | |
let authentic = ethers.BigNumber.from('0'), | |
inauthentic = ethers.BigNumber.from('0'); | |
for (const transfer of res) { | |
if (transfer.user === verifiedMinter) { | |
authentic = authentic.add(transfer.token.data.quantity); | |
} else { | |
inauthentic = inauthentic.add(transfer.token.data.quantity); | |
} | |
} | |
return [authentic, inauthentic] | |
} | |
const main = async () => { | |
const testData = { | |
user: '0xc1dbe29a513ce9a1f7509318d94bd1b18fd3e9d1', | |
verifiedMinter: '0xc2586d68fc53ef74fb9072ec3d16f844ea0ab37d', | |
tokenId: '0xccc8cb5229b0ac8069c51fd58367fd1e622afd97' | |
} | |
const [authentic, inauthentic] = await detectAuthenticTokens(testData.verifiedMinter, testData.user, testData.tokenId); | |
console.log("Authentic: ", authentic.toString()); | |
console.log("Inauthentic: ", inauthentic.toString()); | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment