Search in sources :

Example 6 with Web3j

use of org.bcos.web3j.protocol.Web3j in project web3sdk by FISCO-BCOS.

the class WalletSendFunds method run.

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)) {
        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());
}
Also used : Web3j(org.bcos.web3j.protocol.Web3j) Convert(org.bcos.web3j.utils.Convert) TransactionReceipt(org.bcos.web3j.protocol.core.methods.response.TransactionReceipt) File(java.io.File) Credentials(org.bcos.web3j.crypto.Credentials) BigDecimal(java.math.BigDecimal)

Aggregations

Web3j (org.bcos.web3j.protocol.Web3j)6 Credentials (org.bcos.web3j.crypto.Credentials)5 BigInteger (java.math.BigInteger)4 Service (org.bcos.channel.client.Service)4 ECKeyPair (org.bcos.web3j.crypto.ECKeyPair)4 ChannelEthereumService (org.bcos.web3j.protocol.channel.ChannelEthereumService)4 ApplicationContext (org.springframework.context.ApplicationContext)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 TransactionReceipt (org.bcos.web3j.protocol.core.methods.response.TransactionReceipt)3 Address (org.bcos.web3j.abi.datatypes.Address)2 Type (org.bcos.web3j.abi.datatypes.Type)2 Utf8String (org.bcos.web3j.abi.datatypes.Utf8String)2 Uint256 (org.bcos.web3j.abi.datatypes.generated.Uint256)2 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 ExecutionException (java.util.concurrent.ExecutionException)1 ChannelRequest (org.bcos.channel.dto.ChannelRequest)1 ChannelResponse (org.bcos.channel.dto.ChannelResponse)1 Bool (org.bcos.web3j.abi.datatypes.Bool)1 Int256 (org.bcos.web3j.abi.datatypes.generated.Int256)1