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
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.7k
28 votes
Accepted

Create and sign OFFLINE raw transactions?

ethereumjs-tx is a library with this example: npm install ethereumjs-tx const Tx = require('ethereumjs-tx').Transaction var privateKey = new Buffer('...
eth's user avatar
  • 85.7k
27 votes

workflow on signing a string with private key, followed by signature verification with public key

I was having the same problem earlier, so I am going to give an extensive answer to how this works. I assume you are using geth as a client. There is an open issue where the geth client returns v in ...
MrChico's user avatar
  • 1,786
24 votes
Accepted

Invalid sender error on private chain

The issue was that the chain id was not being set correctly. As a result transactions were signed with the incorrect chain id, so the sender could not be derived correctly. The fix was to also declare ...
thanos's user avatar
  • 844
24 votes
Accepted

How do you sign an verify a message in javascript proving you own an Ethereum address?

You can sign a string of data using web3.eth.sign The address you use needs to be unlocked and you can sign text like this: > web3.eth.sign(<your address>, web3.sha3("Some text")) ...
o0ragman0o's user avatar
  • 4,320
19 votes
Accepted

Ethereum ecrecover signature verification and encryption

v, r, and s are parameters that can be parsed from the signature. Here's a good example from the ethereumjs utils library: var sig = secp256k1.sign(msgHash, privateKey) var ret = {} ret.r = ...
dbryson's user avatar
  • 6,403
19 votes
Accepted

Using AWS CloudHSM to sign transactions

OK, so when we (me and the ShaneT) implemented hardware signing (private key stored exclusively on AWS CloudHSM) there were a number of things we learned. Hopefully this gives you a guide on how you ...
Woodstock's user avatar
  • 338
18 votes
Accepted

How to properly create a raw transaction and sign it using web3 in browser

Below is working code that calls "increment" on https://programtheblockchain.com/dapps/counter. (More info about that sample here: https://programtheblockchain.com/posts/2017/12/13/building-...
user19510's user avatar
  • 28k
18 votes

How to properly create a raw transaction and sign it using web3 in browser

Using Web3.js 1.0.0 encoded = contractInstance.methods.myMethod(params).encodeABI() var tx = { to : myContractAddress, data : encoded } web3.eth.accounts.signTransaction(tx, privateKey)....
biplavo's user avatar
  • 934
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
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
16 votes
Accepted

What are the IDs for the various Ethereum chains?

1 Mainnet: https://ethereum.org 2 Morden Testnet (deprecated) 3 Ropsten Testnet (deprecated) 4 Rinkeby Testnet (deprecated) 5 Goerli Testnet: https://goerli.net 42 Kovan Testnet (deprecated) 11155111 ...
Roland Kofler's user avatar
16 votes
Accepted

Is it possible to sign a message in Solidity?

There might be implementations of signing in Solidity, but you shouldn't do it. This is because in order to sign something, you will need a private key. Since every transaction is public on the ...
erkt's user avatar
  • 673
15 votes
Accepted

Is it safe to reuse Ether addresses?

Currently, Ethereum uses elliptic curve cryptography (ECDSA), the same as Bitcoin. So whatever "unsafe" concerns there are with how Bitcoin transactions are signed, would be the same with Ethereum ...
eth's user avatar
  • 85.7k
14 votes

How do you sign an verify a message in javascript proving you own an Ethereum address?

You can now verify signatures in web3 1.0 using web3.eth.accounts.recover const account = web3.eth.accounts[0]; const signature = await web3.eth.sign("Hello world", account); const signingAddress = ...
David Mihal's user avatar
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

Create and sign OFFLINE raw transactions?

In Go creating a signed transaction would look something like this: transaction := types.NewTransaction(nonce, recipient, value, gasLimit, gasPrice, input) signature, _ := crypto.Sign(transaction....
Péter Szilágyi'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

What if two ether functions have the same signature?

The function signatures need to be unique only within a contract. The Solidity compiler will detect and prevent collisions if they are not unique in this case. If you have fewer than 2^16 functions ...
benjaminion's user avatar
  • 9,267
13 votes
Accepted

How to get private keys on Truffle from Ganache accounts

You can start ganache with a mnemonic as a parameter ( -m 'jar boss sister abuse equal ....'). Doing this, you'll: be guaranteed to have the same addresses generated with each run be able to derive ...
Tudor Constantin's user avatar
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

workflow on signing a string with private key, followed by signature verification with public key

Here's a working example I tested out using truffle: Example.sol pragma solidity ^0.4.0; contract Example { function testRecovery(bytes32 h, uint8 v, bytes32 r, bytes32 s) returns (address) { ...
Miguel Mota's user avatar
  • 5,153
11 votes

Create and sign OFFLINE raw transactions?

You can use Web3. var Accounts = require('web3-eth-accounts'); // Passing in the eth or web3 package is necessary to allow retrieving chainId, gasPrice and nonce automatically // for accounts....
artamonovdev's user avatar
9 votes
Accepted

Can I web3.eth.sign with private key

N/A, in that you don't need to unlock an account at all. Yes, see below. The following uses Web3.js version 1.0.0-beta which is now the default installed by npm. Note that no node is attached. > ...
benjaminion's user avatar
  • 9,267
9 votes
Accepted

Can a message hash be recovered from a signature?

No, you cannot recover the message hash from an ECDSA signature. The siagnture is calculated by generating (x, y) = kG where k is the secret nonce and G is the generator for the curve. Then r = x and ...
Tjaden Hess's user avatar
  • 37.1k
9 votes

How to use ethers keccak256?

With ethers.js v5 you can use: const { ethers, utils } = require("ethers"); const labelhash = utils.keccak256(utils.toUtf8Bytes("example")) This is documented here.
Thomas Clowes's user avatar
8 votes

Create and sign OFFLINE raw transactions?

I found a way using the pyethereum lib. BTW, this lib has little maintenance and doesn't build in most OS's. Here's the sample code for that: from libs.pyethereum.ethereum import transactions from ...
Nico's user avatar
  • 797
8 votes

Do I have to unlock my account in geth to call a web3.eth.sign() in JavaScript?

You need to unlock your account to be able to operate with it. The third parameter of unlockAccount is a timeout in seconds. web3.personal.unlockAccount("0x..", "<passs>", 1000); But be aware ...
Ismael's user avatar
  • 30.6k
8 votes
Accepted

Demystify Transaction signing process

This is basically correct. In (4), any node can receive a transaction, check the signature and relay it to other nodes. The public key can be recovered from the signature, so it doesn't need to be ...
Edmund Edgar's user avatar
  • 16.9k

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