Skip to content

Instantly share code, notes, and snippets.

@ethDreamer
Created February 23, 2024 02:39
Show Gist options
  • Save ethDreamer/938f35f01a1d45c7355864b0490ac1c5 to your computer and use it in GitHub Desktop.
Save ethDreamer/938f35f01a1d45c7355864b0490ac1c5 to your computer and use it in GitHub Desktop.
StarkNet Airdrop Claim
#!/usr/bin/env python3
import sys
import json
import os
def find_account_inclusion_object(eligibles, eth_address):
for account in eligibles:
if account["identity"].lower() == eth_address.lower():
return account
return None
def search_directory_for_account(dir_path, eth_address):
for filename in os.listdir(dir_path):
if filename.endswith('.json'):
file_path = os.path.join(dir_path, filename)
try:
with open(file_path, 'r') as file:
data = json.load(file)
account = find_account_inclusion_object(data.get("eligibles", []), eth_address)
if account:
return account, data["contract_address"]
except Exception as e:
print(f"Error reading {filename}: {e}")
return None, None
def main():
if len(sys.argv) != 4:
print("Usage: script.py <ethereum_address> <starknet_address> <directory_path>")
sys.exit(1)
ethereum_address = sys.argv[1]
starknet_address = sys.argv[2]
dir_path = sys.argv[3]
account, contract_address = search_directory_for_account(dir_path, ethereum_address)
if account is None:
print("Error: Ethereum address not found in any eligibles list.")
sys.exit(2)
print("Address found!")
print(json.dumps(account, indent=2))
print("\n")
eth_address = account["identity"]
balance = str(int(account["amount"]) * 10**18)
merkle_index = account["merkle_index"]
merkle_path_len = account["merkle_path_len"]
merkle_path = ', '.join(['"{}"'.format(path) for path in account["merkle_path"]])
# Format the output strings for toAddress, selector, and payload
toAddress = contract_address
selector = "0x00828430c65c40cba334d4723a4c5c02a62f612d73d564a1c7dc146f1d0053f9"
payload_string = f'"{eth_address}", "{balance}", "0", "{merkle_index}", "{merkle_path_len}", {merkle_path}, "{starknet_address}"'
print(f"toAddress: {toAddress}")
print(f"selector: {selector}")
print(f"Payload: {payload_string}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment