WEB3J Deployment Contract
Environment: Mac OS & Android Studio
Official website: here
Ethernet square web3j for Java configuration and use <1>: here
Ethernet square web3j for Java use-Create a voucher for a user credentials <2>:here One, compile a contract
Solc <contract>.sol--bin--abi--optimize-o <output-dir>/
====> production. Abi and. bin files
For example, in the Hello.sol file directory, enter:
solc hello.sol--bin--abi--optimize-o/users/pro/desktop
second, generate. java Files
WEB3J solidity generate [--javatypes|--soliditytypes]/path/to/<smart-contract>.bin/path/to/< Smart-contract>.abi-o/path/to/src/main/java-p Com.your.organisation.name
For example:
The generated. java file is then imported into an Android project.
III. Deployment of contracts
Yoursmartcontract contract = Yoursmartcontract.deploy (<web3j>, <credentials>, Gas_price, GAS_LIMIT,
[<initialvalue>,]
<param1>,.., <paramN>). Send ();
Or you can load a contract that has been deployed on a private chain:
Yoursmartcontract contract = Yoursmartcontract.load (
"0x<address>|<ensname>", web3j, credentials, Gas_price, Gas_limit);
For example:
allbikeshared contract = Allbikeshared.load ("0x055a864a5f39f9eecd17e729e2cfc4fb6b12c19b", web3, credentials, Gas_ Price, gas_limit);
Iv. invoking the contract
1.call way, without changing the status of the smart contract
Type result = Contract.somemethod (<param1>, ...). Send ();
For example:
BigInteger result = Contract.getusercount (). Send ();