Created
January 28, 2023 14:55
-
-
Save jwinterm/17b205ff852c008e5643e9fe37b4b31f to your computer and use it in GitHub Desktop.
Query MoonPlace Contract to Map Minted/Unminted Tiles
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 base64 | |
import json | |
import web3 | |
from PIL import Image | |
nova_provider = web3.Web3(web3.HTTPProvider('https://nova.arbitrum.io/rpc')) | |
chain_id = 42170 | |
moonplace_address = '0x934095513c1ff89592A4b8490e263da7a6a4CEAc' | |
with open('moonplace.json') as f: | |
abi = json.load(f) | |
moonplace = nova_provider.eth.contract(address=moonplace_address, abi=abi) | |
all_sold_blocks = moonplace.functions.getAllSoldBlocks().call() | |
print(base64.b64decode(moonplace.functions.tokenURI(all_sold_blocks[0]).call().split(',')[1])) | |
unminted_tiles = [] | |
minted_tiles = [] | |
def get_tile_data(): | |
for i in range(0,9999): | |
try: | |
uri_data = json.loads(base64.b64decode(moonplace.functions.tokenURI(i).call().split(',')[1])) | |
minted_tiles.append((i, uri_data['description'].split(':')[1], uri_data['image'])) | |
except: | |
if i > 999: | |
x = int(str(i)[2:]) | |
y = int(str(i)[0:2]) | |
elif i> 99: | |
x = int(str(i)[1:]) | |
y = int(str(i)[0]) | |
else: | |
x = i | |
y = 0 | |
unminted_tiles.append((i, (x,y), None)) | |
with open('minted_tiles.txt', 'w') as f: | |
for tile in minted_tiles: | |
f.write(str(tile) + '\n') | |
with open('unminted_tiles.txt', 'w') as f: | |
for tile in unminted_tiles: | |
f.write(str(tile) + '\n') | |
get_tile_data() | |
size = 100, 100 | |
outimg = Image.new('RGB', size, (255,255,255)) | |
with open('unminted_tiles.txt', 'r') as f: | |
tiles = f.readlines() | |
for tile in tiles: | |
x = int(tile.split(',')[1].split('(')[1].split(',')[0]) | |
y = int(tile.split(',')[2].split(')')[0]) | |
print(x,y) | |
outimg.putpixel((x,y), (0,0,0)) | |
outimg.save('moonplace.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment