![](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
没有合适的资源?快使用搜索试试~ 我知道了~
本科毕设fiscobcos+solidity+springboot+vue.zip
共276个文件
java:138个
sol:41个
xml:19个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 49 浏览量
2023-10-20
21:27:05
上传
评论
收藏 15.33MB ZIP 举报
温馨提示
本科毕设fiscobcos+solidity+springboot+vue.zip
资源推荐
资源详情
资源评论
收起资源包目录
本科毕设fiscobcos+solidity+springboot+vue.zip (276个子文件)
test3.abi 13KB
platform.abi 6KB
digitalCurrency.abi 4KB
LoanRecipt.abi 2KB
digitalCash.abi 2KB
Respository.abi 2KB
Token.abi 2KB
AccountTest.abi 2KB
contractHash.abi 2KB
agreement.abi 1KB
Table.abi 1KB
RespositoryHash.abi 811B
OrderItemHash.abi 805B
OrderHash.abi 793B
HelloWorld.abi 375B
Account.abi 2B
gradlew.bat 3KB
test3.bin 111KB
platform.bin 98KB
digitalCurrency.bin 34KB
Respository.bin 14KB
contractHash.bin 12KB
AccountTest.bin 11KB
LoanRecipt.bin 11KB
digitalCash.bin 10KB
agreement.bin 6KB
OrderHash.bin 3KB
OrderItemHash.bin 3KB
RespositoryHash.bin 3KB
Table.bin 2KB
HelloWorld.bin 2KB
Account.bin 164B
c 1B
sdk.crt 2KB
ca.crt 644B
软件说明.doc 20KB
技术文档.docx 3.64MB
_1.gitignore 780B
.gitignore 780B
build.gradle 4KB
settings.gradle 227B
gradlew 6KB
logback.groovy 2KB
index.html 271B
Test3.java 240KB
DigitalCurrency.java 75KB
DigitalCurrency.java 72KB
WareHouseRecipt.java 38KB
WareHouseRecipt.java 36KB
AccountTest.java 35KB
Respository.java 34KB
Respository.java 33KB
Account.java 32KB
LoanRecipt.java 32KB
LoanRecipt.java 31KB
DigitalCash.java 30KB
Token.java 30KB
ContractHash.java 30KB
Agreement.java 23KB
ContractHash.java 22KB
LoanContractController.java 20KB
Table.java 18KB
OrderContractController.java 17KB
WarehouseReciptHash.java 16KB
RespositoryHash.java 16KB
OrderItemHash.java 16KB
WarehouseReciptHash.java 16KB
OrderHash.java 16KB
RespositoryHash.java 16KB
OrderItemHash.java 16KB
InventoryController.java 15KB
OrderHash.java 15KB
CollateralController.java 15KB
Web3jApiTest.java 14KB
AppointContractController.java 13KB
LoanReciptController.java 12KB
LoanApplyController.java 10KB
HelloWorld.java 9KB
HelloWorld.java 9KB
WarehouseReceiptController.java 9KB
AccountController.java 8KB
TokenExchangeController.java 8KB
SuppyTest.java 8KB
TransferInfoController.java 7KB
RespositoryController.java 7KB
FileController.java 7KB
DigitalCurrencyCall.java 6KB
ContractFileController.java 6KB
ContractHashCall.java 5KB
RespositoryCall.java 5KB
LoanReciptCall.java 5KB
OrderContract.java 5KB
WareHouseReciptCall.java 5KB
LoanContract.java 5KB
DigitalCashCall.java 5KB
OrderController.java 5KB
RespositoryHashCall.java 4KB
OrderItemHashCall.java 4KB
AccountConfig.java 4KB
OrderHashCall.java 4KB
共 276 条
- 1
- 2
- 3
资源评论
- m0_374003492024-04-24发现一个宝藏资源,资源有很高的参考价值,赶紧学起来~
天天501
- 粉丝: 596
- 资源: 4666
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功