## Balance transfer
A sample Node.js app to demonstrate **__fabric-client__** & **__fabric-ca-client__** Node.js SDK APIs
### Prerequisites and setup:
* [Docker](https://www.docker.com/products/overview) - v1.12 or higher
* [Docker Compose](https://docs.docker.com/compose/overview/) - v1.8 or higher
* [Git client](https://git-scm.com/downloads) - needed for clone commands
* **Node.js** v8.4.0 or higher
* [Download Docker images](http://hyperledger-fabric.readthedocs.io/en/latest/samples.html#binaries)
```
cd fabric-samples/balance-transfer/
```
Once you have completed the above setup, you will have provisioned a local network with the following docker container configuration:
* 2 CAs
* A SOLO orderer
* 4 peers (2 peers per Org)
#### Artifacts
* Crypto material has been generated using the **cryptogen** tool from Hyperledger Fabric and mounted to all peers, the orderering node and CA containers. More details regarding the cryptogen tool are available [here](http://hyperledger-fabric.readthedocs.io/en/latest/build_network.html#crypto-generator).
* An Orderer genesis block (genesis.block) and channel configuration transaction (mychannel.tx) has been pre generated using the **configtxgen** tool from Hyperledger Fabric and placed within the artifacts folder. More details regarding the configtxgen tool are available [here](http://hyperledger-fabric.readthedocs.io/en/latest/build_network.html#configuration-transaction-generator).
## Running the sample program
There are two options available for running the balance-transfer sample
For each of these options, you may choose to run with chaincode written in golang or in node.js.
### Option 1:
##### Terminal Window 1
* Launch the network using docker-compose
```
docker-compose -f artifacts/docker-compose.yaml up
```
##### Terminal Window 2
* Install the fabric-client and fabric-ca-client node modules
```
npm install
```
* Start the node app on PORT 4000
```
PORT=4000 node app
```
##### Terminal Window 3
* Execute the REST APIs from the section [Sample REST APIs Requests](https://github.com/hyperledger/fabric-samples/tree/master/balance-transfer#sample-rest-apis-requests)
### Option 2:
##### Terminal Window 1
```
cd fabric-samples/balance-transfer
./runApp.sh
```
* This lauches the required network on your local machine
* Installs the fabric-client and fabric-ca-client node modules
* And, starts the node app on PORT 4000
##### Terminal Window 2
In order for the following shell script to properly parse the JSON, you must install ``jq``:
instructions [https://stedolan.github.io/jq/](https://stedolan.github.io/jq/)
With the application started in terminal 1, next, test the APIs by executing the script - **testAPIs.sh**:
```
cd fabric-samples/balance-transfer
## To use golang chaincode execute the following command
./testAPIs.sh -l golang
## OR use node.js chaincode
./testAPIs.sh -l node
```
## Sample REST APIs Requests
### Login Request
* Register and enroll new users in Organization - **Org1**:
`curl -s -X POST http://localhost:4000/users -H "content-type: application/x-www-form-urlencoded" -d 'username=Jim&orgName=Org1'`
**OUTPUT:**
```
{
"success": true,
"secret": "RaxhMgevgJcm",
"message": "Jim enrolled Successfully",
"token": "<put JSON Web Token here>"
}
```
The response contains the success/failure status, an **enrollment Secret** and a **JSON Web Token (JWT)** that is a required string in the Request Headers for subsequent requests.
### Create Channel request
```
curl -s -X POST \
http://localhost:4000/channels \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json" \
-d '{
"channelName":"mychannel",
"channelConfigPath":"../artifacts/channel/mychannel.tx"
}'
```
Please note that the Header **authorization** must contain the JWT returned from the `POST /users` call
### Join Channel request
```
curl -s -X POST \
http://localhost:4000/channels/mychannel/peers \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json" \
-d '{
"peers": ["peer0.org1.example.com","peer1.org1.example.com"]
}'
```
### Install chaincode
```
curl -s -X POST \
http://localhost:4000/chaincodes \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json" \
-d '{
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
"chaincodeName":"mycc",
"chaincodePath":"github.com/example_cc/go",
"chaincodeType": "golang",
"chaincodeVersion":"v0"
}'
```
**NOTE:** *chaincodeType* must be set to **node** when node.js chaincode is used and *chaincodePath* must be set to the location of the node.js chaincode. Also put in the $PWD
```
ex:
curl -s -X POST \
http://localhost:4000/chaincodes \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json" \
-d '{
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
"chaincodeName":"mycc",
"chaincodePath":"$PWD/artifacts/src/github.com/example_cc/node",
"chaincodeType": "node",
"chaincodeVersion":"v0"
}'
```
### Instantiate chaincode
```
curl -s -X POST \
http://localhost:4000/channels/mychannel/chaincodes \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json" \
-d '{
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
"chaincodeName":"mycc",
"chaincodeVersion":"v0",
"chaincodeType": "golang",
"args":["a","100","b","200"]
}'
```
**NOTE:** *chaincodeType* must be set to **node** when node.js chaincode is used
### Invoke request
```
curl -s -X POST \
http://localhost:4000/channels/mychannel/chaincodes/mycc \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json" \
-d '{
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
"fcn":"move",
"args":["a","b","10"]
}'
```
**NOTE:** Ensure that you save the Transaction ID from the response in order to pass this string in the subsequent query transactions.
### Chaincode Query
```
curl -s -X GET \
"http://localhost:4000/channels/mychannel/chaincodes/mycc?peer=peer0.org1.example.com&fcn=query&args=%5B%22a%22%5D" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```
### Query Block by BlockNumber
```
curl -s -X GET \
"http://localhost:4000/channels/mychannel/blocks/1?peer=peer0.org1.example.com" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```
### Query Transaction by TransactionID
```
curl -s -X GET http://localhost:4000/channels/mychannel/transactions/<put transaction id here>?peer=peer0.org1.example.com \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```
**NOTE**: The transaction id can be from any previous invoke transaction, see results of the invoke request, will look something like `8a95b1794cb17e7772164c3f1292f8410fcfdc1943955a35c9764a21fcd1d1b3`.
### Query ChainInfo
```
curl -s -X GET \
"http://localhost:4000/channels/mychannel?peer=peer0.org1.example.com" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```
### Query Installed chaincodes
```
curl -s -X GET \
"http://localhost:4000/chaincodes?peer=peer0.org1.example.com&type=installed" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```
### Query Instantiated chaincodes
```
curl -s -X GET \
"http://localhost:4000/chaincodes?peer=peer0.org1.example.com&type=instantiated" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```
### Query Channels
```
curl -s -X GET \
"http://localhost:4000/channels?peer=peer0.org1.example.com" \
-H "authorization: Bearer <put JSON Web Token here>" \
-H "content-type: application/json"
```
### Clean the network
The network will still be running at this point. Before starting the network manually again, here
没有合适的资源?快使用搜索试试~ 我知道了~
毕业设计 基于hyperledger fabric区块链的工作流审批应用源码+详细文档+全部资料(高分项目).zip
共163个文件
pem:55个
crt:20个
js:15个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 62 浏览量
2024-04-17
09:10:25
上传
评论
收藏 224KB ZIP 举报
温馨提示
【资源说明】 毕业设计 基于hyperledger fabric区块链的工作流审批应用源码+详细文档+全部资料(高分项目).zip毕业设计 基于hyperledger fabric区块链的工作流审批应用源码+详细文档+全部资料(高分项目).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如软件工程、计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也可作为毕设项目、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 3、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
毕业设计 基于hyperledger fabric区块链的工作流审批应用源码+详细文档+全部资料(高分项目).zip (163个子文件)
0d46ccf0e9436c1bc3b6e2bf80cdb202c4943604f95c72ee0ff839d3ec300719_sk 241B
0d9f72608133ee627b570b6af6877666bc8f365746f9329d6dd8a5f54e53e2ab_sk 241B
0e729224e8b3f31784c8a93c5b8ef6f4c1c91d9e6e577c45c33163609fe40011_sk 241B
1995b11d6573ed3be52fcd7a5fa477bc0f183e1f5f398c8281d0ce7c2c75a076_sk 241B
27ccb54a06020260c66c65bec91f91e1c9043e3076d3d6128692e7271c4c7a2c_sk 241B
27db82c96b1482480baa1c75f80e5cce249beaab27b70c741bb0e2554355957e_sk 241B
2fb065725bf1b7e2811c0e8ca8d37f5a951fc4cd1162a47aad8accf9ddd10291_sk 241B
585175c83bac91fc0c1ce8f9d0ff9aefa47c565678f100ca8673db249ee785ac_sk 241B
5890f0061619c06fb29dea8cb304edecc020fe63f41a6db109f1e227cc1cb2a8_sk 241B
6a211ed18880b4db3867831c977809902713b8e321a5ab55ecc104dafc2eec49_sk 241B
73cdc0072c7203f1ec512232c780fc84acc9752ef30ebc16be1f4666c02b614b_sk 241B
7bb8ba3ff11d3c8cf592bd4326062e77d06ac4963c7b7ae459284dfbd3eb5aac_sk 241B
945092d936f5838c5a6f6484db974d857933706737d00d04bf65f74e3976f9f8_sk 241B
a7d47efa46a6ba07730c850fed2c1375df27360d7227f48cdc2f80e505678005_sk 241B
genesis.block 9KB
server.crt 912B
server.crt 912B
server.crt 908B
server.crt 908B
server.crt 875B
ca.crt 855B
ca.crt 855B
ca.crt 855B
ca.crt 855B
ca.crt 855B
ca.crt 855B
ca.crt 855B
ca.crt 855B
server.crt 834B
server.crt 834B
server.crt 834B
server.crt 834B
ca.crt 826B
ca.crt 826B
server.crt 814B
style.css 111B
db670eed8487a93c35ae448b9f84c2f241a7a8c87df0544fc1dc08baf7832aa0_sk 241B
fdee12a3510fde3155c37128cfec26090ae249bfbca28f884e60c21338493edd_sk 241B
.gitignore 34B
.gitignore 32B
chain.go 19KB
hello.html 128B
Express.iml 458B
app.js 14KB
query.js 8KB
instantiate-chaincode.js 7KB
invoke-transaction.js 7KB
join-channel.js 6KB
invoke.js 5KB
helper.js 5KB
admin.js 4KB
install-chaincode.js 3KB
create-channel.js 3KB
checkdue.js 2KB
index.js 2KB
app.js 1KB
config.js 805B
users.js 203B
package-lock.json 94KB
package-lock.json 36KB
package.json 915B
package.json 466B
users.json 383B
config.json 258B
duetime.json 2B
users.json 0B
server.key 241B
server.key 241B
server.key 241B
server.key 241B
server.key 241B
server.key 241B
server.key 241B
server.key 241B
server.key 241B
server.key 241B
README.md 10KB
README.md 4KB
tlsca.org2.example.com-cert.pem 855B
tlsca.org2.example.com-cert.pem 855B
tlsca.org2.example.com-cert.pem 855B
tlsca.org2.example.com-cert.pem 855B
tlsca.org2.example.com-cert.pem 855B
tlsca.org2.example.com-cert.pem 855B
tlsca.org1.example.com-cert.pem 855B
tlsca.org1.example.com-cert.pem 855B
tlsca.org1.example.com-cert.pem 855B
tlsca.org1.example.com-cert.pem 855B
tlsca.org1.example.com-cert.pem 855B
tlsca.org1.example.com-cert.pem 855B
ca.org2.example.com-cert.pem 847B
ca.org2.example.com-cert.pem 847B
ca.org2.example.com-cert.pem 847B
ca.org2.example.com-cert.pem 847B
ca.org2.example.com-cert.pem 847B
ca.org2.example.com-cert.pem 847B
ca.org1.example.com-cert.pem 843B
ca.org1.example.com-cert.pem 843B
ca.org1.example.com-cert.pem 843B
ca.org1.example.com-cert.pem 843B
共 163 条
- 1
- 2
资源评论
不走小道
- 粉丝: 3331
- 资源: 5060
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功