Created
December 18, 2021 22:13
-
-
Save joshwolff1/b2b704e3623ff63162472d03e4c1c191 to your computer and use it in GitHub Desktop.
Search candy machines
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 requests | |
SEARCH_CANDY_MACHINES_ENDPOINT = "https://api.theblockchainapi.com/v1/solana/nft/candy_machine/search" | |
def get_headers(api_key_id, secret_key): | |
headers = dict() | |
if secret_key: | |
headers["APISecretKey"] = secret_key | |
if api_key_id: | |
headers["APIKeyId"] = api_key_id | |
headers['Language'] = 'Python' | |
return headers | |
def search_candy_machines( | |
update_authority=None, | |
update_authority_search_method=None, | |
config_address=None, | |
config_address_search_method=None, | |
uuid=None, | |
uuid_search_method=None, | |
symbol=None, | |
symbol_search_method=None, | |
nft_name=None, | |
nft_name_index=None, | |
nft_name_search_method=None, | |
network=None | |
): | |
params = dict() | |
if update_authority is not None: | |
params['update_authority'] = update_authority | |
if update_authority_search_method is not None: | |
params['update_authority_search_method'] = update_authority_search_method | |
if config_address is not None: | |
params['config_address'] = config_address | |
if config_address_search_method is not None: | |
params['config_address_search_method'] = config_address_search_method | |
if uuid is not None: | |
params['uuid'] = uuid | |
if uuid_search_method is not None: | |
params['uuid_search_method'] = uuid_search_method | |
if symbol is not None: | |
params['symbol'] = symbol | |
if symbol_search_method is not None: | |
params['symbol_search_method'] = symbol_search_method | |
if nft_name is not None: | |
params['nft_name'] = nft_name | |
if nft_name_index is not None: | |
params['nft_index'] = nft_name_index | |
if nft_name_search_method is not None: | |
params['nft_name_search_method'] = nft_name_search_method | |
if network is not None: | |
params['network'] = network | |
start = int(time.time()) | |
response = requests.post( | |
SEARCH_CANDY_MACHINES_ENDPOINT, | |
params=params, | |
# TODO: ------------------------------------------------------------------------------------ | |
headers=get_headers("FILL IN API KEY ID", "FILL API KEY SECRET") | |
) | |
end = int(time.time()) | |
print("-" * 50) | |
print(f"Params {params}") | |
print(f"Status Code: {response.status_code}") | |
candies = response.json() | |
print(f"Time Taken: {end - start}") | |
for candy_machine_id in candies: | |
print(candy_machine_id) | |
if 'error_message' in candies: | |
print(f"Error Message: {candies['error_message']}") | |
else: | |
print(f"Candy Machines Found: {len(candies)}") | |
print("-" * 50) | |
if __name__ == '__main__': | |
search_candy_machines( | |
nft_name="Elon", | |
nft_name_index=44, | |
nft_name_search_method='begins_with', | |
network='mainnet-beta' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment