1

I'm running local ethereum node on my localhost on http://127.0.0.1:7545 (using ganache). I create a new account with keystore as below snippet. But, how can my local ethereum node can be aware of that new account? Normally, I can get balances, transactions etc... But I couldn't achieve to awareness of new account and managing them over my network via go-ethereum SDK.

func CreateAccount() {
    password := "secret"

    ks := keystore.NewKeyStore("./wallets", keystore.StandardScryptN, keystore.StandardScryptP)

    account, err := ks.NewAccount(password)

    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(account.Address.Hex())
}
jdev
  • 33
  • 3

1 Answers1

1

In order to make go-ethereum talk to your Ganache client, you need to call Dial, which accepts a provider URL. In the case described, that would be done as follows:

client, err := ethclient.Dial("http://localhost:7545")
if err != nil {
  log.Fatal(err)
}

So all together, you would have something like this along with what you are trying to accomplish in creating a new account and having Ganache see it:

func main() {
    client, err := ethclient.Dial("http://localhost:7545")
    if err != nil {
        log.fatal(err)
    }

    fmt.Println("we have a connection")
}

func CreateAccount() {
    ks := keystore.NewKeyStore("./wallets", keystore.StandardScryptN, keystore.StandardScryptP)
    password := "secret"
    account, err := ks.NewAccount(password)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(account.Address.Hex())
}

A really great reference for all things go-ethereum is https://goethereumbook.org which walks through this and more step-by-step with full code examples.

smacguffin
  • 11
  • 3
  • What issue are you facing, or you want a full procedure that should have been read from the documentation? – Aman Chourasiya Mar 17 '21 at 09:49
  • As I mentioned on my question; `I couldn't achieve to awareness of new account and managing them over my network via go-ethereum SDK` , So, I have already a connection method, but I couldn't see any awareness of new account on the network. That was the main point of the question. This keystore is created on only client side. – jdev Mar 22 '21 at 14:04