Withdraw Ethereum ERC20 token using web3j

Posted By : Abhishek Saini | 28-Oct-2017

Ethereum,the popular cryptocurrency and blockchain system, is based on the use of tokens which can be bought, sold, or traded. There are several different tokens which may be used in conjunction with Ethereum,and these differ from ether.We can trasfer tokens to user ethereum address and also get it back from user address to contract.

 

After making and compiling .sol file using solodity compiler we can create wrapper class in which we can access all our contract fuctions to do transactions. We can simply get tokens back from client to contract by loading contract using client credentials like :

 

Also we make sure that before executing any transactions from any account ,that account must have some ether as transation fee.The transaction fee will be deducted from the account that is withdrawing token.

 

Web3j web3j = Web3j.build(new HttpService("http://localhost:8545"));  //change url to your blockchain server url 

Credentials credentials = WalletUtils.loadCredentials("client password","client ketstore file path"); 

BigInteger gasprice = web3j.ethGasPrice().send().getGasPrice();
BigInteger gaslimit = BigInteger.valueOf(90000);

Mycontract contractObj = Mycontract.load("contract address", web3j, credentials, gasprice,gaslimit)

TransactionReceipt balanceOf = contractObj.transfer(new Address("contract adddress"), transferBalance).get();

 

Hope this will help.

Thank you.

About Author

Author Image
Abhishek Saini

Abhishek is bright Lead developer with skills in AngularJS and Java. He loves to learn new technologies.

Request for Proposal

Name is required

Comment is required

Sending message..