- Git
- Docker & Docker-compose
- Nodejs >= 18
- JQ >= 1.6
- cURL
- Golang version 20.x
Get install script:
curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh && chmod +x install-fabric.sh
Format install command:
./install-fabric.sh -h
Usage: ./install-fabric.sh [-f|--fabric-version <arg>] [-c|--ca-version <arg>] <comp-1> [<comp-2>] ... [<comp-n>] ...
<comp>: Component to install one or more of d[ocker]|b[inary]|s[amples]. If none specified, all will be installed
-f, --fabric-version: FabricVersion (default: '2.5.5')
-c, --ca-version: Fabric CA Version (default: '1.5.7')
Choosing which version
./install-fabric.sh --fabric-version 2.5.5 binary
Note: After installation is complete, go to the config folder, access the core.yaml file, then edit the stateDatabase to CouchDB so you can use CouchDB and GetQueryResult!
cd networking
If you already have a test network running, bring it down to ensure the environment is clean.
./network.sh down
Launch the Fabric test network using the network.sh shell script.
./network.sh up createChannel -c mychannel -s couchdb -ca
./network.sh deployCC -ccn basic -ccp ../transfer/chaincode-go -ccl go
Preparation steps:
- Access the folder /networking/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/
- Create a cert.pem file from the *-cert.pem file (if it doesn't exist.)
- Access the transfer/rest-api-go directory and execute the command
go run main.go
Done!
sample api to test
API POST CREATE:
curl --location 'http://localhost:3000/invoke' \
--header 'content-type: application/json' \
--data '{
"channelid": "mychannel",
"chaincodeid": "basic",
"function": "CreateTodoItem",
"args": {
"ID": "todo5",
"Description": "Test Todo Item",
"Owner": "John",
"Status": "Pending",
"StartDate": "2023-01-01T00:00:00Z",
"EndDate": "2023-01-07T00:00:00Z",
"Priority": 2
}
}'
API GET ALL:
curl --location 'http://localhost:3000/query?channelid=mychannel&chaincodeid=basic&function=GetAllTodoItems'
API GET DETAIL:
curl --location 'http://localhost:3000/query?channelid=mychannel&chaincodeid=basic&function=ReadTodoItem&args=todo1'
API PUT UPDATE:
curl --location --request PUT 'http://localhost:3000/invoke' \
--header 'content-type: application/json' \
--data '{
"channelid": "mychannel",
"chaincodeid": "basic",
"function": "UpdateTodoItem",
"args": {
"ID": "todo1",
"Description": "Test Todo Item",
"Owner": "John",
"Status": "Pending",
"StartDate": "2023-01-01T00:00:00Z",
"EndDate": "2023-01-07T00:00:00Z",
"Priority": 2
}
}'
API DELETE:
curl --location --request DELETE 'http://localhost:3000/delete' \
--header 'content-type: application/json' \
--data '{
"channelid": "mychannel",
"chaincodeid": "basic",
"function": "DeleteTodoItem",
"args": [
"todo1"
]
}'
API SEARCH:
curl --location 'http://localhost:3000/search' \
--header 'Content-Type: application/json' \
--data '{
"channelid": "mychannel",
"chaincodeid": "basic",
"status": "Pending"
}'