1

I want to create ethereum account using golang. I am following this guide but I am stuck with errors just at the beginning of code.

accountManager:=accounts.NewManager(".ethereum/rinkeby/keystore",accounts.StandardScryptN, accounts.StandardScryptP))

Error : Unresolved Reference "accounts.StandardScryptN" & "accounts.StandardScryptP"

3 Answers 3

1

I think the guide is out of date.

StandardScryptN and StandardScryptP are now in the keystore package, not the accounts package. You'll need to update your import accordingly.

5
  • sir, you are right. I replaced the params but still accounts.NewManager() is not accepting those params
    – Hafiz Atif
    Feb 16, 2018 at 13:36
  • Is the error the same? How are you importing the keystore package? Are you still importing the accounts package? Can you update your question with an MCV example of the code that's failing? Feb 16, 2018 at 13:43
  • Actually, accounts.NewManager() accept an Interface called "Backend" which is part of "accounts" package. Sir, the problem is I don't know how to use it
    – Hafiz Atif
    Feb 16, 2018 at 13:57
  • Sir, there are only two imports(accounts, keystore) and only one line of code which I have mentioned in my question
    – Hafiz Atif
    Feb 16, 2018 at 14:06
  • Okay, unsure what the issue is (without having a play around with it). If you don't explicitly need the Manager functionality, another option would just be to create a standalone keystore, as per the answer here. Feb 16, 2018 at 14:34
1

You can use the go-ethereum libraries to generate an account

import "github.com/ethereum/go-ethereum/crypto"
import "encoding/hex"

// Create an account
key, err := crypto.GenerateKey()

// Get the address
address := crypto.PubkeyToAddress(key.PublicKey).Hex()
// 0x8ee3333cDE801ceE9471ADf23370c48b011f82a6

// Get the private key
privateKey := hex.EncodeToString(key.D.Bytes())
// 05b14254a1d0c77a49eae3bdf080f926a2df17d8e2ebdf7af941ea001481e57f
1
  • thanks for your reply. But I want to create password protected account
    – Hafiz Atif
    Feb 16, 2018 at 14:17
0

If you have a private key hex string, you can recover the account by this:

package main

import (
    "fmt"
    "github.com/ethereum/go-ethereum/crypto"
)

func main() {
    // not started with 0x
    priKey := "0000000000000000000000000000000000000000000000000000000000000001"
    ecdsa, err := crypto.HexToECDSA(priKey)
    if err != nil {
        fmt.Println(err)
    }
    address := crypto.PubkeyToAddress(ecdsa.PublicKey).Hex()
    fmt.Println(address) //0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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