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"

up vote 0 down vote accepted

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.

  • sir, you are right. I replaced the params but still accounts.NewManager() is not accepting those params – Hafiz Atif Feb 16 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? – Richard Horrocks Feb 16 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 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 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. – Richard Horrocks Feb 16 at 14:34

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
  • thanks for your reply. But I want to create password protected account – Hafiz Atif Feb 16 at 14:17

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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