Skip to content

Instantly share code, notes, and snippets.

@BennyM
Created September 20, 2017 14:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BennyM/3566b593f04b5ffa42d776d088965224 to your computer and use it in GitHub Desktop.
Save BennyM/3566b593f04b5ffa42d776d088965224 to your computer and use it in GitHub Desktop.
Use eth-lightwallet with Web3ProviderEngine
var keyStore = ...init as usual...;
var engine = new Web3ProviderEngine();
var opts = {
getAccounts: (cb) => {
let addresses = keyStore.getAddresses();
let prefixedAddresses = addresses.map(add => {
return '0x' + add;
});
cb(null, prefixedAddresses);
},
signTransaction: (tx, cb) => {
let signedTransactionCallback = (error, result) =>{
cb(null, result);
};
keyStore.signTransaction(tx, signedTransactionCallback);
}
};
var hookedWalletProvider = new HookedWalletSubprovider(opts);
engine.addProvider(hookedWalletProvider);
engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider('http://myblochain.io:8545')));
engine.start();
var web3 = new Web3(engine);
@saniales
Copy link

saniales commented Mar 22, 2018

If you use WebsocketProvider instead of HttpProvider and you use Web3 1.0.0 it currently does not work due to the lack of support of newer version of web3 (at current state : today is 03/22/2018)

@john-osullivan
Copy link

What does your keyStore.signTransaction method look like? I'm not sure where a password would be provided here to perform the sign.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment