Java Code Examples for org.web3j.utils.Convert#Unit

The following examples show how to use org.web3j.utils.Convert#Unit . 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: Transfer.java    From web3j with Apache License 2.0 6 votes vote down vote up
private TransactionReceipt send(
        String toAddress,
        BigDecimal value,
        Convert.Unit unit,
        BigInteger gasPrice,
        BigInteger gasLimit)
        throws IOException, InterruptedException, TransactionException {

    BigDecimal weiValue = Convert.toWei(value, unit);
    if (!Numeric.isIntegerValue(weiValue)) {
        throw new UnsupportedOperationException(
                "Non decimal Wei value provided: "
                        + value
                        + " "
                        + unit.toString()
                        + " = "
                        + weiValue
                        + " Wei");
    }

    String resolvedAddress = ensResolver.resolve(toAddress);
    return send(resolvedAddress, "", weiValue.toBigIntegerExact(), gasPrice, gasLimit);
}
 
Example 2
Source File: Transfer.java    From web3j with Apache License 2.0 6 votes vote down vote up
private TransactionReceipt sendEIP1559(
        String toAddress,
        BigDecimal value,
        Convert.Unit unit,
        BigInteger gasLimit,
        BigInteger gasPremium,
        BigInteger feeCap)
        throws IOException, InterruptedException, TransactionException {

    BigDecimal weiValue = Convert.toWei(value, unit);
    if (!Numeric.isIntegerValue(weiValue)) {
        throw new UnsupportedOperationException(
                "Non decimal Wei value provided: "
                        + value
                        + " "
                        + unit.toString()
                        + " = "
                        + weiValue
                        + " Wei");
    }

    String resolvedAddress = ensResolver.resolve(toAddress);
    return sendEIP1559(
            resolvedAddress, "", weiValue.toBigIntegerExact(), gasLimit, gasPremium, feeCap);
}
 
Example 3
Source File: WalletSendFunds.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
private Convert.Unit getTransferUnit() {
    String unit = console.readLine("Please specify the unit (ether, wei, ...) [ether]: ")
            .trim();

    Convert.Unit transferUnit;
    if (unit.equals("")) {
        transferUnit = Convert.Unit.ETHER;
    } else {
        transferUnit = Convert.Unit.fromString(unit.toLowerCase());
    }

    return transferUnit;
}
 
Example 4
Source File: Transfer.java    From web3j with Apache License 2.0 5 votes vote down vote up
public static RemoteCall<TransactionReceipt> sendFunds(
        Web3j web3j,
        Credentials credentials,
        String toAddress,
        BigDecimal value,
        Convert.Unit unit)
        throws InterruptedException, IOException, TransactionException {

    TransactionManager transactionManager = new RawTransactionManager(web3j, credentials);

    return new RemoteCall<>(
            () -> new Transfer(web3j, transactionManager).send(toAddress, value, unit));
}
 
Example 5
Source File: Transfer.java    From web3j with Apache License 2.0 5 votes vote down vote up
public RemoteCall<TransactionReceipt> sendFunds(
        String toAddress,
        BigDecimal value,
        Convert.Unit unit,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    return new RemoteCall<>(() -> send(toAddress, value, unit, gasPrice, gasLimit));
}
 
Example 6
Source File: Transfer.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
public static RemoteCall<TransactionReceipt> sendFunds(
        Web3j web3j, Credentials credentials,
        String toAddress, BigDecimal value, Convert.Unit unit) throws InterruptedException,
        IOException, TransactionException {

    TransactionManager transactionManager = new RawTransactionManager(web3j, credentials);

    return new RemoteCall<>(() ->
            new Transfer(web3j, transactionManager).send(toAddress, value, unit));
}
 
Example 7
Source File: Transfer.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
private TransactionReceipt send(
        String toAddress, BigDecimal value, Convert.Unit unit, BigInteger gasPrice,
        BigInteger gasLimit) throws IOException, InterruptedException,
        TransactionException {

    BigDecimal weiValue = Convert.toWei(value, unit);
    if (!Numeric.isIntegerValue(weiValue)) {
        throw new UnsupportedOperationException(
                "Non decimal Wei value provided: " + value + " " + unit.toString()
                        + " = " + weiValue + " Wei");
    }

    String resolvedAddress = ensResolver.resolve(toAddress);
    return send(resolvedAddress, "", weiValue.toBigIntegerExact(), gasPrice, gasLimit);
}
 
Example 8
Source File: WalletSendFunds.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
private void confirmTransfer(
        BigDecimal amountToTransfer, Convert.Unit transferUnit, BigDecimal amountInWei,
        String destinationAddress) {

    console.printf("Please confim that you wish to transfer %s %s (%s %s) to address %s%n",
            amountToTransfer.stripTrailingZeros().toPlainString(), transferUnit,
            amountInWei.stripTrailingZeros().toPlainString(),
            Convert.Unit.WEI, destinationAddress);
    String confirm = console.readLine("Please type 'yes' to proceed: ").trim();
    if (!confirm.toLowerCase().equals("yes")) {
        exitError("OK, some other time perhaps...");
    }
}
 
Example 9
Source File: WalletSendFunds.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
private void run(String walletFileLocation, String destinationAddress) {
    File walletFile = new File(walletFileLocation);
    Credentials credentials = getCredentials(walletFile);
    console.printf("Wallet for address " + credentials.getAddress() + " loaded\n");

    if (!WalletUtils.isValidAddress(destinationAddress)
            && !EnsResolver.isValidEnsName(destinationAddress)) {
        exitError("Invalid destination address specified");
    }

    Web3j web3j = getEthereumClient();

    BigDecimal amountToTransfer = getAmountToTransfer();
    Convert.Unit transferUnit = getTransferUnit();
    BigDecimal amountInWei = Convert.toWei(amountToTransfer, transferUnit);

    confirmTransfer(amountToTransfer, transferUnit, amountInWei, destinationAddress);

    TransactionReceipt transactionReceipt = performTransfer(
            web3j, destinationAddress, credentials, amountInWei);

    console.printf("Funds have been successfully transferred from %s to %s%n"
                    + "Transaction hash: %s%nMined block number: %s%n",
            credentials.getAddress(),
            destinationAddress,
            transactionReceipt.getTransactionHash(),
            transactionReceipt.getBlockNumber());
}
 
Example 10
Source File: TransferTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
protected TransactionReceipt sendFunds(
        Credentials credentials, String toAddress, BigDecimal value, Convert.Unit unit)
        throws Exception {
    return new Transfer(web3j, getVerifiedTransactionManager(credentials))
            .sendFunds(toAddress, value, unit)
            .send();
}
 
Example 11
Source File: Transfer.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
public static RemoteCall<TransactionReceipt> sendFunds(
        Web3j web3j, Credentials credentials, String chainId,
        String toAddress, BigDecimal value, Convert.Unit unit) throws InterruptedException,
        IOException, TransactionException {

    TransactionManager transactionManager = new RawTransactionManager(web3j, credentials, Long.valueOf(chainId));

    return new RemoteCall<>(() ->
            new Transfer(web3j, transactionManager).send(toAddress, value, unit));
}
 
Example 12
Source File: Transfer.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
private TransactionReceipt send(String toAddress, BigDecimal value, Convert.Unit unit, BigInteger gasPrice,
                                BigInteger gasLimit) throws IOException, InterruptedException,
        TransactionException {

    BigDecimal weiValue = Convert.toVon(value, unit);
    if (!Numeric.isIntegerValue(weiValue)) {
        throw new UnsupportedOperationException(
                "Non decimal Wei value provided: " + value + " " + unit.toString()
                        + " = " + weiValue + " Wei");
    }

    return send(toAddress, "", weiValue.toBigIntegerExact(), gasPrice, gasLimit);
}
 
Example 13
Source File: WalletSendFunds.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
private void confirmTransfer(
        BigDecimal amountToTransfer, Convert.Unit transferUnit, BigDecimal amountInWei,
        String destinationAddress) {

    console.printf("Please confim that you wish to transfer %s %s (%s %s) to address %s%n",
            amountToTransfer.stripTrailingZeros().toPlainString(), transferUnit,
            amountInWei.stripTrailingZeros().toPlainString(),
            Convert.Unit.VON, destinationAddress);
    String confirm = console.readLine("Please type 'yes' to proceed: ").trim();
    if (!confirm.toLowerCase().equals("yes")) {
        exitError("OK, some other time perhaps...");
    }
}
 
Example 14
Source File: WalletSendFunds.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
private Convert.Unit getTransferUnit() {
    String unit = console.readLine("Please specify the unit (ether, wei, ...) [ether]: ")
            .trim();

    Convert.Unit transferUnit;
    if (unit.equals("")) {
        transferUnit = Convert.Unit.LAT;
    } else {
        transferUnit = Convert.Unit.fromString(unit.toLowerCase());
    }

    return transferUnit;
}
 
Example 15
Source File: TransferTest.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
protected TransactionReceipt sendFunds(Credentials credentials, String toAddress,
                                       BigDecimal value, Convert.Unit unit) throws Exception {
    return new Transfer(web3j, getVerifiedTransactionManager(credentials))
            .sendFunds(toAddress, value, unit).send();
}
 
Example 16
Source File: Transfer.java    From etherscan-explorer with GNU General Public License v3.0 4 votes vote down vote up
public RemoteCall<TransactionReceipt> sendFunds(
        String toAddress, BigDecimal value, Convert.Unit unit, BigInteger gasPrice,
        BigInteger gasLimit) {
    return new RemoteCall<>(() -> send(toAddress, value, unit, gasPrice, gasLimit));
}
 
Example 17
Source File: Transfer.java    From client-sdk-java with Apache License 2.0 3 votes vote down vote up
/**
 * Given the duration required to execute a transaction, asyncronous execution is strongly
 * recommended via {@link Transfer#sendFunds(String, BigDecimal, Convert.Unit)}.
 *
 * @param toAddress destination address
 * @param value     amount to send
 * @param unit      of specified send
 * @return {@link Optional} containing our transaction receipt
 * @throws ExecutionException   if the computation threw an
 *                              exception
 * @throws InterruptedException if the current thread was interrupted
 *                              while waiting
 * @throws TransactionException if the transaction was not mined while waiting
 */
private TransactionReceipt send(String toAddress, BigDecimal value, Convert.Unit unit)
        throws IOException, InterruptedException,
        TransactionException {

    BigInteger gasPrice = requestCurrentGasPrice();
    return send(toAddress, value, unit, gasPrice, GAS_LIMIT);
}
 
Example 18
Source File: Transfer.java    From web3j with Apache License 2.0 2 votes vote down vote up
/**
 * Execute the provided function as a transaction asynchronously. This is intended for one-off
 * fund transfers. For multiple, create an instance.
 *
 * @param toAddress destination address
 * @param value amount to send
 * @param unit of specified send
 * @return {@link RemoteCall} containing executing transaction
 */
public RemoteCall<TransactionReceipt> sendFunds(
        String toAddress, BigDecimal value, Convert.Unit unit) {
    return new RemoteCall<>(() -> send(toAddress, value, unit));
}
 
Example 19
Source File: Transfer.java    From client-sdk-java with Apache License 2.0 2 votes vote down vote up
/**
 * Execute the provided function as a transaction asynchronously. This is intended for one-off
 * fund transfers. For multiple, create an instance.
 *
 * @param toAddress destination address
 * @param value     amount to send
 * @param unit      of specified send
 * @return {@link RemoteCall} containing executing transaction
 */
public RemoteCall<TransactionReceipt> sendFunds(
        String toAddress, BigDecimal value, Convert.Unit unit) {
    return new RemoteCall<>(() -> send(toAddress, value, unit));
}
 
Example 20
Source File: Transfer.java    From etherscan-explorer with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Execute the provided function as a transaction asynchronously. This is intended for one-off
 * fund transfers. For multiple, create an instance.
 *
 * @param toAddress destination address
 * @param value amount to send
 * @param unit of specified send
 *
 * @return {@link RemoteCall} containing executing transaction
 */
public RemoteCall<TransactionReceipt> sendFunds(
        String toAddress, BigDecimal value, Convert.Unit unit) {
    return new RemoteCall<>(() -> send(toAddress, value, unit));
}