Spaces:
No application file
No application file
Download src/common/alchemy.py from metasoccer/collab: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/metasoccer/collab/resolve/main/src/common/alchemy.py
- Command line
-
hf download hf://spaces/metasoccer/collab/src/common/alchemy.py
-
curl -L -o alchemy.py https://huggingface.co/spaces/metasoccer/collab/resolve/main/src/common/alchemy.py
1.07 kB
| import json | |
| import os | |
| from datetime import datetime | |
| import psycopg2 | |
| import requests | |
| from common.coingecko import get_token_usd_price | |
| from common.dbconn.retool import execute_query_with_args | |
| ALCHEMY_API_KEY = os.environ['ALCHEMY_API_KEY'] | |
| # Function to fetch ERC-20 token balances | |
| def get_erc20_balances(address): | |
| url = f"https://polygon-mainnet.g.alchemy.com/v2/{ALCHEMY_API_KEY}" | |
| headers = {'accept': 'application/json', 'content-type': 'application/json'} | |
| payload = json.dumps({ | |
| "id": 1, | |
| "jsonrpc": "2.0", | |
| "method": "alchemy_getTokenBalances", | |
| "params": [address, "erc20"] | |
| }) | |
| response = requests.post(url, headers=headers, data=payload) | |
| return response.json() | |
| # Function to fetch NFTs | |
| def get_nfts(address): | |
| url = f"https://polygon-mainnet.g.alchemy.com/nft/v3/{ALCHEMY_API_KEY}/getNFTsForOwner" | |
| params = {'owner': address, 'withMetadata': 'true', 'pageSize': 100} | |
| headers = {'accept': 'application/json'} | |
| response = requests.get(url, headers=headers, params=params) | |
| return response.json() |