You will need to install the IBM Blockchain Platform Extension for VSCode version 1.38.0 or greater
You will also need to satisfy the following requirements for the IBM Blockchain Platform Extension for VS Code:
- Node v10.x and npm v6.x or greater
- VSCode version 1.38.0 or greater
- Docker version v17.06.2-ce or greater
- Docker Compose v1.14.0 or greater
- Clone the repo
- Use the VS Code extension to set up a smart contract on a basic Fabric network
- Run the application
Clone this repository in a folder your choice:
git clone https://github.com/IBM/fabcar-blockchain-sample.git
cd fabcar-blockchain-sample
We will use the IBM Blockchain Platform extension to package the Fabcar smart contract.
- Open Visual Studio code and open the
contract
folder from this repository that was cloned earlier.
Press the F1
key to see the different VS code options. Choose IBM Blockchain Platform: Package Open Project
.
Click the IBM Blockchain Platform
extension button on the left. This will show the packaged contracts on top and the blockchain connections on the bottom.
-
Next, if you want to, you can export the package to a location on your machine. However, exporting the packaged smart contract is not required for installing the smart contract on the local network.
-
Right click on the packaged contract (in this case, select fabcar@1.0.0) to export it and choose
Export Package
. Choose a location on your machine and save the.cds
file.
You should see FABRIC ENVIRONMENTS
on the left side of the editor. Under this section, you should see 1 Org Local Fabric
. Click it to start the Local Fabric.
The extension will now provision the Docker containers that will act as nodes in your network. Once the provisioning is finished and the network is up and running, you will see the options to install and instantiate the smart contract, the Channels
information, the Nodes
and the organization msps under Organizations
. You are now ready to install the smart contract.
- In the
FABRIC ENVIRONMENTS
section near the bottom, click onSmart Contracts
>Installed
>+ Install
. You will see a pop-up similar to the graphic below.
- Then select the packaged contract:
fabcar@1.0.0 Packaged
Note The 1.0.0 comes from yourpackage.json
line:"version": "1.0.0"
After the install is complete, you should get a message Successfully installed on peer peer0.org1.example.com
. You should also see that the contract is listed under Installed
under FABRIC ENVIRONMENTS
.
-
Under Smart Contracts you will see a section that says Instantiated. Click on
+ Instantiate
under it. -
The extension will then ask you which contract and version to instantiate — choose
fabcar@1.0.0 Installed
.
- The extension will then ask you which function to call on instantiate — type in
initLedger
- Next, it will ask you for the arguments to the function. There are none, so just hit enter.
- Next, the extension will then ask you do you want to use a provide a private data collection configuration file? - Click on
No
.
- Lastly, the extension will then ask you do you want to choose a smart contract endorsement policy. Choose
Default (single endorser, any org)
.
Once instantiation of the contract completes, you should get the message Successfully instantiated smart contract
and you should see fabcar@1.0.0
under Instantiated
under FABRIC ENVIRONMENTS
.
We will now create the app-admin identity using the CA (Certificate Authority) node. The identity information and key files are needed in order to authenticate and run the application.
Under FABRIC ENVIRONMENTS
section in the left hand pane, expand Nodes
and right click on Org1 CA
. Choose Create Identity (register and enroll)
.
Type app-admin
and press the enter key.
The extension will then ask if you want to add any attributes to this identity. Click on Yes
.
The extension will then ask you to provide the attributes for this identity. Enter [{"name":"hf.Registrar.Roles","value":"*","ecert":true}]
.
Once the identity is successfully created, you should get the message Successfully created identity 'app-admin' with the attributes: [{"name":"hf.Registrar.Roles","value":"*","ecert":true}]
. You can now see app-admin
in the FABRIC WALLETS
section under 1 Org Local Fabric
> Org1
.
Under FABRIC WALLETS
in the left hand pane, expand 1 Org Local Fabric
, and under it right click on Org1
and select Export Wallet
.
You can save the exported files anywhere.
From the exported directory, copy the contents of the app-admin
folder to the following location in the directory where you have cloned this repo:
/fabcar-blockchain-sample/web-app/server/wallet/app-admin
The next step is to obtain the connection profile for Org1
. Under FABRIC GATEWAYS
in the left-hand pane, expand 1 Org Local Fabric
and right click on Org1
. Select Export Connection Profile
. Save the file to the following location in the directory where you have cloned this repo:
/fabcar-blockchain-sample/web-app/server
Next, open the config.json file. We need to update this file to indicate that we want to run the application locally.
- Specify the "connection_file" as the name of the connection profile file which was downloaded earlier. Unless you specified a different name when saving the file, it should probably be named
1 Org Local Fabric - Org1_connection.json
. - The value for "caName" can be obtained from the connection profile file. Open the connection profile and look for the certificateAuthorities section. Obtain the caName from the line just below it. It should probably be
Org1CA
. - Update gateway discovery to
{ enabled: true, asLocalhost: true }
to connect to the local fabric network.
After these updates, the config.json file should look similar to the file shown below:
{
"connection_file": "1 Org Local Fabric - Org1_connection.json",
"appAdmin": "app-admin",
"appAdminSecret": "app-adminpw",
"orgMSPID": "Org1MSP",
"caName": "Org1CA",
"userName": "user1",
"gatewayDiscovery": { "enabled": true, "asLocalhost": true }
}
Almost done, you can run the application.
-
Run the
registerUser.js
script.node registerUser.js
-
You should see the following in the terminal:
Successfully registered and enrolled the user user1 and imported it into the wallet
-
From the
server
directory, start the server.npm start
-
In a new terminal, open the web client folder and install the dependencies.
cd web-app/client npm install
-
Start the client:
npm start
You can find the app running at http://localhost:4200/