![](https://github.com/FISCO-BCOS/FISCO-BCOS/raw/master/docs/images/FISCO_BCOS_Logo.svg?sanitize=true)
English / [中文](doc/README_CN.md)
# Spring Boot Starter
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![Build Status](https://travis-ci.org/FISCO-BCOS/spring-boot-starter.svg?branch=master)](https://travis-ci.org/FISCO-BCOS/spring-boot-starter)
[![CodeFactor](https://www.codefactor.io/repository/github/fisco-bcos/spring-boot-starter/badge)](https://www.codefactor.io/repository/github/fisco-bcos/spring-boot-starter)
---
The sample spring boot project is based on [Web3SDK](https://fisco-bcos-documentation.readthedocs.io/en/latest/docs/sdk/sdk.html), which provides the basic framework and basic test cases for blockchain application and helps developers to quickly develop applications based on the FISCO BCOS blockchain. **The version only supports** [FISCO BCOS 2.0+](https://fisco-bcos-documentation.readthedocs.io/en/latest/).
## Quickstart
### Precodition
Build FISCO BCOS blockchain, please check out [here](https://fisco-bcos-documentation.readthedocs.io/en/latest/docs/installation.html)。
### Download
```
$ git clone https://github.com/FISCO-BCOS/spring-boot-starter.git
```
#### Certificate Configuration
Copy the `ca.crt`, `sdk.crt`, and `sdk.key` files in the node's directory `nodes/${ip}/sdk` to the project's `src/main/resources` directory.(Before FISCO BCOS 2.1, the certificate files are `ca.crt`, `node.crt` and `node.key`)
### Settings
The `application.yml` of the spring boot project is shown below, and the commented content is modified according to the blockchain node configuration.
```yml
encrypt-type: # 0:standard, 1:guomi
encrypt-type: 0
group-channel-connections-config:
all-channel-connections:
- group-id: 1 # group ID
connections-str:
- 127.0.0.1:20200 # node listen_ip:channel_listen_port
- 127.0.0.1:20201
- group-id: 2
connections-str:
- 127.0.0.1:20202 # node listen_ip:channel_listen_port
- 127.0.0.1:20203
channel-service:
group-id: 1 # The specified group to which the SDK connects
agency-name: fisco # agency name
accounts:
pem-file: 0xcdcce60801c0a2e6bb534322c32ae528b9dec8d2.pem # PEM format account file
p12-file: 0x98333491efac02f8ce109b0c499074d47e7779a6.p12 # PKCS12 format account file
password: 123456 # PKCS12 format account password
```
A detail description of the SDK configuration for the project, please checkout [ here](https://fisco-bcos-documentation.readthedocs.io/en/latest/docs/sdk/sdk.html#sdk)。
### Run
Compile and run test cases:
```
$ cd spring-boot-starter
$ ./gradlew build
$ ./gradlew test
```
When all test cases run successfully, it means that the blockchain is running normally,and the project is connected to the blockchain through the SDK. You can develop your blockchain application based on the project。
**Note: If you run the demo project in IntelliJ IDEA or Eclipse, please use gradle wrapper mode. In addition, please enable `Annotation Processors` in `Settings` for IntelliJ IDEA.**
## Test Case Introduction
The sample project provides test cases for developers to use. The test cases are mainly divided into tests for [Web3j API](https://fisco-bcos-documentation.readthedocs.io/en/latest/docs/sdk/sdk.html#web3j-api), [Precompiled Serveice API](https://fisco-bcos-documentation.readthedocs.io/en/latest/docs/sdk/sdk.html#precompiled-service-api), Solidity contract file to Java contract file, deployment and call contract.
### Web3j API Test
Provide `Web3jApiTest` class to test the Web3j API. The sample test is as follows:
```java
@Test
public void getBlockNumber() throws IOException {
BigInteger blockNumber = web3j.getBlockNumber().send().getBlockNumber();
System.out.println(blockNumber);
assertTrue(blockNumber.compareTo(new BigInteger("0"))>= 0);
}
```
**Tips:** The `Application` class initializes the Web3j object, which can be used directly in the way where the business code needs it. The usage is as follows:
```
@Autowired
private Web3j web3j
```
### Precompiled Service API Test
Provide `PrecompiledServiceApiTest` class to test the Precompiled Service API。The sample test is as follows:
```java
@Test
public void testSystemConfigService() throws Exception {
SystemConfigSerivce systemConfigSerivce = new SystemConfigSerivce(web3j, credentials);
systemConfigSerivce.setValueByKey("tx_count_limit", "2000");
String value = web3j.getSystemConfigByKey("tx_count_limit").send().getSystemConfigByKey();
System.out.println(value);
assertTrue("2000".equals(value));
}
```
### Solidity contract file to Java contract file Test
Provide `SolidityFunctionWrapperGeneratorTest` class to test contract compilation. The sample test is as follows:
```java
@Test
public void compileSolFilesToJavaTest() throws IOException {
File solFileList = new File("src/test/resources/contract");
File[] solFiles = solFileList.listFiles();
for (File solFile : solFiles) {
SolidityCompiler.Result res = SolidityCompiler.compile(solFile, true, ABI, BIN, INTERFACE, METADATA);
System.out.println("Out: '" + res.output + "'");
System.out.println("Err: '" + res.errors + "'");
CompilationResult result = CompilationResult.parse(res.output);
System.out.println("contractname " + solFile.getName());
Path source = Paths.get(solFile.getPath());
String contractname = solFile.getName().split("\\.")[0];
CompilationResult.ContractMetadata a = result.getContract(solFile.getName().split("\\.")[0]);
System.out.println("abi " + a.abi);
System.out.println("bin " + a.bin);
FileUtils.writeStringToFile(new File("src/test/resources/solidity/" + contractname + ".abi"), a.abi);
FileUtils.writeStringToFile(new File("src/test/resources/solidity/" + contractname + ".bin"), a.bin);
String binFile;
String abiFile;
String tempDirPath = new File("src/test/java/").getAbsolutePath();
String packageName = "org.fisco.bcos.temp";
String filename = contractname;
abiFile = "src/test/resources/solidity/" + filename + ".abi";
binFile = "src/test/resources/solidity/" + filename + ".bin";
SolidityFunctionWrapperGenerator.main(Arrays.asList(
"-a", abiFile,
"-b", binFile,
"-p", packageName,
"-o", tempDirPath
).toArray(new String[0]));
}
System.out.println("generate successfully");
}
```
This test case converts all Solidity contract files (`HelloWorld` contract provided by default) in the `src/test/resources/contract` directory to the corresponding `abi` and `bin` files, and save them in the `src/test/resources/solidity` directory. Then convert the `abi` file and the corresponding `bin` file combination into a Java contract file, which is saved in the `src/test/java/org/fisco/bcos/temp` directory. The SDK will use the Java contract file for contract deployment and invocation.
### Deployment and Invocation Contract Test
Provide `ContractTest` class to test deploy and call contracts. The sample test is as follows:
```java
@Test
public void deployAndCallHelloWorld() throws Exception {
//deploy contract
HelloWorld helloWorld = HelloWorld.deploy(web3j, credentials, new StaticGasProvider(gasPrice, gasLimit)).send();
if (helloWorld != null) {
System.out.println("HelloWorld address is: " + helloWorld.getContractAddress());
//call set function
helloWorld.set("Hello, World!").send();
//call get function
String result = helloWorld.get().send();
System.out.println(result);
assertTrue( "Hello, World!".equals(result));
}
}
```
## Code Contribution
- Your contributions are most welcome and appreciated. Please read the [contribution instruct
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【项目资源】: 包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。 包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。 【项目质量】: 所有源码都经过严格测试,可以直接运行。 功能在确认正常工作后才上传。 【适用人群】: 适用于希望学习不同技术领域的小白或进阶学习者。 可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【附加价值】: 项目具有较高的学习借鉴价值,也可直接拿来修改复刻。 对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。 【沟通交流】: 有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 鼓励下载和使用,并欢迎大家互相学习,共同进步。
资源推荐
资源详情
资源评论
收起资源包目录
毕设&课设&项目&实训-区块链课程大作业.zip (252个子文件)
HelloWorld.abi 375B
HelloWorld.abi 375B
gradlew.bat 3KB
classAnalysis.bin 12.65MB
executionHistory.bin 557KB
taskHistory.bin 61KB
output.bin 34KB
jarAnalysis.bin 24KB
fileHashes.bin 22KB
resourceHashesCache.bin 19KB
outputFiles.bin 19KB
HelloWorld.bin 2KB
HelloWorld.bin 2KB
results.bin 938B
last-build.bin 1B
HelloWorld.class 12KB
HelloWorld.class 12KB
SolidityFunctionWrapperGeneratorTest.class 5KB
AccountConfig.class 4KB
AccountConfig.class 4KB
Channel2Client.class 3KB
GroupChannelConnectionsPropertyConfig.class 2KB
GroupChannelConnectionsPropertyConfig.class 2KB
ServiceConfig.class 2KB
ServiceConfig.class 2KB
ContractTest.class 2KB
PushCallback.class 2KB
PrecompiledServiceApiTest.class 2KB
Channel2Server.class 2KB
Web3jConfig.class 1KB
Web3jConfig.class 1KB
Web3jApiTest.class 1KB
EncryptTypeConfig.class 948B
EncryptTypeConfig.class 918B
Application.class 912B
Application.class 882B
HelloWorld$1.class 756B
HelloWorld$1.class 736B
ConnectConstants.class 605B
ConnectConstants.class 605B
GasConstants.class 549B
GasConstants.class 549B
BaseTest.class 528B
sdk.crt 2KB
node.crt 2KB
sdk.crt 2KB
node.crt 2KB
sdk.crt 2KB
node.crt 2KB
sdk.crt 2KB
node.crt 2KB
ca.crt 1KB
ca.crt 1KB
ca.crt 1KB
ca.crt 1KB
base-style.css 3KB
form.css 2KB
style.css 1KB
company.css 677B
bank.css 677B
build.gradle 2KB
settings.gradle 227B
gradlew 6KB
logback.groovy 2KB
logback.groovy 2KB
logback.groovy 2KB
org.fisco.bcos.solidity.SolidityFunctionWrapperGeneratorTest.html 15KB
org.fisco.bcos.PrecompiledServiceApiTest.html 10KB
org.fisco.bcos.server.Channel2Client.html 7KB
org.fisco.bcos.ContractTest.html 5KB
org.fisco.bcos.server.Channel2Server.html 5KB
org.fisco.bcos.Web3jApiTest.html 5KB
index.html 4KB
org.fisco.bcos.html 2KB
org.fisco.bcos.server.html 2KB
org.fisco.bcos.solidity.html 2KB
company.html 2KB
makeReceipt.html 1KB
transferReceipt.html 987B
confirmReceipt.html 978B
updateBalance.html 913B
updateCredit.html 911B
repay.html 902B
evaluateReceipt.html 862B
setCompanyAddress.html 862B
setDescription.html 862B
setCompanyName.html 854B
bank.html 828B
checkReceiptCreditor.html 813B
checkReceiptDebtor.html 809B
checkBalance.html 796B
credits.html 787B
receipts.html 787B
Infos.html 783B
loan.html 780B
autoRepays.html 679B
register.html 675B
output.bin.idx 376B
main.iml 1KB
test.iml 475B
共 252 条
- 1
- 2
- 3
资源评论
妄北y
- 粉丝: 2w+
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 电子学习资料设计作品全资料数字温度计资料
- 基于Django框架的IT资产维修管理系统设计源码
- 基于SpringBoot与Vue框架的宿舍管理系统设计源码
- 基于C#语言的预警监测系统设计源码
- yolo将xml文件转换为txt文件
- 电子学习资料设计作品全资料水库控制系统资料
- 基于PHP+MySQL架构的FoxCMS黔狐内容管理系统设计源码
- 基于Go语言的MySQL Binlog Exporter设计源码,实现Prometheus监控MySQL Binlog事件及主从同步监控
- 电子学习资料设计作品全资料同步电机模型的MATLAB仿真资料
- 基于Go语言的校园云互助跑腿小程序设计源码
- 基于SSM框架的JSP/Java精品课程在线学习系统设计源码
- 电子学习资料设计作品全资料危险气体泄露报警器设计资料
- 基于Vue2+Vant2与Vue2+Element Ui的宠物寄养平台前后台管理系统设计源码
- 基于Vue框架的居家上门服务系统移动端设计源码
- 基于Vue3与Node的SSR旅游住宿信息服务平台设计源码-爱此迎
- 卧式摆线螺杆机带仿真视频sw19可编辑全套技术资料100%好用.zip.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功