I am trying to use this function in order to create keypairs for users via frontend, and these pairs are associated with username and password.

However, I noticed, that this:

var account = new Web3EthAccounts('ws://localhost:8545');


works always, no matter if on that port something is running or not. And for that reason I am not so sure anymore, if the web3.eth.accounts-library is even interacting with my running blockchain. I also am not even sure anymore if thats even necessary, or if the keypair just doesn't need that connection.


If you take a look at the create function, it's simply generating a string of random bytes.

// web3-eth-accounts
Accounts.prototype.create = function create(entropy) {
    return this._addAccountFunctions(Account.create(entropy || utils.randomHex(32)));

// eth-lib/lib/account
var create = function create(entropy) {
  var innerHex = keccak256(Bytes.concat(Bytes.random(32), entropy || Bytes.random(32)));
  var middleHex = Bytes.concat(Bytes.concat(Bytes.random(32), innerHex), Bytes.random(32));
  var outerHex = keccak256(middleHex);
  return fromPrivate(outerHex);

It's kind of like if every atom in the universe was a private key you can use, and you're simply picking a random one. The chances of someone randomly picking the same one is close to 0%.


There's no need to be connected to anything to generate a key pair. It's essentially just generating a random number.


As mentioned here above, the private key is generated completely randomly, without checking for a "collision" with any other key online.

However, A public ethereum address has 160 bits (derived by a hash of a longer key). Therefore the odds of generating a double address in a certain attempt is 1 to 2^160, which is very, very close to 0%.

Here is a detailed explanation i found on why there are around 10 addresses for every cubic micrometer of the sun :)


for more info on how those keys are generated you can look here:

How are ethereum addresses generated?

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.