0

I have sent the following transactions to the account 0x2D76d8729F9Cfa5bC3CEba8a504400FE30bb53D2:

However, when I try to query the balance using the code below, I get a balance of 0

package main

import (
    "context"
    "fmt"
    "log"
    "github.com/joho/godotenv"
    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/ethclient"
)

var myenv map[string]string

const envLoc = ".env"

func loadEnv() {
    var err error
    if myenv, err = godotenv.Read(envLoc); err != nil {
        log.Printf("could not load env from %s: %v", envLoc, err)
    }
}

func main() {
    loadEnv()

    ctx := context.Background()

    client, err := ethclient.Dial("http://kovan.infura.io/v3/<!REDACTED>)
    if err != nil {
        log.Fatalf("could not connect to Ethereum gateway: %v\n", err)
    }
    defer client.Close()

    accountAddress := common.HexToAddress("0x2D76d8729F9Cfa5bC3CEba8a504400FE30bb53D2")
    balance, _ := client.BalanceAt(ctx, accountAddress, nil)
    fmt.Printf("Balance: %d\n", balance)
}

I would appreciate pointers as to what I am doing wrong

0

Infura doues not allow unencrypted HTTP requests. Should be https://kovan.infura.io/v3/....

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.