Last active
March 24, 2022 13:34
-
-
Save fdemiramon/ea19be165b86d9b815d69d5d4766d49a to your computer and use it in GitHub Desktop.
Check user's balance (can only be 1 or 0)
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
// npm install web3 | |
// get the ABI of the contract (https://mumbai.polygonscan.com/address/0xe9239a8324ee9144e6f1af0cab81a5a8d8274551#code) | |
// store it in ./abis/serieAToken.json | |
// run `node index` | |
const Web3 = require('web3') | |
const fs = require('fs'); | |
const SerieATokenAbi = JSON.parse(fs.readFileSync('./abis/serieAToken.json')); | |
const web3 = new Web3('https://polygon-mumbai.infura.io/v3/8d675eea201c403e9837891cf0d36a3c'); | |
const contractInstance = new web3.eth.Contract(SerieATokenAbi, '0xe9239a8324ee9144e6f1af0cab81a5a8d8274551'); | |
function getBalance(userAddress) { | |
contractInstance.methods.balanceOf(userAddress).call((err, result) => { | |
if (err || result > 1){ | |
console.log(err) | |
} else { | |
console.log(userAddress + ' => ' + (result == 1 ? 'YES' : 'NO')); | |
} | |
}) | |
} | |
const addressesToCheck = [ | |
'0xd6140a3c3020454aAD17b6dB7B4f3F09952cBaa0', | |
'0x50f6c98bfd04bead3c529d8fb5c81241072cc00e', | |
'0x0ce538a6f7ce0473383b15d06a3f2220d51e494a', | |
'0x54354b7f53ee4c8091047e87bb37da93051d672a' | |
] | |
addressesToCheck.map(getBalance) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment