Last active
November 19, 2017 19:22
-
-
Save tomericco/41822dbaf7068f8419f0d5bd6eaecbb3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3'); | |
const SignerProvider = require('ethjs-provider-signer'); | |
const EthereumTx = require('ethereumjs-tx'); | |
const keystore = require('../lib/keystore'); | |
const provider = new SignerProvider('http://localhost:8545', { | |
signTransaction(rawTx, cb) { | |
const { from } = rawTx; | |
const privateKey = keystore.getPrivateKeyByAddress(from); // Load user's private key from your own keystore | |
const privateKeyHex = Buffer.from(privateKey, 'hex'); | |
const tx = new EthereumTx(rawTx); | |
tx.sign(privateKeyHex); | |
cb(null, '0x' + tx.serialize().toString('hex')); | |
} | |
}); | |
const web3 = new Web3(provider); // Use this instance of web3 to sign with your own logic above |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment