Method for generating java class file by blockchain smart contract

You can refer to the document  https://docs.web3j.io/smart_contracts/      The official document of web3j is written very clearly and can be translated by Google

 

The first step is to generate the required bin and abi files according to the smart contract.

install install solc 

 The command npm install -g solc can not use npm, please install the environment by Baidu

After installing solc, generate the bin file and abi file corresponding to the smart contract  

solcjs smart contract file path --bin --abi --optimize -o output path

For example: solcjs C:/**/IERC20.sol --bin --abi --optimize -o C:/**/output The corresponding output path will generate bin and abi files (the file name will be longer and can be repeated Naming modification is convenient for future use)

The second step uses the bin and abi files to generate the corresponding java class files

Download web3j   https://github.com/web3j/web3j/releases   Download the compressed package and decompress it 

cmd to open the command line window (cd C:/**/web3j/bin under the bin path decompressed by cd web3j) 

generate java file

 web3j solidity generate -b bin file -a abi file -p package name -o output path

 web3j solidity generate -b C:\**\EIP20Interface.bin -a C:\**\EIP20Interface.abi -p com.wallet.contract -o C:\**\output

Find the corresponding java file in the output path and you can use it

Guess you like

Origin blog.csdn.net/sinat_35541927/article/details/100593125