63 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 ...
user avatar
  • 15.2k
42 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 ...
user avatar
  • 78.8k
41 votes
Accepted

Where is the private key for a contract stored?

Contracts do not possess private keys in the same way that your ether wallet does. Instead, they have programming code written in the language of the Ethereum Virtual Machine. To determine what a ...
user avatar
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('...
user avatar
  • 78.8k
25 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 ...
user avatar
  • 1,736
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")) ...
user avatar
  • 4,180
23 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 ...
user avatar
  • 824
21 votes
Accepted

Is Ethereum secure against an attack by quantum computers?

Currently, Ethereum uses elliptic curve cryptography, which is not quantum resistant. In the upcoming Serenity upgrade, however, accounts will be able to specify their own scheme for validating ...
user avatar
  • 34.4k
18 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 = ...
user avatar
  • 6,043
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-...
user avatar
  • 26.7k
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)....
user avatar
  • 869
16 votes

How can I sign a piece of data with the private key of an Ethereum address?

First, you'll need the private key for your account. To generate a brand new key, I use elliptic.js: import {ec as EC} from 'elliptic'; const ec = new EC('secp256k1'); const keypair = ec.genKeyPair()...
user avatar
16 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 ...
user avatar
  • 78.8k
15 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 ...
user avatar
  • 1,736
15 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 ...
user avatar
  • 298
14 votes
Accepted

How can I sign a piece of data with the private key of an Ethereum address?

There's a functionality from the JSON RPC API not yet ported to web3 to sign data directly with one RPC function call, without messing with keys and crypto. If you don't need to sign messages ...
user avatar
  • 2,331
14 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 ...
user avatar
  • 643
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....
user avatar
13 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 ...
user avatar
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 ...
user avatar
12 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(...
user avatar
  • 2,896
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 ...
user avatar
  • 2,896
12 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 = ...
user avatar
12 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 Row ...
user avatar
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) { ...
user avatar
  • 4,795
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....
user avatar
11 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 ...
user avatar
11 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 ...
user avatar
  • 8,702
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 ...
user avatar
  • 807
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 ...
user avatar
  • 29.5k

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