Java Magazine, Jan/Feb 2017
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2017 46 cryptocurrency of tokens event Approval address indexed _ owner address indexed _ spender uint256 _ value Consensys has made available a full implementation of this smart contract which you can download and then compile with the Solidity compiler solc HumanStandardToken sol bin abi optimize o build You can then generate smart contract wrappers for this smart contract as shown next Again full paths are trimmed for brevity web3j 107 bin web3j solidity generate build HumanStandardToken bin build HumanStandardToken abi p org web3j example generated o src main java Youre now ready to work with some of your very own tokens and start issuing them deploy your smart contract HumanStandardToken contract HumanStandardToken deploy web3 credentials BigInteger ZERO new Uint256 BigInteger valueOf 1000000 new Utf8String web3j tokens new Uint8 BigInteger TEN new Utf8String w3j get print the total supply issued Uint256 totalSupply contract totalSupply get System out println Token supply issued totalSupply getValue check your token balance Uint256 balance contract balanceOf new Address credentials getAddress get System out println Your current balance is w3j balance getValue transfer tokens to another address TransactionReceipt transferReceipt contract transfer new Address 0x destination address new Uint256 BigInteger valueOf 100 get You can refer to this articles accompanying code for the full example Conclusion In this article I have scratched the surface of working with the Ethereum blockchain There are many further details I have had to gloss over or omit entirely but I hope this has given you some appreciation of what this fascinating technology is capable of For further information you can refer to the web3j project source code and the documentation which provides a lot more background information on Ethereum and web3j than I can fit into a single article article Conor Svensson @ conors10 is the author of web3j the Java library for integrating applications with the Ethereum blockchain He previously cofounded the startups coHome and Huffle He is currently helping Othera build its blockchain lending platform and exchange He blogs about technology and finance When not in front of a screen Svensson likes to make the most of surfing at his local beach Maroubra in Sydney Australia
You must have JavaScript enabled to view digital editions.