Skip to content

Instantly share code, notes, and snippets.

@tomericco
Last active November 19, 2017 19:22
Show Gist options
  • Save tomericco/41822dbaf7068f8419f0d5bd6eaecbb3 to your computer and use it in GitHub Desktop.
Save tomericco/41822dbaf7068f8419f0d5bd6eaecbb3 to your computer and use it in GitHub Desktop.
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