×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles

    Etherscan is an Ethereum block explorer (https://etherscan.io/)

    Here is some Python code to get the balance from an ETH address using their API.

    # get balance of a wallet from Etherscan
    # parameter: <ETH wallet address>
    def eth_balance(address):
        api_url="https://api.etherscan.io/api?module=account&action=balance&tag=latest&apikey=YourApiKeyToken&address="
        fetch_url=api_url+address
        try:
            req = requests.get(fetch_url)
            req.raise_for_status()
        except Exception as err:
            print('failed to talk to Etherscan - {0} - {1}'.format(err.message, err.args))
            sys.exit(2)
        try:
            resp = req.json()
        except Exception as err:
            print('failed to parse JSON - {0} - {1}'.format(err.message, err.args))
            sys.exit(2)
        rawbalance = resp['result']
        balance=round((int(rawbalance)/1000000000000000000),2)
        return balance
    
    
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.