We can use Go to access the Ethereum blockchain and identify the balance at a given address.
Ethereum Balance in Go |
Theory
package main import ( "fmt" "os" "context" "regexp" "math" "math/big" "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/common" ) func main() { addr:="0x5eD8Cee6b63b1c6AFce3AD7c92f4fD7E1B8fAd9F" argCount := len(os.Args[1:]) if (argCount>0) {addr = string(os.Args[1])} fmt.Printf("Balance of %s\n\n",addr) re := regexp.MustCompile("^0x[0-9a-fA-F]{40}$") fmt.Printf("Address is valid: %v\n", re.MatchString(addr)) client, _ := ethclient.Dial("https://mainnet.infura.io") account := common.HexToAddress(addr) balance, _ := client.BalanceAt(context.Background(), account, nil) ethBal := new(big.Float) ethBal.SetString(balance.String()) ethValue := new(big.Float).Quo(ethBal, big.NewFloat(math.Pow10(18))) fmt.Printf("Balance is %d Wei %f Eth\n",balance,ethValue) }
A sample run is:
Balance of 0x5eD8Cee6b63b1c6AFce3AD7c92f4fD7E1B8fAd9F Address is valid: true Balance is 920021309477024304476 Wei 920.021309 Eth