Skip to content

Instantly share code, notes, and snippets.

@ulinkwo
Forked from miracle2k/convert.js
Created February 26, 2022 04:17
Show Gist options
  • Save ulinkwo/656e3c1bcd8aa6c7ae1676cc96537dcd to your computer and use it in GitHub Desktop.
Save ulinkwo/656e3c1bcd8aa6c7ae1676cc96537dcd to your computer and use it in GitHub Desktop.
Convert Ethereum private keys to EOS private keys (the "Fallback method" to access your EOS tokens).
// Extracted from https://github.com/eoscafe/eoskeyio
const ecc = require('eosjs-ecc');
const eth = require('ethereumjs-util');
let ethereumPrivateKey = 'FILL THIS IN';
if(eth.isValidPrivate(Buffer.from(ethereumPrivateKey, 'hex'))) {
let ethereumAddress = '0x' + eth.privateToAddress(Buffer.from(ethereumPrivateKey, 'hex')).toString('hex')
let ethereumPublicKey = eth.privateToPublic(Buffer.from(ethereumPrivateKey, 'hex')).toString('hex')
// Create EOS keys
let eosWIF = ecc.PrivateKey(Buffer.from(ethereumPrivateKey, 'hex')).toWif()
let convertedEOSPrivateKey = eosWIF
let convertedEOSPublicKey = ecc.privateToPublic(eosWIF)
console.log(`EOS Private Key: ${convertedEOSPrivateKey}`)
console.log(`EOS Public Key: ${convertedEOSPublicKey}`)
} else {
console.log("Invalid Ethereum Private Key")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment