Web3j: how to getTransactionHash() as soon as possible

Created on 28 Mar 2018  路  8Comments  路  Source: web3j/web3j

hi everyone ,
i want to know how to getTransactionHash() as soon as possible as transaction send,no matter this transaction is success or fail,now too slow,should wait for more than 60s.
thanks!

Most helpful comment

If you have a signed raw transaction, you can calculate the transaction hash directly. Even before sending the transaction to a client node.

All 8 comments

If you have a signed raw transaction, you can calculate the transaction hash directly. Even before sending the transaction to a client node.

@fcorneli How to calculate the transaction hash directly thanks

String transactionHash = Hash.sha3(rawTransaction);

@fcorneli thanks

@fcorneli Decoding transaction input data with web3j (Java)

If you'd like to get the hash without calculating it yourself, you can set a transaction manager which will not poll for the block being mined. If you use something like the following, you will get the transaction hash immediately:

    NoOpProcessor processor = new NoOpProcessor(web3j);
    TransactionManager txManager = new FastRawTransactionManager(web3j, credentials, processor);
    ERC20Interface token = ERC20Interface.load(TOKEN_CONTRACT_ADDRESS, web3j, txManager, gasPrice, gasLimit);
    String tx = token.transfer(wallet, tokenAmount).send().getTransactionHash();

Hi all, I'm using the send asynk function of smart contract, now ceck the log and the RPC of the node send the transaction hash at the first request but it is not possible to retrive it before the transaction succed or fail. I check inside the lib and in the class org.web3j.tx.Contract at line number 275, the transaction hash is available soon after the submit whitout wait the end of the transaction. exist a way to retrive this value whitout wait?

@marcuzzu please open a new issue with more detail to you question or problem.

Was this page helpful?
0 / 5 - 0 ratings