GithubHelp home page GithubHelp logo

hfc-nodejs's Introduction

Hyperledger Fabric Nodejs SDK 와 ExpressJS 사용하여 서버구축하기

시작하기전에

  • https://github.com/sjlee1125/Multi-Host-Fabric-Network 참조하여 기본적인 네트워크 구성

  • 이번에는 chaincode_example02 코드가아닌 fabcar chaincode를 설치한다.

    change Org1-Peer0
    $ peer chaincode install -n fabcar -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/fabcar
    change Org1-Peer1
    $ peer chaincode install -n fabcar -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/fabcar
    change Org2-Peer0
    $ peer chaincode install -n fabcar -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/fabcar
    change Org2-Peer1
    $ peer chaincode install -n fabcar -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/fabcar
  • Instantiate Chaincode

    $ peer chaincode instantiate -o orderer0.example.com:7050 -C mychannel -n fabcar -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
  • Invoke Chaincode

    $ peer chaincode invoke -o orderer0.example.com:7050 -C mychannel -n fabcar -c '{"function":"initLedger","Args":[""]}'
  • Query Chaincode

    $ peer chaincode query -o orderer0.example.com:7050 -C mychannel -n fabcar -c '{"function":"queryAllCars","Args":[""]}'

    Query후 Json형식의 text출력하면 완료

ExpressJS사용하여 Server구축

  • node libraries install

    $ cd hfc-nodejs
    $ npm install
  • Admin 등록

    hfc_enrollAdmin.js의 42번째줄 수정

    ca를 가지고있는 주소와 포트, ca의 aliases된 network에서의 이름

    fabric_ca_client = new Fabric_CA_Client('org1의 ca주소', tlsOptions , 'org1 ca의 aliases된 network에서의 이름', crypto_suite);
    -> fabric_ca_client = new Fabric_CA_Client('http://test-pc4:7054', tlsOptions , 'ca.org1.example.com', crypto_suite);
    

    수정후 아래의 명령어 수행

    $ node hfc_enrollment.js
  • User 등록hfc_registerUser.js의 42번째줄 수정

    ca를 가지고있는 주소와 포트, ca의 aliases된 network에서의 이름

    fabric_ca_client = new Fabric_CA_Client('org1의 ca주소', tlsOptions , '', crypto_suite);
    -> fabric_ca_client = new Fabric_CA_Client('http://test-pc4:7054', tlsOptions , '', crypto_suite);
    

    수정후 아래의 명령어 수행

    $ node hfc_registerUSer.js
  • 아래의 명령어로 완료되었는지 확인

    $ node hfc_query.js
  • Install ExpressJS

    $ npm install express --save
  • Server 구동

    $ node hfc_server.js 
  • Testing

    브라우저에 아래의 텍스트 입력

    "PC4의 IP주소":8081/api/query

    result

hfc-nodejs's People

Contributors

sjlee1125 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.