Solidity编译器和简单调试

1 安装Solidity编译器

1.1 通过docker安装Solc

搜索docker的Solc镜像

docker search —no-trunc ethereum/solc

通过docker安装Solc

docker pull docker.io/ethereum/solc:stable

1.2 运行Solc容器

运行如下命令

docker run —rm -it —privileged=true —net=host -v /home/hpbroot/ethereum_go/contract:/contract —name solc ethereum/solc:stable –version

查看是否成功

 

2 新建spring boot工程

2.1 通过Eclipse新建工程

首先,新建ContractCompile工程

在springboot配置文件application.properties中添加如下

1 web3j.contract.solcCmd=docker run --rm -it --privileged=true --net=host -v /home/hpbroot/ethereum_go/contract:/contract --name solc ethereum/solc:stable
2    在pom文件添加依赖
3    <dependency>
4    <groupId>org.ethereum</groupId>
5    <artifactId>solcJ-all</artifactId>
6    <version>0.4.10</version>
7    </dependency>

新建ContractConfig类

1     @Component
2    @ConfigurationProperties(prefix = "web3j.contract")
3    public class ContractConfig {
4        private String solcCmd;
5        public String getSolcCmd() {
6            return solcCmd;
7         }
8        public void setSolcCmd(String solcCmd) {
9        this.solcCmd = solcCmd;
10      }
11    }

2.2 调用智能合约编译器的代码

1     String soliditySrcCode =MapUtils.getString(preParam, "soliditySrcCode");
2    if(StringUtils.isBlank(soliditySrcCode)) {
3    param.put(ContractConstant.RETURN_CODE, ContractConstant.ERROR_CODE);
4    param.put(ContractConstant.RETURN_MSG, ContractConstant.N

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值