-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-metadata-rocks.py
More file actions
76 lines (63 loc) · 2.43 KB
/
Copy pathget-metadata-rocks.py
File metadata and controls
76 lines (63 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import requests
import json
import hashlib
base_url = "https://api.ethscriptions.com/api/ethscriptions/exists/"
# Function to generate the data string
def generate_data_string(token_id):
data_string = f"data:,{{\"p\":\"erc-20\",\"op\":\"mint\",\"tick\":\"💯\",\"id\":\"{token_id}\",\"amt\":\"1\"}}"
return data_string.encode('utf-8')
# Function to check existence and create JSON output
def check_ethscriptions():
tokens_data = []
for token_id in range(1, 101):
encoded_data = generate_data_string(token_id)
hashed_value = hashlib.sha256(encoded_data).hexdigest()
url = base_url + hashed_value
print(f"Checking for rock #{token_id} at URL {url}...", end='')
response = requests.get(url)
if response.status_code == 200:
api_data = response.json()
ethscription_id = api_data.get('ethscription', {}).get('transaction_hash')
if ethscription_id:
print("FOUND!")
else:
print("Not Found :(")
token_data = {
"ethscription_id": ethscription_id,
"name": f"Rock #{token_id}",
"description": "",
"external_url": "",
"background_color": "",
"item_index": token_id - 1,
"item_attributes": [
{
"trait_type": "ID",
"value": token_id
}
]
}
tokens_data.append(token_data)
# Constructing the final JSON structure
final_json = {
"name": "Rocks",
"description": "One hundred rock emojis as ERC-20 tokens on Ethscriptions",
"total_supply": 100,
"logo_image_uri": "",
"banner_image_uri": "",
"background_color": "#C4FF00",
"twitter_link": "",
"website_link": "",
"discord_link": "",
"collection_items": tokens_data
}
return final_json
# Function to save JSON to a specified location
def save_json_to_file(json_data, file_path):
with open(file_path, 'w') as file:
json.dump(json_data, file, indent=4)
# Specifying the file path
file_location = "file path to where you want to save the metadata JSON"
# Calling the function and saving the output to the specified location
result = check_ethscriptions()
save_json_to_file(result, file_location)
print(f"JSON data saved to: {file_location}")