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.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Abhishek Saini
Abhishek is bright Lead developer with skills in AngularJS and Java. He loves to learn new technologies.