This connector is based on two other repositories with HL examples:
The example core consists of four key files:
-
config.json
- Which contains configuration information necessary to connect to the right service endpoints. -
creds.json
- This are the credentials obtained from the IBP Starter Plan. -
app.js
- Implements the core logic for the node REST app. -
connection.js
- Implements a class that loads the profile and config information needed to create a connection to the IBP Starter Plan. It also provides a set of APIs to query the IBP Starter Plan.
We make the following assumptions in this document:
- You have an instance of the IBM Blockchain Platform Starter Plan running.
- You have initialized your network, you will be working with the default channel (e.g.,
defaultchannel
) created or have created a new channel and will make the adjustments as necessary. - You have uploaded your chaincode to the starter plan and instantiated it.
To create a network and get started with your own instance of the IBM Blockchain Platform Starter Plan please visit Getting Started.
For an end-to-end application running inside the starter plan also feel free to see IBM Blockchain - Car Auction Network Fabric Node SDK.
The first thing we need to do is clone the repo on your local computer.
git clone https://github.com/berserkr/ibps_connector
Then, go ahead and go into the directory:
cd ibps_connector
First, we need to generate the necessary keys and certs from the Certificate Authority to prove our authenticity to the network.
To do this, we will go into our new IBM Blockchain Starter Plan network, and from the Overview
Tab on the left, we will click on Connection Profile
on the right-side of the page. Then click on Raw JSON
.
Open up the JSON
document as we will need to extract a few things from it:
enrollId
- should be "admin"enrollSecret
- should be similar to "1dcab332aa"url
- should be similar to "nde288ef7dd7542d3a1cc824a02be67f1-org1-ca.us02.blockchain.ibm.com:31011"caName
- should be "org1CA"
You will need to populate the right parameters in the config.json
file:
{
"channelName" : "defaultchannel",
"peerName" : "org1-peer1",
"chaincodeId" : "mycc",
"adminId" : "admin",
"adminSecret" : "1dcab332aa",
"orgId" : "org1",
"orgCAName" : "org1CA",
"endpointURL" : "nde288ef7dd7542d3a1cc824a02be67f1-org1-ca.us02.blockchain.ibm.com:31011",
"keyStoreName" : "hfc-key-store"
}
Next, we need to download the credentials needed to access the network.
To do this, we will go into our new IBM Blockchain Starter Plan network, and from the Overview
Tab on the left, we will click on Connection Profile
on the right-side of the page. Then click on Download
.
You will end up with a file named creds_nc88cda81f7a341b9a96b6a9fb0f03c02_org1.json
or something similar, rename it creds.json
and move it over to
the same directory where config.json
and app.js
reside.
Save your file, and run npm install:
npm install
In the command line run:
node app
Next, you can exercise the server by running the testAPI.sh
script. There
are a few things that need to be tweaked before hand.
If there is no admin
registered, the service will register the admin
user for you. You may then use the get token endpoint to perform administrative tasks.
You can register new users via the users
url:
http://localhost:3000/users
Otherwise, to get an access token, you may call the token
url:
http://localhost:3000/token
Below is an example showing how to invoke the user registration url. Notice,
the name of the user we are getting a token for (e.g., TestUser
).
############################### NOTE ###############################
# If testing with new user, please user http://localhost:3000/users
# otherwise, keep it as http://localhost:3000/token
####################################################################
ORG1_TOKEN=$(curl -s -X POST \
http://localhost:3000/token \
-H "content-type: application/x-www-form-urlencoded" \
-d 'username=TestUser&orgName=org1')
echo $ORG1_TOKEN
ORG1_TOKEN=$(echo $ORG1_TOKEN | jq ".token" | sed "s/\"//g")
echo
echo "ORG1 token is $ORG1_TOKEN"
Assuming you have a default channel called defaultchannel
, make sure that all curl
calls use the right channel during invocation.
For example:
http://localhost:3000/channels/defaultchannel/chaincodes/blooms
Next, we need to make sure that the chaincode name is updated, for instance, if your target chaincode is mycc
, make sure that all calls that require some interaction with the chaincode have mycc
(replace it with your chaincode name).
For example:
http://localhost:3000/channels/defaultchannel/chaincodes/mycc
- IBM Blockchain - Car Auction Network Fabric Node SDK
- Hyperledger Fabric Samples - Balance Transfer
- IBM Blockchain - Marbles demo
- Hyperledger Fabric Docs
-
Blockchain Code Patterns: Enjoyed this Code Pattern? Check out our other Blockchain Code Patterns
-
Blockchain 101: Learn why IBM believes that blockchain can transform businesses, industries – and even the world. Blockchain 101