Skip to content

Instantly share code, notes, and snippets.

@azhang
Last active September 4, 2021 04:42
Show Gist options
  • Save azhang/ee62f7389c51d33fe80177c0e0ba2dde to your computer and use it in GitHub Desktop.
Save azhang/ee62f7389c51d33fe80177c0e0ba2dde to your computer and use it in GitHub Desktop.
get rock owners πŸ˜‚
// run this in inspector
var howMany = 1000
const ABI = JSON.parse('[{"constant":false,"inputs":[{"name":"rockNumber","type":"uint256"},{"name":"receiver","type":"address"}],"name":"giftRock","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"rockOwners","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"rockNumber","type":"uint256"}],"name":"dontSellRock","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"rockNumber","type":"uint256"}],"name":"buyRock","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"rocks","outputs":[{"name":"owner","type":"address"},{"name":"currentlyForSale","type":"bool"},{"name":"price","type":"uint256"},{"name":"timesSold","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"rockNumber","type":"uint256"}],"name":"getRockInfo","outputs":[{"name":"","type":"address"},{"name":"","type":"bool"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_address","type":"address"}],"name":"rockOwningHistory","outputs":[{"name":"","type":"uint256[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"latestNewRockForSale","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"rockNumber","type":"uint256"},{"name":"price","type":"uint256"}],"name":"sellRock","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"}]')
const contractAddress = '0x37504ae0282f5f334ed29b4548646f887977b7cc'
var RocksContract = web3.eth.contract(ABI)
var Rocks = RocksContract.at(contractAddress)
var data = new Array(howMany).fill(0);
for (let i in data) {
Rocks.rocks(i, (err, res) => {data[i] = res[0] })
}
// wait til the above is done running then use this to print indices of available rocks
console.log(data.map((e, i) => !e ? i : '').filter(String))
@azhang
Copy link
Author

azhang commented Aug 30, 2021

might hit the rate limiter which will show you some invalid results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment