Java Magazine, Jan/Feb 2017
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2017 44 cryptocurrency public methods available on the smart contract web3j requires these two files in order to generate the smart contract wrappers for working with the smart contract in Java I generate the greeter wrappers using the web3j commandline tools this time with the solidity command full paths have been shortened for brevity web3j 109 bin web3j solidity generate build greeter bin build greeter abi p org web3j javamag generated o src main java This command will create the class file org web3j example generated Greeter which wraps all the smart contracts methods so they can be called from Java public final class Greeter extends Contract private static final String BINARY 6060604052604051610269380380610269833981 private Greeter String contractAddress Web3j web3j Credentials credentials BigInteger gasPrice BigInteger gasLimit super contractAddress web3j credentials gasPrice gasLimit public Future Utf8String greet Function function new Function greet Arrays Type asList Arrays TypeReference asList new TypeReference Utf8String return executeCallSingleValueReturnAsync function public static Future Greeter deploy Web3j web3j Credentials credentials BigInteger gasPrice BigInteger gasLimit BigInteger initialValue Utf8String _ greeting String encodedConstructor FunctionEncoder encodeConstructor Arrays Type asList_ greeting return deployAsync Greeter class web3j credentials gasPrice gasLimit BINARY encodedConstructor initialValue public static Greeter load String contractAddress Web3j web3j Credentials credentials BigInteger gasPrice BigInteger gasLimit return new Greeter contractAddress web3j credentials gasPrice gasLimit I can now both deploy and call the smart contract Credentials credentials WalletUtils loadCredentials my password path to walletfile Greeter contract Greeter deploy web3 credentials BigInteger ZERO
You must have JavaScript enabled to view digital editions.