"Block Chain" Ethernet Square web3j for Java use-deployment and invocation contracts <3>__mysql

Source: Internet
Author: User
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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.