50

Paste the key into a text file, save it to disk and use the path to that file with geth account import. Here are some example Windows instructions that might help: Open Notepad Paste key into notepad without any extra characters or quotations Save the file as nothing_special_delete_me.txt at C:\ Run the command, geth account import C:\...


36

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 contract "does", all members of the Ethereum network simply run the relevant portion of code every time a transaction or other contract uses the contract's ...


22

You can use MyEtherWallet or MyCrypto(fork of MyEtherWallet) offline only wallet "view wallet details" function to extract private key from wallet json file. Feel free to use its offline version on an air gapped computer to secure your private key. Edit: MyCrypto only provides this function in the offline version of the wallet now for obvious security ...


20

Yes and no. No - a Bitcoin address cannot be directly used in Ethereum, and vice versa. Yes - underneath, a bitcoin private key is essentially a random 256-bit number (in a certain range, see bitcoin wiki). And the private key's corresponding public key is essentially the x and y coordinates of a point on an elliptic curve. Bitcoin and Ethereum both use ...


19

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 the wrong format, so let's keep in mind that if we get a v that is 0 or 1 we should add 27 to it. If you are running node and have connected web3 to your ...


19

Use the following command in the geth console web3.personal.importRawKey("<Private Key>","<New Password>")


18

The private key is encrypted and, if you are confident in your password's strength, does not need to be encrypted again. The key is encrypted with 128-bit AES by default if you're using geth, and all of the parameters are in the JSON file. The encrypted private key is in the ciphertext attribute. I would recommend keeping the entire file, Theoretically, ...


18

From my reading of the Yellow Paper (YP), Yes you would be able to spend the funds of the contract. But as you note, it is with extremely low probability of being able to find a contract's private key. Spending money in Ethereum is done via a CALL opcode, passing it parameters such as the sender, recipient, value (being spent). Since you have the private ...


18

Yes, both cryptocoins use the same elliptic curve SECP256K1. Perhaps a better alternative is to use a BIP32 wallet. You have a master key that is not directly used for transactions, but it is used to derive child keys than can be used. You can derive separate keys for bitcoin and ethereum. You will always be able to use the master key to sign transactions ...


18

Your calculations are right, except there aren't exactly 2^256 private keys -- there are "FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141" (this number is named N in the ETH source code, and is the order of the generator of the elliptic curve secp256k1, from which Ethereum key pairs are generated). In answer to your question, yes, ...


16

As mentioned by Peter, a private key is a random 256 bit blob. It is a common oversight that there're no restrictions. It has to be valid for the secp256k1 curve, which means two conditions: cannot be zero must be less than the order of the curve (called n and has a value of ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141) In ...


16

ethereumjs-wallet can be used to get public key from private key: > const hdkey = require('ethereumjs-wallet/hdkey') > const privateKey = hdkey.fromMasterSeed('random')._hdkey._privateKey > const Wallet = require('ethereumjs-wallet') > const wallet = Wallet.fromPrivateKey(privateKey) > wallet.getPublicKeyString() '...


14

You can now import single/"loose"(as we call) keys into MetaMask if you click the menu in the top right corner. It will drop down with the option "Import account", you can click that and it will take you to a view where it will ask you to import your private key or json file.


13

For a numbers of 64 hexadecimal digits, there are 16 ^ 64 = 115792089237316195423570985008687907853269984665640564039457584007913129639936 possibilities. For a numbers of 32 hexadecimal digits, there are 16 ^ 32 = 340282366920938463463374607431768211456 possibilities. If someone has half your private key, your security has been reduced by a factor of ...


13

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-decentralized-apps-with-ethereum-and-javascript/.) It uses web3.js and ethereumjs-tx: <!-- from https://github.com/ethereumjs/browser-builds/raw/master/dist/...


12

Edit: the following info is outdated. It still works, but see the verified answer to import directly. Currently I don't believe you can import into Metamask, so I did it the other way around. Here is how: 1) Go to the account in Metamask and Export the account you want. This will give you the private key. 2) Create a file on your desktop called ...


12

If you have node.js, you can do this in node var keyth=require('keythereum') //install keythereum by runing "npm install keythereum" var keyobj=keyth.importFromFile('0x...your..ether..address..','./Appdata/roaming/ethereum') './Appdata/roaming/ethereum' is the folder contains 'keystore'. importFile looks for 'keystore' in that folder. var privateKey=...


12

Simply use geth as indicated in the github wiki: Account update $ geth account update a94f5374fce5edbc8e2a8697c15331677e6ebf0b Unlocking account a94f5374fce5edbc8e2a8697c15331677e6ebf0b | Attempt 1/3 Passphrase: 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b Account 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' unlocked. Please give a new password. Do not ...


12

geth-compatible keystore file can be created in Node using ethereumjs-wallet library: > var Wallet = require('ethereumjs-wallet'); > var key = Buffer.from('efca4cdd31923b50f4214af5d2ae10e7ac45a5019e9431cc195482d707485378', 'hex'); > var wallet = Wallet.fromPrivateKey(key); > wallet.toV3String('password'); '{"version":3,"id":"467233bf-45ec-423b-...


12

Using Web3.js 1.0.0 encoded = contractInstance.methods.myMethod(params).encodeABI() var tx = { to : myContractAddress, data : encoded } web3.eth.accounts.signTransaction(tx, privateKey).then(signed => { web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log) });


11

Just to add to the very good accepted answer: Coin | Address size | Address encoding | Address creation ---------+---------------------+------------------+------------------ Bitcoin | 160 bits (20 bytes) | Base58Check | RIPEMD160(SHA256(<public_key>) Ethereum | 160 bits (20 bytes) | HEX* | KECCAK256(<public_key>)** ...


10

Mist has no way to import via GUI, so you need to import using command line (geth). It will show up in your Mist immediately. For Mac: Open TextEdit Paste key into TextEdit without any extra characters or quotations Save the file as nothing_special_delete_me.txt to your Desktop Open Terminal, run command: geth account import ~/Desktop/...


10

For test net, the folder you are looking for is ~/.ethereum/testnet/keystore/.


10

Some of the links in the comments helped me get the answers to my questions. I have collected all that information combined with my own (recently acquired) knowledge of cryptography from the Coursera Cryptography-I class (for the answer to question number 3). A1. The private key is never (or should never be) saved unencrypted on disk. It is generated from ...


10

There is no general solution for this. Possible approaches for the client-side are: Users keep the private key stored in an encrypted keystore file. The "Login" into the DAPP would be: (1) upload locally, not to the server, the keystore file into the DAPP, (2) type in the password to unlock the keystore, (3) use the private key in DAPP. This is how https:/...


9

Summary The code in the question theoretically should not run, as the private key is in hex format and the call to new BigInteger(senderPrivKey) to parse the hex string without the 16 radix specified would result in a thrown exception. When the code is adjusted to use new BigInteger(senderPrivKey, 16) specifying the base 16 radix, the public key is ...


9

(I've left this as an answer, rather than a wiki, to encourage multiple answers since there may be other explanations that resonate better with people) For brevity, this answer assumes that the underlying cryptography of Ethereum has not been broken. TLDR: private key = only way to access an Ethereum account password = protects private key via encryption; ...


8

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) { /* prefix might be needed for geth only * https://github.com/ethereum/go-ethereum/issues/3731 */ // bytes memory prefix = "\...


8

Alternatively if you are happy installing node.js and npm, you can choose from multiple Javascript projects handling keys: ethereumjs-wallet or keythereum if you want to code a bit or helpeth if you need a simple commandline tool. This command should give you the details needed: $ helpeth -p <your private key as a hex string> keyDetails Make sure ...


8

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 the private keys from that mnemonic const bip39 = require('bip39'); const hdkey = require('ethereumjs-wallet/hdkey'); const wallet = require('ethereumjs-wallet')...


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