Java Code Examples for org.web3j.protocol.core.methods.response.TransactionReceipt

The following examples show how to use org.web3j.protocol.core.methods.response.TransactionReceipt. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: web3j   Source File: FunctionWrappersIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFibonacciNotify() throws Exception {
    Fibonacci fibonacci =
            Fibonacci.load(
                    "0x3c05b2564139fb55820b18b72e94b2178eaace7d",
                    Web3j.build(new HttpService()),
                    ALICE,
                    STATIC_GAS_PROVIDER);

    TransactionReceipt transactionReceipt =
            fibonacci.fibonacciNotify(BigInteger.valueOf(15)).send();

    Fibonacci.NotifyEventResponse result = fibonacci.getNotifyEvents(transactionReceipt).get(0);

    assertEquals(result.input, (new Uint256(BigInteger.valueOf(15))));

    assertEquals(result.result, (new Uint256(BigInteger.valueOf(610))));
}
 
Example 2
Source Project: web3j_demo   Source File: Web3jUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Waits for the receipt for the transaction specified by the provided tx hash.
 * Makes 40 attempts (waiting 1 sec. inbetween attempts) to get the receipt object.
 * In the happy case the tx receipt object is returned.
 * Otherwise, a runtime exception is thrown. 
 */
public static TransactionReceipt waitForReceipt(Web3j web3j, String transactionHash) 
		throws Exception 
{

	int attempts = Web3jConstants.CONFIRMATION_ATTEMPTS;
	int sleep_millis = Web3jConstants.SLEEP_DURATION;
	
	Optional<TransactionReceipt> receipt = getReceipt(web3j, transactionHash);

	while(attempts-- > 0 && !receipt.isPresent()) {
		Thread.sleep(sleep_millis);
		receipt = getReceipt(web3j, transactionHash);
	}

	if (attempts <= 0) {
		throw new RuntimeException("No Tx receipt received");
	}

	return receipt.get();
}
 
Example 3
Source Project: web3j   Source File: KotlinParser.java    License: Apache License 2.0 6 votes vote down vote up
public String generateAssertionKotlinPoetStringTypes() {
    Type returnType = getMethodReturnType();
    Object[] body = generatePlaceholderValues();
    StringBuilder symbolBuilder = new StringBuilder();
    symbolBuilder.append("%T.");
    if (returnType == TransactionReceipt.class) {
        symbolBuilder.append("assertTrue(%L.isStatusOK())");
    } else {
        symbolBuilder.append("assertEquals(");
        if (returnType.getTypeName().contains("Tuple")) {
            symbolBuilder.append(" %T(");
            for (Type t : getTypeArray(returnType)) {
                symbolBuilder.append(mappingHelper.getPoetFormat().get(t)).append(", ");
            }
            symbolBuilder.deleteCharAt(symbolBuilder.lastIndexOf(", "));
            symbolBuilder.append(")");
        } else {
            symbolBuilder.append(mappingHelper.getPoetFormat().get(body[0]));
        }
        symbolBuilder.append(", ");
        symbolBuilder.append("%L");
        symbolBuilder.append(")");
    }
    return symbolBuilder.toString();
}
 
Example 4
Source Project: web3j   Source File: JavaParser.java    License: Apache License 2.0 6 votes vote down vote up
public String generateAssertionJavaPoetStringTypes() {
    Type returnType = getMethodReturnType();
    Object[] body = generatePlaceholderValues();
    StringBuilder symbolBuilder = new StringBuilder();
    symbolBuilder.append("$T.");
    if (returnType.equals(TransactionReceipt.class)) {
        symbolBuilder.append("assertTrue($L.isStatusOK())");
    } else {
        symbolBuilder.append("assertEquals(");
        if (returnType.getTypeName().contains("Tuple")) {
            symbolBuilder.append("new $T(");
            for (Type t : getTypeArray(returnType)) {
                symbolBuilder.append(mappingHelper.getPoetFormat().get(t)).append(", ");
            }
            symbolBuilder.deleteCharAt(symbolBuilder.lastIndexOf(", "));
            symbolBuilder.append(")");
        } else {
            symbolBuilder.append(mappingHelper.getPoetFormat().get(body[0]));
        }
        symbolBuilder.append(", ");
        symbolBuilder.append("$L");
        symbolBuilder.append(")");
    }

    return symbolBuilder.toString();
}
 
Example 5
Source Project: client-sdk-java   Source File: BaseContract.java    License: Apache License 2.0 6 votes vote down vote up
private TransactionResponse getResponseFromTransactionReceipt(TransactionReceipt transactionReceipt) throws TransactionException {
	List<Log> logs = transactionReceipt.getLogs();
       if(logs==null||logs.isEmpty()){
       	 throw new TransactionException("TransactionReceipt logs is empty");
       }

	String logData = logs.get(0).getData();
	if(null == logData || "".equals(logData) ){
		throw new TransactionException("TransactionReceipt log data is empty");
	}

       RlpList rlp = RlpDecoder.decode(Numeric.hexStringToByteArray(logData));
       List<RlpType> rlpList = ((RlpList)(rlp.getValues().get(0))).getValues();
       String decodedStatus = new String(((RlpString)rlpList.get(0)).getBytes());
       int statusCode = Integer.parseInt(decodedStatus);
       
       TransactionResponse transactionResponse = new TransactionResponse();
       transactionResponse.setCode(statusCode);
       transactionResponse.setTransactionReceipt(transactionReceipt);
       
       return transactionResponse;
}
 
Example 6
Source Project: web3j   Source File: ContractTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDeployInvalidContractAddress() throws Throwable {
    TransactionReceipt transactionReceipt = new TransactionReceipt();
    transactionReceipt.setTransactionHash(TRANSACTION_HASH);

    prepareTransaction(transactionReceipt);
    ContractGasProvider contractGasProvider = new DefaultGasProvider();
    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Collections.<Type>singletonList(new Uint256(BigInteger.TEN)));
    assertThrows(
            RuntimeException.class,
            () ->
                    TestContract.deployRemoteCall(
                                    TestContract.class,
                                    web3j,
                                    SampleKeys.CREDENTIALS,
                                    contractGasProvider,
                                    "0xcafed00d",
                                    encodedConstructor,
                                    BigInteger.ZERO)
                            .send());
}
 
Example 7
private TransactionReceipt performTransfer(
        Web3j web3j, String destinationAddress, Credentials credentials,
        BigDecimal amountInWei) {

    console.printf("Commencing transfer (this may take a few minutes) ");
    try {
        Future<TransactionReceipt> future = Transfer.sendFunds(
                web3j, credentials, destinationAddress, amountInWei, Convert.Unit.WEI)
                .sendAsync();

        while (!future.isDone()) {
            console.printf(".");
            Thread.sleep(500);
        }
        console.printf("$%n%n");
        return future.get();
    } catch (InterruptedException | ExecutionException | TransactionException | IOException e) {
        exitError("Problem encountered transferring funds: \n" + e.getMessage());
    }
    throw new RuntimeException("Application exit failure");
}
 
Example 8
Source Project: client-sdk-java   Source File: ContractTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testStaticGasProvider() throws IOException, TransactionException {
    ContractGasProvider gasProvider = new ContractGasProvider(BigInteger.TEN, BigInteger.ONE);
    TransactionManager txManager = mock(TransactionManager.class);
    when(txManager.executeTransaction(any(), any(), any(), any(), any()))
            .thenReturn(new TransactionReceipt());

    contract = new TestContract(ADDRESS, web3j, txManager, gasProvider);

    Function func = new Function("test",
            Arrays.<Type>asList(), Collections.<TypeReference<?>>emptyList());
    contract.executeTransaction(func);

    verify(txManager).executeTransaction(eq(BigInteger.TEN),
            eq(BigInteger.ONE), any(), any(), any());
}
 
Example 9
Source Project: client-sdk-java   Source File: DelegateContract.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *  获得解除委托时所提取的委托收益(当减持/撤销委托成功时调用)
 *
 * @param transactionReceipt
 * @return
 * @throws TransactionException
 */
public BigInteger decodeUnDelegateLog(TransactionReceipt transactionReceipt) throws TransactionException {
    List<Log> logs = transactionReceipt.getLogs();
    if(logs==null||logs.isEmpty()){
        throw new TransactionException("TransactionReceipt logs is empty");
    }

    String logData = logs.get(0).getData();
    if(null == logData || "".equals(logData) ){
        throw new TransactionException("TransactionReceipt logs[0].data is empty");
    }

    RlpList rlp = RlpDecoder.decode(Numeric.hexStringToByteArray(logData));
    List<RlpType> rlpList = ((RlpList)(rlp.getValues().get(0))).getValues();
    String decodedStatus = new String(((RlpString)rlpList.get(0)).getBytes());
    int statusCode = Integer.parseInt(decodedStatus);

    if(statusCode != ErrorCode.SUCCESS){
        throw new TransactionException("TransactionResponse code is 0");
    }

    return  ((RlpString)((RlpList)RlpDecoder.decode(((RlpString)rlpList.get(1)).getBytes())).getValues().get(0)).asPositiveBigInteger();
}
 
Example 10
@Test
public void testFibonacciNotify() throws Exception {
    Fibonacci fibonacci = Fibonacci.load(
            "0x3c05b2564139fb55820b18b72e94b2178eaace7d", Web3j.build(new HttpService()),
            ALICE, GAS_PRICE, GAS_LIMIT);

    TransactionReceipt transactionReceipt = fibonacci.fibonacciNotify(
            BigInteger.valueOf(15)).send();

    Fibonacci.NotifyEventResponse result = fibonacci.getNotifyEvents(transactionReceipt).get(0);

    assertThat(result.input,
            equalTo(new Uint256(BigInteger.valueOf(15))));

    assertThat(result.result,
            equalTo(new Uint256(BigInteger.valueOf(610))));
}
 
Example 11
Source Project: web3j   Source File: Scenario.java    License: Apache License 2.0 6 votes vote down vote up
private Optional<TransactionReceipt> getTransactionReceipt(
        String transactionHash, int sleepDuration, int attempts) throws Exception {

    Optional<TransactionReceipt> receiptOptional =
            sendTransactionReceiptRequest(transactionHash);
    for (int i = 0; i < attempts; i++) {
        if (!receiptOptional.isPresent()) {
            Thread.sleep(sleepDuration);
            receiptOptional = sendTransactionReceiptRequest(transactionHash);
        } else {
            break;
        }
    }

    return receiptOptional;
}
 
Example 12
Source Project: web3j   Source File: RevertReasonExtractor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Extracts the error reason of a reverted transaction (if one exists and enabled).
 *
 * @param transactionReceipt the reverted transaction receipt
 * @param data the reverted transaction data
 * @param web3j Web3j instance
 * @param revertReasonCallEnabled flag of reason retrieval via additional call
 * @return the reverted transaction error reason if exists or null otherwise
 * @throws IOException if the call to the node fails
 */
public static String extractRevertReason(
        TransactionReceipt transactionReceipt,
        String data,
        Web3j web3j,
        Boolean revertReasonCallEnabled)
        throws IOException {

    if (transactionReceipt.getRevertReason() != null) {
        return transactionReceipt.getRevertReason();
    } else if (revertReasonCallEnabled) {
        String revertReason = retrieveRevertReason(transactionReceipt, data, web3j);
        if (revertReason != null) {
            transactionReceipt.setRevertReason(revertReason);
            return revertReason;
        }
    }
    return MISSING_REASON;
}
 
Example 13
Source Project: web3j   Source File: ContractTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTransactionFailedWithRevertReason() throws Exception {
    TransactionReceipt transactionReceipt = createFailedTransactionReceipt();
    prepareCall(OWNER_REVERT_MSG_HASH);

    TransactionException thrown =
            assertThrows(
                    TransactionException.class,
                    () -> {
                        prepareTransaction(transactionReceipt);

                        contract.performTransaction(
                                        new Address(BigInteger.TEN),
                                        new Uint256(BigInteger.ONE))
                                .send();
                    });

    assertEquals(
            String.format(
                    "Transaction %s has failed with status: %s. Gas used: 1. Revert reason: '%s'.",
                    TRANSACTION_HASH, TXN_FAIL_STATUS, OWNER_REVERT_MSG_STR),
            thrown.getMessage());
    assertEquals(transactionReceipt, thrown.getTransactionReceipt().get());
}
 
Example 14
@Test
public void testTransactionReceiptIsStatusOK() {
    TransactionReceipt transactionReceipt = new TransactionReceipt();
    transactionReceipt.setStatus("0x1");
    assertThat(transactionReceipt.isStatusOK(), equalTo(true));

    TransactionReceipt transactionReceiptNoStatus = new TransactionReceipt();
    assertThat(transactionReceiptNoStatus.isStatusOK(), equalTo(true));

    TransactionReceipt transactionReceiptZeroStatus = new TransactionReceipt();
    transactionReceiptZeroStatus.setStatus("0x0");
    assertThat(transactionReceiptZeroStatus.isStatusOK(), equalTo(false));
}
 
Example 15
Source Project: ethsigner   Source File: Contracts.java    License: Apache License 2.0 5 votes vote down vote up
public String address(final String hash) {
  return failOnIOException(
      () -> {
        final TransactionReceipt receipt =
            getTransactionReceipt(hash)
                .orElseThrow(() -> new RuntimeException("No receipt found for hash: " + hash));
        assertThat(receipt.getContractAddress()).isNotEmpty();
        return receipt.getContractAddress();
      });
}
 
Example 16
@Test
public void testTransaction() throws Exception {
    TransactionReceipt transactionReceipt = new TransactionReceipt();
    transactionReceipt.setTransactionHash(TRANSACTION_HASH);
    transactionReceipt.setStatus("0x1");

    prepareTransaction(transactionReceipt);

    assertThat(contract.performTransaction(
            new Address(BigInteger.TEN), new Uint256(BigInteger.ONE)).send(),
            is(transactionReceipt));
}
 
Example 17
public RemoteFunctionCall<TransactionReceipt> addParticipants(
    byte[] _enclaveKey, List<byte[]> _accounts) {
  final org.web3j.abi.datatypes.Function function =
      new org.web3j.abi.datatypes.Function(
          FUNC_ADDPARTICIPANTS,
          Arrays.<Type>asList(
              new org.web3j.abi.datatypes.generated.Bytes32(_enclaveKey),
              new org.web3j.abi.datatypes.DynamicArray<org.web3j.abi.datatypes.generated.Bytes32>(
                  org.web3j.abi.datatypes.generated.Bytes32.class,
                  org.web3j.abi.Utils.typeMap(
                      _accounts, org.web3j.abi.datatypes.generated.Bytes32.class))),
          Collections.<TypeReference<?>>emptyList());
  return executeRemoteCallTransaction(function);
}
 
Example 18
Source Project: Android-Wallet-Token-ERC20   Source File: TokenERC20.java    License: Apache License 2.0 5 votes vote down vote up
public List<TransferEventResponse> getTransferEvents(TransactionReceipt transactionReceipt) {
    final Event event = new Event("Transfer", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
    ArrayList<TransferEventResponse> responses = new ArrayList<TransferEventResponse>(valueList.size());
    for (EventValues eventValues : valueList) {
        TransferEventResponse typedResponse = new TransferEventResponse();
        typedResponse.from = (String) eventValues.getIndexedValues().get(0).getValue();
        typedResponse.to = (String) eventValues.getIndexedValues().get(1).getValue();
        typedResponse.value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example 19
public RemoteFunctionCall<TransactionReceipt> removeParticipant(
    byte[] enclaveKey, byte[] account) {
  final Function function =
      new Function(
          FUNC_REMOVEPARTICIPANT,
          Arrays.<Type>asList(
              new org.web3j.abi.datatypes.generated.Bytes32(enclaveKey),
              new org.web3j.abi.datatypes.generated.Bytes32(account)),
          Collections.<TypeReference<?>>emptyList());
  return executeRemoteCallTransaction(function);
}
 
Example 20
Source Project: web3j-quorum   Source File: HumanStandardToken.java    License: Apache License 2.0 5 votes vote down vote up
public List<TransferEventResponse> getTransferEvents(TransactionReceipt transactionReceipt) {
    List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(TRANSFER_EVENT, transactionReceipt);
    ArrayList<TransferEventResponse> responses = new ArrayList<TransferEventResponse>(valueList.size());
    for (Contract.EventValuesWithLog eventValues : valueList) {
        TransferEventResponse typedResponse = new TransferEventResponse();
        typedResponse.log = eventValues.getLog();
        typedResponse._from = (String) eventValues.getIndexedValues().get(0).getValue();
        typedResponse._to = (String) eventValues.getIndexedValues().get(1).getValue();
        typedResponse._value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example 21
Source Project: web3j   Source File: SimpleStorage.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> set(BigInteger x) {
    final Function function = new Function(
            FUNC_SET, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(x)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example 22
Source Project: besu   Source File: EthGetTransactionReceiptTransaction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Optional<TransactionReceipt> execute(final NodeRequests node) {
  try {
    final EthGetTransactionReceipt result = node.eth().ethGetTransactionReceipt(input).send();
    assertThat(result.hasError()).isFalse();
    return result.getTransactionReceipt();
  } catch (final IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example 23
public RemoteCall<TransactionReceipt> setName(byte[] node, String name) {
    Function function = new Function(
            "setName",
            Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Bytes32(node),
            new org.web3j.abi.datatypes.Utf8String(name)),
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example 24
Source Project: besu   Source File: ExpectValidTransactionReceipt.java    License: Apache License 2.0 5 votes vote down vote up
public void verify(final Contract contract) {

    assertThat(contract).isNotNull();
    final Optional<TransactionReceipt> receipt = contract.getTransactionReceipt();

    // We're expecting a receipt
    assertThat(receipt).isNotNull();
    assertThat(receipt.isPresent()).isTrue();
    final TransactionReceipt transactionReceipt = receipt.get();

    // Contract transaction has no 'to' address or contract address
    assertThat(transactionReceipt.getTo()).isNull();
    assertThat(transactionReceipt.getRoot()).isNull();

    // Variables outside the control of the test :. just check existence
    assertThat(transactionReceipt.getBlockHash()).isNotBlank();
    assertThat(transactionReceipt.getTransactionHash()).isNotBlank();
    assertThat(transactionReceipt.getTransactionIndex()).isNotNull();
    assertThat(transactionReceipt.getTransactionHash()).isNotNull();

    // Block zero is the genesis, expecting anytime after then
    assertThat(transactionReceipt.getBlockNumber()).isGreaterThanOrEqualTo(BigInteger.ONE);

    // Address generation is deterministic, based on the sender address and the transaction nonce
    assertThat(transactionReceipt.getContractAddress()).isEqualTo(contractAddress);

    // Expecting successful transaction (status '0x1')
    assertThat(transactionReceipt.getStatus()).isEqualTo("0x1");

    // Address for the account that signed (and paid) for the contract deployment transaction
    assertThat(transactionReceipt.getFrom()).isEqualTo(senderAddress);

    // No logs from expected from the contract deployment
    assertThat(transactionReceipt.getLogs()).isNotNull();
    assertThat(transactionReceipt.getLogs().size()).isEqualTo(0);
    assertThat(transactionReceipt.getLogsBloom())
        .isEqualTo(
            "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
  }
 
Example 25
public List<PubkeyChangedEventResponse> getPubkeyChangedEvents(TransactionReceipt transactionReceipt) {
    final Event event = new Event("PubkeyChanged", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Bytes32>() {}, new TypeReference<Bytes32>() {}));
    List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
    ArrayList<PubkeyChangedEventResponse> responses = new ArrayList<PubkeyChangedEventResponse>(valueList.size());
    for (EventValues eventValues : valueList) {
        PubkeyChangedEventResponse typedResponse = new PubkeyChangedEventResponse();
        typedResponse.node = (byte[]) eventValues.getIndexedValues().get(0).getValue();
        typedResponse.x = (byte[]) eventValues.getNonIndexedValues().get(0).getValue();
        typedResponse.y = (byte[]) eventValues.getNonIndexedValues().get(1).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
Example 26
Source Project: web3j   Source File: ERC721.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> safeTransferFrom(String _from, String _to, BigInteger _tokenId, BigInteger weiValue) {
    final Function function = new Function(
            FUNC_SAFETRANSFERFROM, 
            Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(_from), 
            new org.web3j.abi.datatypes.Address(_to), 
            new org.web3j.abi.datatypes.generated.Uint256(_tokenId)), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function, weiValue);
}
 
Example 27
@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }
    if (!(o instanceof TransactionReceipt)) {
        return false;
    }

    TransactionReceipt that = (TransactionReceipt) o;

    return getTransactionHash() != null
            ? getTransactionHash().equals(that.getTransactionHash())
            : that.getTransactionHash() == null;
}
 
Example 28
Source Project: client-sdk-java   Source File: BaseContract.java    License: Apache License 2.0 5 votes vote down vote up
private TransactionResponse executeTransaction(Function function, BigInteger weiValue, GasProvider gasProvider)throws TransactionException, IOException {

    	TransactionReceipt receipt = send(contractAddress, EncoderUtils.functionEncoder(function), weiValue,
             gasProvider.getGasPrice(),
             gasProvider.getGasLimit());

    	return getResponseFromTransactionReceipt(receipt);
    }
 
Example 29
Source Project: etherscan-explorer   Source File: Arrays.java    License: GNU General Public License v3.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> dynamicReverse(List<BigInteger> input) {
    final Function function = new Function(
            "dynamicReverse", 
            java.util.Arrays.<Type>asList(new org.web3j.abi.datatypes.DynamicArray<org.web3j.abi.datatypes.generated.Uint256>(
                    org.web3j.abi.Utils.typeMap(input, org.web3j.abi.datatypes.generated.Uint256.class))), 
            Collections.<TypeReference<?>>emptyList());
    return executeRemoteCallTransaction(function);
}
 
Example 30
public void getTxReceipt(final String txHash, final Callback<TransactionReceipt> callback) {
    if (web3jConnection != null && connectionAvailable) {
        TxReceiptRequestTask task = new TxReceiptRequestTask(txHash, callback);
        task.execute();
    } else {
        provideConnection(new ConnectionCallback() {
            @Override
            public void onFinish() {
                getTxReceipt(txHash, callback);
            }
        });
    }
}