Springboot with Ethereum (web3j)

Springboot with Ethereum (web3j)

节选自《Netkiller Spring Cloud 手札》

Maven

 <dependency>
 <groupId>org.web3j</groupId>
 <artifactId>web3j-spring-boot-starter</artifactId>
 <version>1.6.0</version>
 </dependency> 

application.properties

web3j.client-address=https://ropsten.infura.io/CsS9shwaAab0z7B4LP2d
web3j.admin-client=true 

TestRestController

package cn.netkiller.wallet.restful;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.response.Web3ClientVersion;

@RestController
public class TestRestController {
 private static final Logger logger = LoggerFactory.getLogger(TestRestController.class);

 @Autowired
 private Web3j web3j;

 public TestRestController() {
 // TODO Auto-generated constructor stub
 }

 @GetMapping("/version")
 public String version() throws IOException {
 Web3ClientVersion web3ClientVersion = web3j.web3ClientVersion().send();
 String clientVersion = web3ClientVersion.getWeb3ClientVersion();
 logger.info(clientVersion);
 return clientVersion;
 }

} 

测试

neo@MacBook-Pro ~ % curl http://localhost:8080/version
Geth/v1.8.3-stable/linux-amd64/go1.10
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

netkiller-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值