Web3j: ERC20 Transaction receipt was not generated after 600 seconds for transaction

Created on 23 Jan 2018  Â·  6Comments  Â·  Source: web3j/web3j

I send EOS transaction,throw error Transaction receipt was not generated after 600 seconds for transaction:txid,so I re-send tx,but when I check the target(to) address on https://etherscan.io/,
target address receive many transaction from my address.how to avoid re-send ERC20 tx,this is my code:

  Web3j web3j = Web3j.build(new HttpService(protocol + "://" + url));
 TransactionManager transactionManager = new ClientTransactionManager(web3j, fromAddress);
  // EOS is Auto generated code via web3j command line tools
  EOS eos = EOS.load(contractAddress, web3j, transactionManager, gasPrice, gas);
  TransactionReceipt receipt = eos.transfer(to, value).send();
  if(receipt==null){
   // re-send TX after 5 min
  }

Most helpful comment

I solved this problem,like this:
1.web3j OkHttp set timeout 300 seconds,set attempts 8

Web3jConfig web3jConfig = new Web3jConfig();
Web3j web3j = Web3j.build(web3jConfig.buildService(protocol + "://" + url));

int sleepDuration = 15 * 1000;
int attempts = 8; // DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH = 40
TransactionManager transactionManager = new ClientTransactionManager(web3j, this.fromAddress, attempts, sleepDuration);
erc20Instance = CRE.load(contractAddress, web3j, transactionManager, null, null);
  1. catch exception get transaction id from exception message

  2. manual re-send coins if failed

All 6 comments

I get why the program throw exception?because my ETH wallet node sync block so slow.so I can't get transaction receipt Within 10(40*15 second) minutes.can you return transaction hash after 10 minutes instead of throw exception? @conor10

I solved this problem,like this:
1.web3j OkHttp set timeout 300 seconds,set attempts 8

Web3jConfig web3jConfig = new Web3jConfig();
Web3j web3j = Web3j.build(web3jConfig.buildService(protocol + "://" + url));

int sleepDuration = 15 * 1000;
int attempts = 8; // DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH = 40
TransactionManager transactionManager = new ClientTransactionManager(web3j, this.fromAddress, attempts, sleepDuration);
erc20Instance = CRE.load(contractAddress, web3j, transactionManager, null, null);
  1. catch exception get transaction id from exception message

  2. manual re-send coins if failed

I hit the same problem. Also I used same way to solved the problem.

Is there a way to get the "txHash" when send the request? If we can get the "txHash" from thrown execption, why not provide a way to get the "txHash" first?

I solved this problem,like this:
1.web3j OkHttp set timeout 300 seconds,set attempts 8

Web3jConfig web3jConfig = new Web3jConfig();
Web3j web3j = Web3j.build(web3jConfig.buildService(protocol + "://" + url));

int sleepDuration = 15 * 1000;
int attempts = 8; // DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH = 40
TransactionManager transactionManager = new ClientTransactionManager(web3j, this.fromAddress, attempts, sleepDuration);
erc20Instance = CRE.load(contractAddress, web3j, transactionManager, null, null);
  1. catch exception get transaction id from exception message
  2. manual re-send coins if failed

Hi, how decreasing attempts count solved your problem (Default attempts is 40)?

send usdt error org.web3j.protocol.exceptions.TransactionException: Transaction receipt was not generated after 600 seconds for transaction: 0xb5e5f38855abe55356f98cc63d671eba71b89aa14b2c6b477f8951321c858457

```public static TransactionReceipt sendToken(Credentials credentials, String toaddress, String count, String contractAddress, double decimals, int isTest) throws Exception {
TransactionReceipt send = getToken(credentials, contractAddress, isTest).transfer(toaddress, new BigDecimal(count).multiply(new BigDecimal(Math.pow(10, decimals))).toBigInteger()).sendAsync().get();
return send;
}

public static Erc20Token2 getToken(Credentials credentials, String contractAddress, int isTest) {
Erc20Token2 load = Erc20Token2.load(contractAddress, getWeb3jForToken(isTest), credentials, getSmallGas());
return load;
}

public static StaticGasProvider getSmallGas() {
//return new StaticGasProvider(DefaultGasProvider.GAS_PRICE, new BigInteger("150000"));
return new DefaultGasProvider();
}
```

I hit the same problem. Also I used same way to solved the problem.

Is there a way to get the "txHash" when send the request? If we can get the "txHash" from thrown execption, why not provide a way to get the "txHash" first?

Can you relove the question????

Was this page helpful?
0 / 5 - 0 ratings