org.web3j.tx.Transfer Java Examples

The following examples show how to use org.web3j.tx.Transfer. 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: TransferEtherTest.java    From web3j_demo with Apache License 2.0 6 votes vote down vote up
/**
 * Ether transfer tests using methods {@link Transfer#sendFunds()}.
 * Sending account needs to be unlocked for this to work.   
 */
@Test
public void testSendFunds() throws Exception {
	BigDecimal amountEther = BigDecimal.valueOf(0.123);
	BigInteger amountWei = Convert.toWei(amountEther, Convert.Unit.ETHER).toBigInteger();

	ensureFunds(Alice.ADDRESS, amountWei);

	BigInteger fromBalanceBefore = getBalanceWei(Alice.ADDRESS);
	BigInteger toBalanceBefore = getBalanceWei(Bob.ADDRESS);

	// this is the method to test here
	TransactionReceipt txReceipt = Transfer.sendFunds(
			web3j, Alice.CREDENTIALS, Bob.ADDRESS, amountEther, Convert.Unit.ETHER);

	BigInteger txFees = txReceipt.getGasUsed().multiply(Web3jConstants.GAS_PRICE);

	assertFalse(txReceipt.getBlockHash().isEmpty());
	assertEquals("Unexected balance for 'from' address", fromBalanceBefore.subtract(amountWei.add(txFees)), getBalanceWei(Alice.ADDRESS));
	assertEquals("Unexected balance for 'to' address", toBalanceBefore.add(amountWei), getBalanceWei(Bob.ADDRESS));
}
 
Example #2
Source File: WalletSendFunds.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
private TransactionReceipt performTransfer(
        Web3j web3j, String destinationAddress,String chainId, Credentials credentials,
        BigDecimal amountInWei) {

    console.printf("Commencing transfer (this may take a few minutes) ");
    try {
        Future<TransactionReceipt> future = Transfer.sendFunds(
                web3j, credentials, destinationAddress,chainId, amountInWei, Convert.Unit.LAT)
                .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 #3
Source File: WalletSendFunds.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
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 #4
Source File: PayWagesTest.java    From client-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void transferToContract() throws Exception {
	String toAddress = contractAddress;

	// get balance
	PlatonGetBalance balance = web3j.platonGetBalance(toAddress, DefaultBlockParameterName.LATEST).send();
	System.err.println("Before transfer,balance >>> " + balance.getBalance().toString());

	// transfer to toAddress
	Transfer transfer = new Transfer(web3j, transactionManager);
	BigDecimal value = BigDecimal.valueOf(500L);
	TransactionReceipt receipt = transfer.sendFunds(toAddress, value, Convert.Unit.LAT, GAS_PRICE, GAS_LIMIT).send();
	System.err.println("transfer status >>> " + receipt.getStatus());
	System.err.println("transfer result >>> " + JSON.toJSONString(receipt));

	// transfer event
	PayWages payWages = PayWages.load(contractAddress, web3j, transactionManager, gasProvider);
	List<TransferEventResponse> list = payWages.getTransferEvents(receipt);
	System.err.println("to >>> " + list.get(0)._to);
	System.err.println("value >>> " + list.get(0)._value.toString());
	System.err.println("TransferEventResponse >>> " + JSON.toJSONString(list));

	// get balance
	balance = web3j.platonGetBalance(toAddress, DefaultBlockParameterName.LATEST).send();
	System.err.println("After transfer, balance >>> " + balance.getBalance().toString());
}
 
Example #5
Source File: FastRawTransactionManagerIT.java    From web3j with Apache License 2.0 5 votes vote down vote up
private RemoteCall<TransactionReceipt> createTransaction(
        Transfer transfer, BigInteger gasPrice) {
    return transfer.sendFunds(
            BOB.getAddress(),
            BigDecimal.valueOf(1.0),
            Convert.Unit.KWEI,
            gasPrice,
            Transfer.GAS_LIMIT);
}
 
Example #6
Source File: SendEtherIT.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransfer() throws Exception {
    TransactionReceipt transactionReceipt =
            Transfer.sendFunds(
                            web3j,
                            ALICE,
                            BOB.getAddress(),
                            BigDecimal.valueOf(0.2),
                            Convert.Unit.ETHER)
                    .send();
    assertFalse(transactionReceipt.getBlockHash().isEmpty());
}
 
Example #7
Source File: EthereumUtils.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
public static TransactionReceipt sendFundsToContract(Credentials credentials,
                                                     Web3j web3j,
                                                     int etherAmount,
                                                     String toAddress,
                                                     Transfer transfer) throws Exception {

    return transfer.sendFunds(
            toAddress,
            new BigDecimal(etherAmount),
            Convert.Unit.ETHER).send();
}
 
Example #8
Source File: SendEtherIT.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testTransfer() throws Exception {
    TransactionReceipt transactionReceipt = Transfer.sendFunds(
            web3j, ALICE, BOB.getAddress(), BigDecimal.valueOf(0.2), Convert.Unit.ETHER)
            .send();
    assertFalse(transactionReceipt.getBlockHash().isEmpty());
}
 
Example #9
Source File: RewardContractTest.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void transfer() throws Exception {
    Transfer.sendFunds(web3j, superCredentials, chainId, deleteCredentials.getAddress(), new BigDecimal("10000000"), Unit.LAT).send();
    System.out.println("stakingCredentials balance="+ web3j.platonGetBalance(deleteCredentials.getAddress(), DefaultBlockParameterName.LATEST).send().getBalance());
}
 
Example #10
Source File: ProposalContractTest.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void transfer() throws Exception {
	Transfer.sendFunds(web3j, superCredentials, chainId, stakingCredentials.getAddress(), new BigDecimal("10000"), Unit.LAT).send();
	System.out.println("stakingCredentials balance="+ web3j.platonGetBalance(stakingCredentials.getAddress(), DefaultBlockParameterName.LATEST).send().getBalance());
}
 
Example #11
Source File: StakingContractTest.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void transfer() throws Exception {
	Transfer.sendFunds(web3j, superCredentials, chainId, stakingCredentials.getAddress(), new BigDecimal("10000000"), Unit.LAT).send();
	System.out.println("stakingCredentials balance="+ web3j.platonGetBalance(stakingCredentials.getAddress(), DefaultBlockParameterName.LATEST).send().getBalance());
}
 
Example #12
Source File: FastRawTransactionManagerIT.java    From etherscan-explorer with GNU General Public License v3.0 4 votes vote down vote up
private RemoteCall<TransactionReceipt> createTransaction(
        Transfer transfer, BigInteger gasPrice) {
    return transfer.sendFunds(
            BOB.getAddress(), BigDecimal.valueOf(1.0), Convert.Unit.KWEI,
            gasPrice, Transfer.GAS_LIMIT);
}
 
Example #13
Source File: DelegateContractTest.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void transfer() throws Exception {
	Transfer.sendFunds(web3j, superCredentials, chainId, deleteCredentials.getAddress(), new BigDecimal("10000000"), Unit.LAT).send();
	System.out.println("stakingCredentials balance="+ web3j.platonGetBalance(deleteCredentials.getAddress(), DefaultBlockParameterName.LATEST).send().getBalance());
}
 
Example #14
Source File: SendEtherWorkitemHandler.java    From jbpm-work-items with Apache License 2.0 4 votes vote down vote up
public void setTransfer(Transfer transfer) {
    this.transfer = transfer;
}
 
Example #15
Source File: ProposalScenario.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
public void transfer() throws Exception {
    Transfer.sendFunds(web3j, superCredentials, chainId, proposalCredentials.getAddress(), transferValue, Unit.LAT).send();
    Transfer.sendFunds(web3j, superCredentials, chainId, voteCredentials.getAddress(), transferValue, Unit.LAT).send();
}
 
Example #16
Source File: StakingScenario.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
public void transfer() throws Exception {
    Transfer.sendFunds(web3j, superCredentials, chainId, stakingCredentials.getAddress(), transferValue, Unit.LAT).send();
    Transfer.sendFunds(web3j, superCredentials, chainId, delegateCredentials.getAddress(), transferValue, Unit.LAT).send();
}
 
Example #17
Source File: RestrictingScenario.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
public void transfer() throws Exception {
	Transfer.sendFunds(web3j, superCredentials, chainId, restrictingSendCredentials.getAddress(), transferValue, Unit.LAT).send();
}
 
Example #18
Source File: SlashScenario.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
public void transfer() throws Exception {
	Transfer.sendFunds(web3j, superCredentials, chainId, slashCredentials.getAddress(), transferValue, Unit.LAT).send();
}