org.web3j.protocol.exceptions.TransactionException: Error processing request: unknown transaction
I am calling a transfer method on an ERC20 contract like this:
> Credentials credentials = null;
> try {
> this.initWeb3Client();
> credentials = WalletUtils.loadCredentials(pwd, path);
> MyToken mt = MyToken.load(ADDRESS,web3j,
> credentials, BigInteger.valueOf(20_000_000_000L),BigInteger.valueOf(4_300_000L));
> TransactionReceipt tr = oso.transfer(address,value).send();
> System.out.println("hash:"+tr.getTransactionHash());
> } catch (IOException e) {
> e.printStackTrace();
> } catch (CipherException e) {
> e.printStackTrace();
> } catch (Exception e) {
> e.printStackTrace();
> }
The transaction was successful and confirmed at Rinkeby, but an exception was returned
org.web3j.protocol.exceptions.TransactionException: Error processing request: unknown transaction
at org.web3j.tx.response.TransactionReceiptProcessor.sendTransactionReceiptRequest(TransactionReceiptProcessor.java:32)
at org.web3j.tx.response.PollingTransactionReceiptProcessor.getTransactionReceipt(PollingTransactionReceiptProcessor.java:37)
at org.web3j.tx.response.PollingTransactionReceiptProcessor.waitForTransactionReceipt(PollingTransactionReceiptProcessor.java:29)
at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:72)
at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:51)
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:70)
at org.web3j.tx.Contract.executeTransaction(Contract.java:223)
at org.web3j.tx.Contract.executeTransaction(Contract.java:207)
at org.web3j.tx.Contract.executeTransaction(Contract.java:201)
at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:240)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
at com.novel.balbit.ports.contract.MyTokenTest.transfer(MyTokenTest.java:358)
at com.novel.balbit.ports.contract.MyTokenTest.main(MyTokenTest.java:396)
The problem is inside TransactionReceiptProcessor
when you call web3j.ethGetTransactionReceipt(transactionHash).send()
inside of
waitForTransactionReceipt
Your Node may not reached the state, where it can give you a valid TransactionReceipt.
You can get a workaround on this, constructing the transaction manually:
Web3j web3 = Web3j.build(new HttpService()); // defaults to http://localhost:8545/
Credentials credentials = WalletUtils.loadCredentials("password", "/path/to/walletfile");
// get the next available nonce
EthGetTransactionCount ethGetTransactionCount = web3j.ethGetTransactionCount(
address, DefaultBlockParameterName.LATEST).sendAsync().get();
BigInteger nonce = ethGetTransactionCount.getTransactionCount();
// create our transaction
RawTransaction rawTransaction = RawTransaction.createEtherTransaction(
nonce, <gas price>, <gas limit>, <toAddress>, <value>);
// sign & send our transaction
byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
String hexValue = Hex.toHexString(signedMessage);
// FROM here you can get the tx hash.
EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).send();
Although you can inject your custom TransactionManager and change the variable value of polling attempts to increase the probability to get the txhash.
public static final int DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH = 40;
public static final long DEFAULT_POLLING_FREQUENCY = 1000 * 15;
For example:
new Transfer(client, new ClientTransactionManager(client ,fromAddress, 100))
PostScriptum Found another imho more explicit way to do it:
val txManager = new RawTransactionManager(client,credentials,100,1000 * 15)
val transfer = new Transfer(client,txManager)
transfer.sendFunds(
walletAddress,
amount,
currency.convert)
})
I've used an extension to inject my own TX manager into the construction of generated code that extends the Contract class. And the injected TX manager uses different timeouts than the default.
IF that's of interest or use to others I could see about getting the code into the web3j spring module, but I'd need to noodle on the best way to do the wiring in that case - in my case I just inject the Tx Manager into the methods that create the contract instances, which are all spring "beans" in my app, so the wiring is trivial. But that wouldn't be the best for a general case solution
The best way would be do decouple the receipt getting functionality from the one that returns a transaction hash. So you could compose two async operations with separate callbacks. This re-pulling strategy is inefficient since it do CPU work for nothing.
I called web3j.ethSendTransaction(transaction).sendAsync().get() to get transaction hash, then I used transaction hash to waitForTransactionReceipt;
Thanks for your reply, a great help for me! @allquantor @eepstein
I’m afraid there may be deeper problem requiring to be resolved and this issue reopened.
I have the similar problems with Error processing request: unknown transaction, except what I am using is not a transfer, but the SolidityFunctionWrapperGenerator-generated wrappers for some contract.
Trying to call a method like public RemoteCall<TransactionReceipt> bulkTransfer(String token, List<String> toAddresses, List<BigInteger> values), I get this problem.
Deep inside the chain of calls, I see that web3j, inside TransactionManager.processResponse, does the following:
String transactionHash = transactionResponse.getTransactionHash();
return transactionReceiptProcessor.waitForTransactionReceipt(transactionHash);
If I understand the comment from allquantor properly, this means that at this point web3j, for some reason, may be in the state when it cannot successfully perform and handle waitForTransactionReceipt, though it does it anyway; but until it is fixed, this makes any smart contract method calls from web3j virtually useless.
Dear all, it seems I have exactly the same basic problem
I am starting my ethreum node via
geth --identity="Node01" --datadir="../Node01" -verbosity 6 --port 30301 -rpc --rpcport 8545 --rpcaddr localhost --rpccorsdomain "*" --rpcapi "db,eth,net,web3" --networkid="12345" --nodiscover console 2>> ./../target/Node01.log
Then the following code is working
HttpService httpService = new HttpService("http://localhost:8545");
Web3j web3 = Web3j.build(httpService);
Web3ClientVersion web3ClientVersion;
try {
web3ClientVersion = web3.web3ClientVersion().sendAsync().get();
String clientVersion = web3ClientVersion.getWeb3ClientVersion();
System.out.println(clientVersion);
} catch (InterruptedException | ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
But when I call a smart contract coded in solidity and encapsulated via web3j-maven-plugin
I am getting the same error
Credentials credentials = AccountManager.getInstance().getCredentials(0);
// https://github.com/web3j/web3j/issues/117
BigInteger GAS_PRICE = BigInteger.valueOf(20_000_000_000L);
BigInteger GAS_LIMIT = BigInteger.valueOf(4_700_000);
// BigInteger initialEtherValue = BigInteger.valueOf(0);
this.dataQualifier = DataQualifier.deploy(Ethereum.getInstance().getWeb3j(), credentials, GAS_PRICE, GAS_LIMIT)
.send();
Error message:
java.lang.RuntimeException: org.web3j.protocol.exceptions.TransactionException: Error processing request: unknown transaction
at org.web3j.tx.Contract.deploy(Contract.java:283)
at org.web3j.tx.Contract.lambda$deployRemoteCall$5(Contract.java:315)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
at com.cea.licia.blockchainergy.client.AbstractTestScenario.deployContracts(AbstractTestScenario.java:60)
at com.cea.licia.blockchainergy.client.TestVoting.testScenario(TestVoting.java:36)
at com.cea.licia.blockchainergy.client.TestVoting.<init>(TestVoting.java:30)
at com.cea.licia.blockchainergy.client.TestVoting.main(TestVoting.java:22)
Caused by: org.web3j.protocol.exceptions.TransactionException: Error processing request: unknown transaction
at org.web3j.tx.response.TransactionReceiptProcessor.sendTransactionReceiptRequest(TransactionReceiptProcessor.java:32)
at org.web3j.tx.response.PollingTransactionReceiptProcessor.getTransactionReceipt(PollingTransactionReceiptProcessor.java:37)
at org.web3j.tx.response.PollingTransactionReceiptProcessor.waitForTransactionReceipt(PollingTransactionReceiptProcessor.java:29)
at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:72)
at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:51)
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:70)
at org.web3j.tx.Contract.executeTransaction(Contract.java:223)
at org.web3j.tx.Contract.create(Contract.java:252)
at org.web3j.tx.Contract.deploy(Contract.java:281)
... 6 more
Any idea will be well come!
@flefevre , I have (unconfirmed) suspicion that it may happen with recent Geth versions (1.8.0 and above). I recall I’ve seen my code working with 1.7.3/Rinkeby, while the same code fails completely with all such smart contract method calls on 1.8.0/Rinkeby (and I think, fails on 1.8.0/Mainnet as well).
What geth version are you using? This may be either some temporary issue in 1.8.0 (so it will be resolved later); or, if it is “a new geth way of life”, web3j may need to be updated to handle this; cause at the moment they are basically incompatible.
hello, personnaly, i was on geth 1.8.0 i have downloaded the git repository today and test with lastest version INFO [02-02|21:07:28] Starting peer-to-peer node instance=Geth/v1.8.0-unstable-fdb34b7a/linux-amd64/go1.8.3
I am still experiencing the problem. I do not if it help you to determine where it comes but if I switch to the new UnixIpcService(GETH_IPC_PATH), it works. It seems to be specific to the new HttpService("http://localhost:8545")
I am sorry not to have additional idea, do not hesitate to ask me to test whatever you want. Have a good week-end
I Have this problem too!! I do Contract or Transaction having this problem。 And I used geth 1.7.2 or 1.7.3 or leater, web3j 3.2.0 ! I can not solve.
Exception in thread "main" java.util.concurrent.ExecutionException: org.web3j.protocol.exceptions.TransactionException: Error processing request: unknown transaction
Same problem .I start a private chain ,and run the sample-project-gradle to integrate with it. Code like:
TransactionReceipt transferReceipt = Transfer.sendFunds(
web3j, credentials,
"0xe80fbabee07b259fe36a950ef384abf401806eef", // you can put any address here
BigDecimal.ONE, Convert.Unit.WEI) // 1 wei = 10^-18 Ether
.send();
The transfer was successful. And an exception was returned as followed:
14:53:32.862 [main] INFO org.web3j.sample.Application - Connected to Ethereum client version: Geth/TestNode/v1.8.0-unstable-4dedde7b/linux-amd64/go1.8.3
14:53:35.125 [main] INFO org.web3j.sample.Application - Credentials loaded
14:53:35.143 [main] INFO org.web3j.sample.Application - Sending 1 Wei (0.000000000000000001 Ether)
Exception in thread "main" org.web3j.protocol.exceptions.TransactionException: Error processing request: unknown transaction
at org.web3j.tx.response.TransactionReceiptProcessor.sendTransactionReceiptRequest(TransactionReceiptProcessor.java:32)
at org.web3j.tx.response.PollingTransactionReceiptProcessor.getTransactionReceipt(PollingTransactionReceiptProcessor.java:37)
at org.web3j.tx.response.PollingTransactionReceiptProcessor.waitForTransactionReceipt(PollingTransactionReceiptProcessor.java:29)
at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:72)
at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:51)
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:70)
at org.web3j.tx.Transfer.send(Transfer.java:65)
at org.web3j.tx.Transfer.send(Transfer.java:49)
at org.web3j.tx.Transfer.lambda$sendFunds$20(Transfer.java:76)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
at org.web3j.sample.Application.run(Application.java:81)
at org.web3j.sample.Application.main(Application.java:51)
Here is the command that I start my private chain :
geth --identity "TestNode" --rpc --rpcapi "db,personal,eth,net,web3" --rpcaddr="0.0.0.0" --rpcport "8545" --rpccorsdomain "http://remix.ethereum.org" --datadir ./data --port "30304" --networkid 2222 console 2>>my.log
Another same problem happened . When executed :
Greeter contract = Greeter.deploy(
web3j, credentials,
ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT,
"Hello blockchain world!").send();
Exception in thread "main" java.lang.RuntimeException: org.web3j.protocol.exceptions.TransactionException: Error processing request: unknown transaction
at org.web3j.tx.Contract.deploy(Contract.java:283)
at org.web3j.tx.Contract.lambda$deployRemoteCall$5(Contract.java:315)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
at org.web3j.sample.Application.run(Application.java:94)
at org.web3j.sample.Application.main(Application.java:52)
Caused by: org.web3j.protocol.exceptions.TransactionException: Error processing request: unknown transaction
at org.web3j.tx.response.TransactionReceiptProcessor.sendTransactionReceiptRequest(TransactionReceiptProcessor.java:32)
at org.web3j.tx.response.PollingTransactionReceiptProcessor.getTransactionReceipt(PollingTransactionReceiptProcessor.java:37)
at org.web3j.tx.response.PollingTransactionReceiptProcessor.waitForTransactionReceipt(PollingTransactionReceiptProcessor.java:29)
at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:72)
at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:51)
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:70)
at org.web3j.tx.Contract.executeTransaction(Contract.java:223)
at org.web3j.tx.Contract.create(Contract.java:252)
at org.web3j.tx.Contract.deploy(Contract.java:281)
I got rid of this problem getting back to geth 1.7.3 stable; too bad that all the build procedures for go language assume building the master branch and thus build the 1.8.0 unstable only.
@amyodov When I change to geth 1.7.3 stable , It works ! Thank you a lot!
1.8.0 is not working well
I upgraded geth to 1.8.1-stable, but also get the same error while using Transfer.sendFunds(). Geth v1.8.* doesn't seem to have a lot of features/bugfixes added over 1.7.3. Can anyone tell me the downsides of using the older 1.7.3 instead of 1.8.*?
The only way around this is to extend PollingTransactionReceiptProcessor yourself to retrieve the transactionHash of the newly deployed smart contract later on.
MyTransactionReceiptProcessor transactionReceiptProcessor = new MyTransactionReceiptProcessor(admin);
TransactionManager transactionManager = new ClientTransactionManager(admin, account, transactionReceiptProcessor);
MyContract.deploy(admin, transactionManager, MyContract.GAS_PRICE, MyContract.GAS_LIMIT, "hello world").sendAsync();
String transactionHash = null;
while (null == transactionHash) {
transactionHash = transactionReceiptProcessor.getTransactionHash();
Thread.sleep(1000);
}
It should definitely be easier than the above to deploy a contract and get its transaction hash.
Just tested what @allquantor has pointed out: constructing the transaction manually and this works (at least for sending Ether) without errors. @duvalCC This will help you too!
@Daantie "constructing the transaction manually"... so what's the point of the wrappers then?
I faced the same problem on 1.8.* geth. Works fine with 1.7.2.
In geth 1.8.0/1.8.1, eth.getTransactionReceipt() throws "Error: unknown transaction" instead of null if the transaction is not mined. This makes web3j throw exception. Filed an issue to go-ethereum: https://github.com/ethereum/go-ethereum/issues/16213 @conor10 Any ideas? Thanks.
@fcorneli in this case they're useless, I was just pointing at a workaround. The current Web3j version (v3.2.0 - mid Dec) is older than the v1.8.* Geth (new since 2 weeks). I guess you should stick with Geth 1.7.3 if you want to work with the wrappers and wait for new Web3j version, or use the workaround and go for Geth 1.8.*.