ethereum-private-key-to-public-key
Version:
Convert an Ethereum private key to a public key
61 lines (38 loc) • 2.21 kB
Markdown
> Convert an Ethereum private key to a public key
[](https://raw.githubusercontent.com/miguelmota/ethereum-private-key-to-public-key/master/LICENSE)
[](http://badge.fury.io/js/ethereum-private-key-to-public-key)
[](https://lab.miguelmota.com/ethereum-private-key-to-public-key)
```bash
npm install ethereum-private-key-to-public-key
```
```javascript
const privateKeyToPublicKey = require('ethereum-private-key-to-public-key')
console.log(privateKeyToPublicKey(Buffer.from('4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d', 'hex')).toString('hex')) // '04e68acfc0253a10620dff706b0a1b1f1f5833ea3beb3bde2250d5f271f3563606672ebc45e0b7ea2e816ecb70ca03137b1c9476eec63d4632e990020b7b6fba39'
console.log(privateKeyToPublicKey('4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d').toString('hex')) // '04e68acfc0253a10620dff706b0a1b1f1f5833ea3beb3bde2250d5f271f3563606672ebc45e0b7ea2e816ecb70ca03137b1c9476eec63d4632e990020b7b6fba39'
console.log(privateKeyToPublicKey('0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d').toString('hex')) // '04e68acfc0253a10620dff706b0a1b1f1f5833ea3beb3bde2250d5f271f3563606672ebc45e0b7ea2e816ecb70ca03137b1c9476eec63d4632e990020b7b6fba39'
```
Install:
```bash
npm install -g ethereum-private-key-to-public-key
```
Convert private key to public key:
```bash
$ ethereum_private_key_to_public_key 4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d
04e68acfc0253a10620dff706b0a1b1f1f5833ea3beb3bde2250d5f271f3563606672ebc45e0b7ea2e816ecb70ca03137b1c9476eec63d4632e990020b7b6fba39
```
Piping private key example:
```bash
$ echo 4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d | ethereum_private_key_to_public_key
04e68acfc0253a10620dff706b0a1b1f1f5833ea3beb3bde2250d5f271f3563606672ebc45e0b7ea2e816ecb70ca03137b1c9476eec63d4632e990020b7b6fba39
```
```bash
npm test
```
[](LICENSE)