Java Code Examples for org.web3j.protocol.core.methods.response.TransactionReceipt#isStatusOK()

The following examples show how to use org.web3j.protocol.core.methods.response.TransactionReceipt#isStatusOK() . 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 File: Contract.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
/**
 * Given the duration required to execute a transaction.
 *
 * @param data  to send in transaction
 * @param weiValue in Wei to send in transaction
 * @return {@link Optional} containing our transaction receipt
 * @throws IOException                 if the call to the node fails
 * @throws TransactionException if the transaction was not mined while waiting
 */
TransactionReceipt executeTransaction(
        String data, BigInteger weiValue, String funcName)
        throws TransactionException, IOException {

    TransactionReceipt receipt = send(contractAddress, data, weiValue,
            gasProvider.getGasPrice(),
            gasProvider.getGasLimit());

    if (!receipt.isStatusOK()) {
        throw new TransactionException(
                String.format(
                        "Transaction has failed with status: %s. "
                                + "Gas used: %d. (not-enough gas?)",
                        receipt.getStatus(),
                        receipt.getGasUsed()));
    }

    return receipt;
}
 
Example 2
Source File: Contract.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Given the duration required to execute a transaction.
 *
 * @param data  to send in transaction
 * @param weiValue in Wei to send in transaction
 * @return {@link Optional} containing our transaction receipt
 * @throws IOException                 if the call to the node fails
 * @throws TransactionException if the transaction was not mined while waiting
 */
TransactionReceipt executeTransaction(
        String data, BigInteger weiValue)
        throws TransactionException, IOException {

    TransactionReceipt receipt = send(contractAddress, data, weiValue, gasPrice, gasLimit);

    if (!receipt.isStatusOK()) {
        throw new TransactionException(
                String.format(
                        "Transaction has failed with status: %s. "
                                + "Gas used: %d. (not-enough gas?)",
                        receipt.getStatus(),
                        receipt.getGasUsed()));
    }

    return receipt;
}
 
Example 3
Source File: PrivateTransactionManager.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Override
public String sendCall(
        final String to, final String data, final DefaultBlockParameter defaultBlockParameter)
        throws IOException {
    try {
        EthSendTransaction est =
                sendTransaction(
                        gasProvider.getGasPrice(),
                        gasProvider.getGasLimit(),
                        to,
                        data,
                        BigInteger.ZERO);
        final TransactionReceipt ptr = processResponse(est);

        if (!ptr.isStatusOK()) {
            throw new ContractCallException(
                    String.format(REVERT_ERR_STR, extractRevertReason(ptr, data, besu, false)));
        }
        return ((PrivateTransactionReceipt) ptr).getOutput();
    } catch (TransactionException e) {
        log.error("Failed to execute call", e);
        return null;
    }
}
 
Example 4
Source File: WasmContract.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
TransactionReceipt executeTransaction(String data, BigInteger vonValue) throws TransactionException, IOException {

		TransactionReceipt receipt = send(contractAddress, data, vonValue, gasProvider.getGasPrice(), gasProvider.getGasLimit());

		if (!receipt.isStatusOK()) {
			throw new TransactionException(String.format("Transaction has failed with status: %s. " + "Gas used: %d. (not-enough gas?)",
					receipt.getStatus(), receipt.getGasUsed()));
		}

		return receipt;
	}
 
Example 5
Source File: Contract.java    From web3j with Apache License 2.0 5 votes vote down vote up
/**
 * Given the duration required to execute a transaction.
 *
 * @param data to send in transaction
 * @param weiValue in Wei to send in transaction
 * @return {@link Optional} containing our transaction receipt
 * @throws IOException if the call to the node fails
 * @throws TransactionException if the transaction was not mined while waiting
 */
TransactionReceipt executeTransaction(
        String data, BigInteger weiValue, String funcName, boolean constructor)
        throws TransactionException, IOException {

    TransactionReceipt receipt =
            send(
                    contractAddress,
                    data,
                    weiValue,
                    gasProvider.getGasPrice(funcName),
                    gasProvider.getGasLimit(funcName),
                    constructor);

    if (!receipt.isStatusOK()) {
        throw new TransactionException(
                String.format(
                        "Transaction %s has failed with status: %s. "
                                + "Gas used: %s. "
                                + "Revert reason: '%s'.",
                        receipt.getTransactionHash(),
                        receipt.getStatus(),
                        receipt.getGasUsedRaw() != null
                                ? receipt.getGasUsed().toString()
                                : "unknown",
                        extractRevertReason(receipt, data, web3j, true)),
                receipt);
    }
    return receipt;
}