Skip to content

Instantly share code, notes, and snippets.

@jorgedison
Last active December 14, 2019 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgedison/65508a597e6725209ed34cd9145ef294 to your computer and use it in GitHub Desktop.
Save jorgedison/65508a597e6725209ed34cd9145ef294 to your computer and use it in GitHub Desktop.
Chaincode nodejs
# Creacion de chaincode nodejs
#Ruta: ~/hyperledger/fabric/curso-fabric/chaincode
mkdir notasnodejs
cd notasnodejs
npm init
npm install --save fabric-contract-api
npm install --save fabric-shim
#Tomar como referencia
#package.json -> https://raw.githubusercontent.com/jorgedison/Prueba-Hyperledger-Fabric/master/chaincode/notasnodejs/package.json
#index.js -> https://raw.githubusercontent.com/jorgedison/Prueba-Hyperledger-Fabric/master/chaincode/notasnodejs/index.js
#logica.js -> https://raw.githubusercontent.com/jorgedison/Prueba-Hyperledger-Fabric/master/chaincode/notasnodejs/logica.js
npm install
# Iniciar e Instanciar chaincode nodejs
docker exec -it cli bash
export CHANNEL_NAME=marketplace
export CHAINCODE_NAME=notasnodejs
export CHAINCODE_VERSION=0
export COMPOSE_PROJECT_NAME=acmenetwork
export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/acme.com/orderers/orderer.acme.com/msp/tlscacerts/tlsca.acme.com-cert.pem
#Instala chaincode
peer chaincode install -l node -n $CHAINCODE_NAME -p "/opt/gopath/src/github.com/chaincode/notasnodejs" -v $CHAINCODE_VERSION
#Listado de chaincode instalados
peer chaincode list --installed -C $CHANNEL_NAME
#Instancia chaincode
peer chaincode instantiate -o orderer.acme.com:7050 --tls --cafile $ORDERER_CA -C $CHANNEL_NAME -n $CHAINCODE_NAME -l node -v $CHAINCODE_VERSION -c '{"Args":[]}'
#Listado de chaincode instanciados
peer chaincode list --instantiated -C $CHANNEL_NAME
#Registra Notas
peer chaincode invoke -o orderer.acme.com:7050 -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{"function":"registraNotas","Args":["jorge","10","15","20"]}'
#Consulta Notas
peer chaincode query -o orderer.acme.com:7050 -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{"function":"consultaNotas","Args":["jorge"]}'
#Elimina Notas
peer chaincode invoke -o orderer.acme.com:7050 -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{"function":"eliminaNotas","Args":["Alice"]}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment