I am using ganache which creates an ethereum blockchain with 10 accounts.

enter image description here

The blockchain created by ganache is linked with truffle's pet-shop box using web3. I want to add a new account in that blockchain. I used web3.eth.accounts.create() which returns public and private key of the newly created account.

truffle(development)> web3.eth.accounts.create()

{ address: '0x53811349479671B8230BD853184AFf1e589f5A07',
  signTransaction: [Function: signTransaction],
  sign: [Function: sign],
  encrypt: [Function: encrypt] }

But the new account doesn't appear in the ganache. I also used web3.eth.getAccounts() to show all the accounts in the blockchain but I didn't get the new account.

truffle(development)> web3.eth.getAccounts()

[ '0x7771248F9Df904f5Ee684D325E9a2B4d7A413bA0',
  '0xb037075B163a6d3772AA8a401FC8A1361b970c43' ]

I can use the new account by using its private key. But where the new account is created? How I will know that the new account is part of ethereum blockchain or not which is created by ganache?

2 Answers 2


Ganache doesn't sync with the new accounts you generate.

Ganache gets you started with 10 accounts to choose from.

Why don't you just use one of them?

  • My evaluator gave me a task to create a new account in the current blockchain. Commented Aug 28, 2019 at 4:46
  • Ok in case the other answer didn't help you as well you are best off asking in the official group here: gitter.im/ConsenSys/truffle
    – cqx
    Commented Aug 28, 2019 at 6:01
  • i asked there also Commented Sep 3, 2019 at 6:20

When you start ganache it creates you 10 accounts by default, pre-funds it with 100 ETH per account and groups those 10 accounts in a Object (let's call this accounts array because it looks similar to an array :p)

When you run the command web3.eth.accounts.create() , you are creating a new account part of the same ganache network (of course same blockchain) but it not part of the initial accounts array that ganache gave you when you started the network. So it is not pre funded (But hey, for all testing purposes 1000 ETH is way too generous)

But if you want to group all your accounts for your use case, run these commands in your truffle console:

truffle(development)> accountsArray = await web3.eth.getAccounts() // you are getting 10 pre-funded accounts

truffle(development)> newAccount = web3.eth.accounts.create() //creating a new account

truffle(development)> accountsArray.push(newAccount.address) //adding your new account to the accounts array

truffle(development)> accountsArray //you can now see your new account in this list

I hope this answer gives you a general understanding of what happens in the background :)

  • push() function was not working for me. The method above will only put publick key in the accountsArray but i want to link my new account with actual blockchain. Commented Sep 3, 2019 at 6:11
  • I would like to know what error msg you get while executing push function. And yes, this will only add new account to the array. I do not understand what you mean by linking because the new account is part of actual blockchain. Commented Sep 3, 2019 at 18:35
  • sorry, the push is not giving any error now. Commented Sep 4, 2019 at 12:07
  • I want to add the new account in the accounts created by ganache so that whenever I write web3.eth.getAccounts() it should show me public key of 10 accounts created by ganache + the public key of new account. The above answer is only creating a copy of public keys of these11 accounts in accountsArray Commented Sep 4, 2019 at 12:16

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.