hyperledger-web3j / web3j

Lightweight Java and Android library for integration with Ethereum clients
https://www.web3labs.com/web3j-sdk
Other
5.12k stars 1.69k forks source link

Way to immediately retrieve a contract transaction call hash without waiting for future? #153

Closed jordaniac89 closed 7 years ago

jordaniac89 commented 7 years ago

If I make a call through something like Postman, I can immediately get back a transaction hash. Is there a way to do this with web3j? The only way I'm seeing to get the data back in the client is to return a future and wait for it. If not, is this a planned update?

Thanks, Jordan

jordaniac89 commented 7 years ago

I believe I found what I'm looking for:

Transaction transaction = Transaction.createFunctionCallTransaction(
                <credentials>, 
                <nonce>, 
                <gasPrice>, 
                <gasLimit>, 
                <contractAddress>, 
                <data> );

EthSendTransaction response = 
                web3j.ethSendTransaction( transaction ).send();

String hash = response.getTransactionHash()

Does this look like best practice?

conor10 commented 7 years ago

That's certainly a way around it.

It makes sense to have a transaction manager that returns the transaction hash straight away. This helps with higher throughput scenarios. Your welcome to take a look at this if you fancy creating a PR.

jordaniac89 commented 7 years ago

I may do that. BTW, I'm also using the client on the new Rootstock smart contract platform for Bitcoin. Works like a charm :)

conor10 commented 7 years ago

I've created a couple of classes to address this:

Just receive the transaction hash & nothing else: https://github.com/web3j/web3j/blob/master/core/src/main/java/org/web3j/tx/response/NoOpProcessor.java

Get the transactions to be processed in a worker thread that's continually running in the background: https://github.com/web3j/web3j/blob/master/core/src/main/java/org/web3j/tx/response/QueuingTransactionReceiptProcessor.java

See usage examples in the following integration test: https://github.com/web3j/web3j/blob/master/integration-tests/src/test/java/org/web3j/protocol/scenarios/FastRawTransactionManagerIT.java#L79

krakintgithub commented 3 years ago

Just receive the transaction hash & nothing else: https://github.com/web3j/web3j/blob/master/core/src/main/java/org/web3j/tx/response/NoOpProcessor.java

Doesn't look like it does what you said it does...

falconwoods commented 3 years ago

Why is this closed? Is there a better way to do this instead of "Transaction.createFunctionCallTransaction" ?