🌑

帮帮技术站

web3-sol 编译.sol到java

  1. 安装编译器

    1
    2
    npm intall -g solc
    npm install -g solc@0.4.22
  2. 编译abi

    1
    2
    3
    4
    work-home > solcjs --abi --bin ./contract/WoodenFish.sol -o ./abi

    运行命令错误,参考: https://www.cnblogs.com/pywen/p/16881543.html

或者使用 用网页版IDE remix 来将其转换为abi/和bin

  1. 安装Web3j CLI

    1
    2
    3
    4
    5
    6
    7
    8
    linux: curl -L get.web3j.io | sh && source ~/.web3j/source.sh

    window:
    https://github.com/web3j/web3j/releases?page=4 v4.5.5
    设置环境变量



  2. 编译到java

    1
    2
    3
    4
    5
    6
    7
    8

    web3j solidity generate
    -b ./abi/contract/WoodenFish_sol_WoodenFishToken.bin
    -a ./abi/contract/WoodenFish_sol_WoodenFishToken.abi
    -o ./src/main/java -p cn.jiliapp.contract

    运行命令错误,参考: https://www.cnblogs.com/pywen/p/16881543.html

  3. 更改合约编译后名称 重新输出合约对象

    1
    2
    3
    4
    5
    6
    7
    8
    9
    solcjs --abi --bin ./contract/WoodenFish.sol -o ./abi

    contract_WoodenFish_sol_WoodenFishToken.bin -> WoodenFishToken.bin
    contract_WoodenFish_sol_WoodenFishToken.abi -> WoodenFishToken.abi

    web3j solidity generate -b ./abi/WoodenFishToken.bin -a ./abi/WoodenFishToken.abi -o ./src/main/java -p cn.jiliapp.contract

    WoodenFishToken.java

  4. WoodenFishToken.java对象依赖

    1
    2
    3
    4
    5
    6
    <dependency>
    <groupId>org.web3j</groupId>
    <artifactId>core</artifactId>
    <version>5.0.0</version>
    </dependency>

— Jan 7, 2023

Search