Bu sayfa henüz yerel dilinizde mevcut değildir. Daha fazla dil seçeneği eklemek için yoğun bir şekilde çalışıyoruz. Desteğiniz için teşekkür ederiz.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Node.js SDK Demo

Updated on 2023-03-07 GMT+08:00

This demo provides a Node.js chaincode and a program that uses the Hyperledger Fabric SDK for Node.js (fabric-nodejs-sdk) to invoke the chaincode to describe how to use a Node.js SDK to access BCS. For details about the APIs of Hyperledger Fabric SDK for Node.js, visit https://hyperledger.github.io/fabric-sdk-node/release-1.4/index.html.

NOTE:

This is a demo only and is not for actual use.

Preparations

Step

Action

Description

1

Install a development tool.

Download and install the Node.js source code: https://nodejs.org/en/download/

2

Download the demo project code.

Project code: nodejs-demo.zip

Creating a BCS Instance

  1. Log in to the BCS console.
  2. Click Create BCS Instance in the upper right corner.
  3. Configure basic information about the BCS instance by referring to Table 1.

    NOTICE:

    To ensure that the demo runs properly, set the parameters as described in the following table.

    Table 1 Basic settings

    Parameter

    Setting

    Region

    Retain the default value.

    Enterprise project

    Select default.

    Instance Name

    Enter node-sdk-demo.

    Edition

    Professional

    Blockchain Type

    Select Private.

    Enhanced Hyperledger Fabric Version

    v2.2

    Consensus Mechanism

    Select SOLO.

    Resource Access Initial Password

    Enter a password.

    Confirm Password

    Confirm the password.

  4. Click Next: Configure Resources. Table 2 describes the resource parameters.

    Table 2 Resource configurations

    Parameter

    Example

    Environment Resources

    Select Custom.

    Cluster

    Select Create a new CCE cluster.

    AZ

    Select an AZ.

    ECS Specifications

    Select the flavor for 4 vCPUs | 8 GB.

    ECS Quantity

    Enter 1.

    High Availability

    Select No.

    VPC

    Select Automatically create VPC.

    Subnet

    Select Automatically create subnet.

    ECS Login Method

    Select Password.

    Password of Root User

    If you do not enter a password here, the previously specified resource access initial password will be used.

    Confirm Password

    -

    Use EIP of a CCE Node

    Select Yes.

    EIP Billed By

    Retain the default value.

    EIP Bandwidth

    Set it to 5 Mbit/s.

  5. Click Next: Configure Blockchain. Table 3 describes the blockchain parameters.

    Table 3 Blockchain configurations

    Parameter

    Example

    Blockchain Configuration

    Select Custom.

    Blockchain Mgmt. Initial Password

    If you do not enter a password here, the previously specified resource access initial password will be used.

    Confirm Password

    -

    Volume Type

    Select SFS Turbo.

    Storage Capacity of Peer Organization (GB)

    Retain the default value.

    Ledger Storage

    Select File database (GoLevelDB).

    Peer Organization

    A peer organization named organization has been automatically created. Change the peer quantity to 1.

    Channel Configuration

    The organization organization has been added to the channel automatically. Retain this default setting.

    Orderer Quantity

    Retain the default value.

    Security Mechanism

    Select ECDSA.

    NOTICE:

    Only ECDSA can be selected.

    Configure Block Generation

    Select No.

    Enable Support for RESTful API

    Select No.

  6. Click Next: Confirm.
  7. Confirm the configurations and finish the creation process.

    Wait for several minutes. After a message is displayed indicating successful installation, check the status of the instance. If it is Normal, the deployment is completed.

Installing and Instantiating a Chaincode

  1. Log in to the BCS console.
  2. In the navigation pane on the left, click Instance Management.
  3. Find the instance you just created and click Manage Blockchain to go to the Blockchain Management console.
  4. On the login page, enter the username and password, and click Log In.

    NOTE:

    The username is admin, and the password is the Blockchain Mgmt. Initial Password set when you created the BCS instance. If you have not set this password, use the resource access initial password.

  5. Click in the upper left corner of the page.

    The parameters for chaincode installation are as follows.

    Parameter

    Setting

    Chaincode Name

    Enter bcsysq.

    Chaincode Version

    Enter 1.0

    Ledger Storage

    File database (goleveldb)

    Select All Peers

    Check the box.

    Organization & Peer

    Select peer-0.

    Language

    Select Node.js.

    Chaincode File

    Add the downloaded chaincode file nodejs-chaincode.zip.

    Chaincode Description

    Enter a description of the chaincode.

  6. Click Install.
  7. After installing the chaincode, click Instantiate in the Operation column of the chaincode list.

    The parameters for chaincode instantiation are as follows.

    Parameter

    Setting

    Chaincode Name

    Enter bcsysq.

    Channel

    Select channel.

    Chaincode Version

    Enter 1.0

    Initialization Function

    Enter init.

    Chaincode Parameters

    Enter a,200,b,250.

    Endorsement Policy

    Select Endorsement from any of the following organizations.

    Endorsing Organizations

    Select organization.

    Privacy Protection Configuration

    Select No.

Deploying the Application

  1. Download and decompress the demo project code package nodejs-demo.zip to the local PC, and use an IDE to open it.

    This demo is compiled using Node.js. It contains the fabric-client library to enable money transfer from user A to user B by running the chaincode. Use the IDE that you prefer to open the script. The following table lists the files included in the project.

    Table 4 Project content

    Fie

    Description

    invoke.js

    Invoking the chaincode to transfer money from user A to user B.

    query.js

    Querying the chaincode to determine the account balance of user A.

    sdk-config.js

    Parsing the blockchain network configuration file sdk-config.json downloaded from the BCS console.

    sdk-config.json

    Containing the blockchain network configuration data.

  2. Download SDK configurations and certificates.

    1. On the Instance Management page, click Download Client Configuration on an instance card.
    2. Select SDK Configuration File and set the parameters as described in the following table.

      Parameter

      Description

      Chaincode Name

      Enter bcsysq.

      NOTICE:

      The chaincode name must be the same as the name specified during chaincode installation and instantiation.

      Certificate Root Path

      Specify a path for storing certificates. In this example, the path is E:\code\temp.

      Channel

      Select channel.

      Organization & Peer

      Retain the default value.

      Select Orderer Certificate.

      Select Peer Certificates, select organization for Peer Organization, and select Administrator certificate.

    3. Click Download to download the SDK configuration file and the administrator certificates for the node-sdk-demo-orderer and organization organizations.

  3. Copy and decompress the package.

    1. Download the project source code javasdkdemo_src.zip and decompress it.
    2. Decompress the .zip package obtained in 2 and copy the content in the orderer and peer folders to the certificate storage path. Copy the sdk-config.json file to the directory where the certificate is stored and name the file node-sdk-demo-sdk-config.json.

Debugging the Application

  1. Open the sdk-config.js file, and change the path of the SDK configuration file to the path of node-sdk-demo-sdk-config.json.

  2. Run the node query.js command in the path where the project is located to query the account balance of user A. (As shown in the following figure, user A's balance is 10,000 in this example.)

  3. Run the node invoke.js command in the path where the project is located to execute the chaincode to transfer money from user A to user B. As shown in the following figure, the chaincode is successfully executed.

  4. Query the account balance of user A again. The result shows that the money has been successfully transferred. (As shown in the following figure, user A's balance is 9990 in this example.)

Description

  • This demo uses demos in the Fabric community as references. For more demos, visit https://github.com/hyperledger/fabric-samples.
  • Method of customizing an npm repository in the chaincode
    • Create a personal configuration file named .npmrc in the path of the chaincode package. The content of the file is as follows: Registry=https://registry.npm.taobao.org/
    • In this way, when the chaincode container is instantiated, the class library is extracted from the specified repository.
    • Run the npm config get registry command to check whether the address of the customized npm repository has been correctly configured.

Sitemizi ve deneyiminizi iyileştirmek için çerezleri kullanırız. Sitemizde tarama yapmaya devam ederek çerez politikamızı kabul etmiş olursunuz. Daha fazla bilgi edinin

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback