Consensys / eth-lightwallet

Lightweight JS Wallet for Node and the browser
MIT License
1.46k stars 501 forks source link

How do I sign a transaction? #151

Open IAMtheIAM opened 7 years ago

IAMtheIAM commented 7 years ago

The examples are not very clear. How do I use the wallet to

1) prompt the user for password/acceptance, then 2) use password to decrypt passwordDerivedKey, and finally 3) sign transaction?

The keystore is great, I just need some help implementing this into a real wallet where a user is actually prompted for a password before signing the transaction, similar to how metamask prompts to accept/reject the transaction.

sc0Vu commented 7 years ago

Hi,

Before you sign transaction, you need to create RLP encoded raw unsigned transactions .

You can see the txutils-function-definitions in README.md to create RLP encoded raw unsigned transactions .

For example valueTx: var valueTx = lightwallet.txutils.valueTx({to: 'to address', value: 'value', nonce: 'nonce', gasPrice: 'gas price'})

contractTx: var funcTx = lightwallet.txutils.functionTx(abi, 'name', ['args'], {to: 'contract address', value: 'value', nonce: 'nonce', gasPrice: 'gas price'})

signedTx: var signedTx = lightwallet.signing.signTx(keystore, pwDerivedKey, 'your RLP encoded raw unsigned transactions', address).toString('hex')

Finally use sendRawTransaction in web3Js.

IAMtheIAM commented 7 years ago

Thanks, i get

var signedTx = lightwallet.txutils.signTx(keystore, _privateKey, valueTx, toAddr).toString('hex');

//error
Uncaught (in promise) TypeError: txutils.signTx is not a function
tzapu commented 7 years ago

@IAMtheIAM signTx is in the signing lib, not txutils https://github.com/ConsenSys/eth-lightwallet#signing-function-definitions

sc0Vu commented 7 years ago

@tzapu It's signing lib, thx! Before send the transaction, you should add hex prefix.