Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how I can get the transaction hash before web3.eth.sendSignedTransaction #2193

Closed
dk-lan opened this issue Jan 15, 2019 · 6 comments
Closed

Comments

@dk-lan
Copy link

dk-lan commented Jan 15, 2019

        let tx = new Tx(rawTransaction);
        tx.sign(privateKey);
        let serializedTx = '0x' + tx.serialize().toString('hex');
        // I need to get the transaction hash here
        let sender = web3.eth.sendSignedTransaction(serializedTx).once('transactionHash',  async hash => {
            console.log(hash)              
        })
@OFRBG
Copy link

OFRBG commented Jan 15, 2019

@dk-lan
Copy link
Author

dk-lan commented Jan 16, 2019

You might want to try this: https://web3js.readthedocs.io/en/1.0/web3-eth-personal.html#signtransaction

tq for you reply, but I only have privateKey, signtransaction must need password for account.

@OFRBG
Copy link

OFRBG commented Jan 16, 2019

Managing plaintext private keys is a bad idea, but if you must, then try with https://web3js.readthedocs.io/en/1.0/web3-eth.html#signtransaction.

@dev1644
Copy link

dev1644 commented Jan 16, 2019

@dk-lan This will get you the txHash of your transaction before sending it.
const txHash = await web3.utils.sha3(serializedTx);

@dk-lan
Copy link
Author

dk-lan commented Jan 16, 2019

@dev1644
thanks , the way is correctly

@dk-lan dk-lan closed this as completed Jan 16, 2019
@mmo2112
Copy link

mmo2112 commented Oct 18, 2019

@dev1644, hi I've tried wtih online hashing such as https://emn178.github.io/online-tools/keccak_256.html but the result is different. Maybe web3 has modified few input data or something? Thanks for your help so much bro.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants