You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def get_balance(address):
"""Fetches the balance of a specified address."""
return token_contract.functions.balanceOf(address).call()
def calculate_circulating_supply():
"""Calculates the circulating supply of the token."""
excluded_balance = sum(get_balance(addr) for addr in EXCLUDED_ADDRESSES)
circulating_supply = TOTAL_SUPPLY - excluded_balance / (10**18) # Assuming 18 decimals
return circulating_supply
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
# Check if the request path is /circulating_supply
if self.path == '/circulating_supply':
try:
circulating_supply = calculate_circulating_supply()
response = {"result": circulating_supply}
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(json.dumps(response).encode())
except Exception as e:
# Send error response in case of failure
self.send_response(500)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(json.dumps({"error": str(e)}).encode())
else:
# Handle 404 Not Found for other paths
self.send_response(404)
self.end_headers()
self.wfile.write(b'{"error": "Endpoint not found"}')
def run(server_class=HTTPServer, handler_class=RequestHandler, port=8000):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print(f'Starting httpd server on port {port}...')
httpd.serve_forever()
if name == 'main':
run()
The text was updated successfully, but these errors were encountered:
from http.server import BaseHTTPRequestHandler, HTTPServer
import json
from web3 import Web3
Connect to the Base network
web3 = Web3(Web3.HTTPProvider('https://base.drpc.org'))
Convert token contract address to checksum format
TOKEN_CONTRACT_ADDRESS = web3.to_checksum_address('0xac27fa800955849d6d17cc8952ba9dd6eaa66187')
Convert excluded addresses to checksum format
EXCLUDED_ADDRESSES = [
web3.to_checksum_address('0x3074517c5F5428f42C74543C68001E0Ca86FE7dd'), # Unlock Protocol Foundation
web3.to_checksum_address('0x12be7322070cFA75E2f001C6B3d6Ac8C2efEF5Ea'), # Swapping Contract
web3.to_checksum_address('0xB34567C4cA697b39F72e1a8478f285329A98ed1b'), # DAO Timelock Contract
web3.to_checksum_address('0x9ef81f4e2f2f15ff1c0c3f8c9ecc636580025242') # Uniswap Pool
]
Total supply of the token
TOTAL_SUPPLY = 1_000_000_000
Minimum ABI for fetching balances from ERC-20 contract
ERC20_ABI = [
{
"constant": True,
"inputs": [{"name": "_owner", "type": "address"}],
"name": "balanceOf",
"outputs": [{"name": "balance", "type": "uint256"}],
"type": "function"
}
]
Instantiate the ERC-20 token contract
token_contract = web3.eth.contract(address=TOKEN_CONTRACT_ADDRESS, abi=ERC20_ABI)
def get_balance(address):
"""Fetches the balance of a specified address."""
return token_contract.functions.balanceOf(address).call()
def calculate_circulating_supply():
"""Calculates the circulating supply of the token."""
excluded_balance = sum(get_balance(addr) for addr in EXCLUDED_ADDRESSES)
circulating_supply = TOTAL_SUPPLY - excluded_balance / (10**18) # Assuming 18 decimals
return circulating_supply
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
# Check if the request path is /circulating_supply
if self.path == '/circulating_supply':
try:
circulating_supply = calculate_circulating_supply()
response = {"result": circulating_supply}
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(json.dumps(response).encode())
except Exception as e:
# Send error response in case of failure
self.send_response(500)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(json.dumps({"error": str(e)}).encode())
else:
# Handle 404 Not Found for other paths
self.send_response(404)
self.end_headers()
self.wfile.write(b'{"error": "Endpoint not found"}')
def run(server_class=HTTPServer, handler_class=RequestHandler, port=8000):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print(f'Starting httpd server on port {port}...')
httpd.serve_forever()
if name == 'main':
run()
The text was updated successfully, but these errors were encountered: