Springboot连接FISCO-BCOS链

依赖

FISCO-BOCS 2.5.0
JAVA 1.8
Spring Boot 2.0.2

官方文档

前期准备

部署FISCO-BOCS 2.5.0

引入SDK

<dependency>
    <groupId>org.fisco-bcosgroupId>
    <artifactId>web3sdkartifactId>
    <version>2.6.1version>
dependency>

SSL连接

将节点所在目录nodes/${ip}/sdk/目录下的ca.crt、sdk.crt和sdk.key文件拷贝到项目的资源目录

Spring Boot

配置GroupChannelConnectionsConfig

@Bean(name="groupChannelConnectionsConfig")
	public GroupChannelConnectionsConfig groupChannelConnectionsConfig(){
		GroupChannelConnectionsConfig groupChannelConnectionsConfig = new GroupChannelConnectionsConfig();
		List<ChannelConnections> allChannelConnections = new ArrayList<ChannelConnections>();
		ChannelConnections channelConnections = new ChannelConnections();
		channelConnections.setGroupId(1);
		List<String> connectionsStr = new ArrayList<String>();
		connectionsStr.add("127.0.0.1:20200");
		channelConnections.setConnectionsStr(connectionsStr);
		allChannelConnections.add(channelConnections);
		groupChannelConnectionsConfig.setAllChannelConnections(allChannelConnections);
		return groupChannelConnectionsConfig;
	}

配置channelService

@Bean(name="channelService")
	public Service channelService(){
		Service service = new Service();
		service.setGroupId(1);
		service.setAgencyName("sinolife");
		service.setAllChannelConnections(groupChannelConnectionsConfig());
		return service;
	}

你可能感兴趣的:(区块链,区块链,FISCO-BCOS)