Skip to main content
Share Your Experience: Take the 2024 Developer Survey
192 votes
Accepted

How are ethereum addresses generated?

Recently this article came to my attention that is way more in depth and technical than my more accessible version below. It also walks you through how to generate one on your own. I highly recommend ...
tayvano's user avatar
  • 16k
70 votes
Accepted

Get public key of any ethereum account

You can if and only if a transaction has been sent from the account. When you send a tx, you sign the transaction and it includes these v r and s values. You parse these from the signed tx and then ...
tayvano's user avatar
  • 16k
56 votes
Accepted

ecrecover from Geth and web3.eth.sign

I was stuck on this issue as well for a very long time. So the solution is: Add this prefix string to your Solidity smart contract. function verify(bytes32 hash, uint8 v, bytes32 r, bytes32 s) ...
Adil Haris's user avatar
49 votes
Accepted

What does v, r, s in eth_getTransactionByHash mean?

v, r, s are the values for the transaction's signature. They can be used as in Get public key of any ethereum account A little more information, r and s are outputs of an ECDSA signature, and v is ...
eth's user avatar
  • 85.9k
46 votes
Accepted

How to encrypt a message with the public-key of an Ethereum address

thx @Edmunx Edgar, i tried to use ECIES, but it failed to install because of a subdepencency. I now used the bitcore-lib together with bitcore-ecies. This works like expected. EDIT: I created a npm-...
pubkey's user avatar
  • 1,157
31 votes
Accepted

How can I get a mnemonic phrase from a private key?

No, a mnemonic is generated using an hd wallet - a hierarchical deterministic wallet. Private keys are "children" of this mnemonic and there can be millions of them, but there's no way to go back to ...
Paul Razvan Berg's user avatar
25 votes
Accepted

How to set private key for Ethers Signer

You could simply replace the 2nd line in your code above and instead define the signer as follows: const signer = new ethers.Wallet(your_private_key_string, provider); You could also define a signer ...
Ahmed Ihsan Tawfeeq's user avatar
23 votes

Which cryptographic hash function does Ethereum use?

To make it clearer that Ethereum uses KECCAK-256 instead of the NIST standardized SHA-3 hash function, Solidity 0.4.3 has introduced keccak256. (It is an alias to sha3, meaning that keccak256 ...
eth's user avatar
  • 85.9k
18 votes

Why aren't Solidity sha3 hashes not matching what other sha3 libraries produce?

Extending on this answer: Ethereum uses Keccak hashing, which was submitted to the NIST competition for SHA3. It was subsequently selected as a winner in 2012, but the final standard was only ...
axic's user avatar
  • 2,569
18 votes

Account uniqueness guaranteed?

Ethereum addresses are 160 bit hashes, meaning there are 2^160 possible hashes. Per the birthday problem, the chance of a collision rises to 50% when there are about 2^80 accounts created. To give ...
Nick Johnson's user avatar
  • 8,174
17 votes

Get public key of any ethereum account

It is now possible to recover public key from Ethereum transaction without any coding: Open the transaction in Etherscan.io Click on vertical ellipsis in the top-right corner Click on "Get Raw ...
Mikhail Vladimirov's user avatar
16 votes

How are ethereum addresses generated?

Private Key Space: Here are some code examples, based on the elliptic curve secp256k1 used by ethereum, as others have noted in order for the 256-bit key to be valid, it must be smaller than the ...
Steven Hatzakis's user avatar
16 votes
Accepted

How can I verify a signature with the web3 javascript API?

web3 does not support this feature yet, but it might be coming with web3 1.0. In the meantime you can use ethereumjs-utils ecrecover feature. Note that this function expects v to be in {27, 28}, and ...
MrChico's user avatar
  • 1,786
15 votes

ecrecover from Geth and web3.eth.sign

According to issue #3731: Geth prepends the string \x19Ethereum Signed Message:\n<length of message> to all data before signing it (https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign). ...
Miguel Mota's user avatar
  • 5,163
14 votes

What's a precompiled contract and how are they different from native opcodes?

Not an authority, but I know of someone who is... From Vitalik's article, A Prehistory of the Ethereum Protocol The second was the idea of “precompiles”, solving the problem of allowing complex ...
benjaminion's user avatar
  • 9,297
14 votes

Get public key of any ethereum account

I don't think this is possible, since you lose information when going from public key to address: Start with the public key (64 bytes) Take the Keccak-256 hash of the public key. You should ...
Olmo Ziarko's user avatar
13 votes
Accepted

Getting an address from ethereumjs-utils ecrecover

ecrecover returns public key, you need to convert it to address with pubToAddress. pub = ethJsUtil.ecrecover(msg, v, r, s); addrBuf = ethJsUtil.pubToAddress(pub); addr = ethJsUtil.bufferToHex(...
max taldykin's user avatar
  • 2,966
13 votes
Accepted

Why are Ethereum addresses hashes of public keys?

Indeed, ethereum's address reuse renders the "protection against an ecc public key attack" argument null. For externally owned accounts, using the public key directly would likely not result in any ...
Raghav Sood's user avatar
  • 4,050
12 votes

How to encrypt a message with the public-key of an Ethereum address

Assuming you have the public key of the person you want to send a message to (if they've already signed a transaction you can recover it from the signature) it should be possible to encrypt and ...
Edmund Edgar's user avatar
  • 16.9k
12 votes
Accepted

Getting the wrong address back from ecrecover

Geth adds prefix to the message before siginig it in web3.eth.sign (see JSON-PRC spec). Without this it can be possible to trick user to sign transaction (more here). So, the correct code to sign ...
max taldykin's user avatar
  • 2,966
11 votes

How are ethereum addresses generated?

Ethereum addresses are hashes of a public key. So to generate one you have to generate a private key first (see: What is the approach to calculate an Ethereum address from a 256 bit private key?) The ...
Nicolas Massart's user avatar
11 votes
Accepted

arguments of the sha256 function in Solidity

Solidity docs say that sha256 (and sha3, ripemd160) arguments are tightly packed: “tightly packed” means that the arguments are concatenated without padding. This means that the following are all ...
eth's user avatar
  • 85.9k
11 votes

Would it be profitable enough to do a Master's degree in blockchain technologies (focused on ethereum above all)?

A blockchain masters, as of now, would only be worth your time and money if it's from a school with a lot of time under it's belt working on bitcoin(It's been around longer) or taught by Nick Szabo. ...
Vignesh Karthikeyan's user avatar
10 votes

Out of Gas invoking precompiled contracts on private blockchains

There is a general gas cost rule that states that sending message to any non-existing account costs more than sending message to an existing account. That also applies to the accounts of the ...
Paweł Bylica's user avatar
9 votes
Accepted

Does Ethereum Suffer From Transaction Malleability?

No it does not suffer from malleability (anymore). The homestead hardfork included the malleability fix and transactions that have their signature in the upper range of secp256k1n/2 are rejected.
Jeffrey W.'s user avatar
  • 1,939
9 votes
Accepted

What are zkSNARKs? How do they work?

I'll not enter on crypto hard details, because I don't know that much about it, and it needs pages and pages to be explained correctly. But let's try it!!! ZKSnarks also known as: Zero Knowledge ...
CPereez19's user avatar
  • 2,835
8 votes

How does the system enforce correct execution of smart contracts?

Every full node will run the same contract with the same input (with the goal of checking the output). So, when a miner runs a contract and notes its execution in a published block, every full ...
Slender's user avatar
  • 141
8 votes
Accepted

Account uniqueness guaranteed?

Quoting Chris613 on ethereum forum about cpp ethereum : A 256-bit Private Key is initialized with random data The secret is tested for being an acceptable key, which just means non-zero and ...
Nicolas Massart's user avatar
8 votes

How to calculate an Ethereum Contract's address during its creation using the Solidity language?

The most optimized version: function addressFrom(address _origin, uint _nonce) public pure returns (address) { bytes memory data; if (_nonce == 0x00) data = abi.encodePacked(byte(0xd6)...
k06a's user avatar
  • 3,036
8 votes
Accepted

How to get the zero address from ecrecover?

I stumbled upon this thread, then I discovered this document and I now understand that setting v as any (positive?) number other than 27 or 28 will deterministically return 0x0 as the origin signer ...
Paul Razvan Berg's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible