Coder Social home page Coder Social logo

convector-example-fabcar's Introduction

Fabcar example in Convector code

This is a Convector-CLI generated project for Hyperledger Fabric.

It is based on the Fabcar chaincode created in Fabric-samples.

The idea is to showcase how to migrate your mental concepts from Go development to TypeScript based Convector smart contracts.

Prerequisites

Run this project

# Compile everything
npx lerna bootstrap
# Wake yourself up a dev blockchain
npm run env:restart
# Now install the chaincode!
npm run cc:start -- car 1

There is also included a NodeJS backend to make a few REST endpoints available.

# Start the backend
npx lerna run dev:debug --scope myapp --stream

A few API endpoints will be available at http://localhost:300. You can test them out with Postman.

GET localhost:3000/api/v1/examples
GET localhost:3000/api/v1/examples/1
POST localhost:3000/api/v1/examples/
Body
{
 "make":"Volkswagen",
 "model":"Jetta",
 "colour":"gray",
 "owner":"Walter Montes",
 "id":"1"
}

How it was done - Smart Contract

As simple as the example looks like, getting around all the Go code may be confusing, so we made it even easier with the framework's CLI.

# In case you don't have Convector-CLI installed already
npm i -g @worldsibu/convector-cli
conv new fabcar -c car
cd fabcar
npm i

Modify the default ./packages/car-cc/src/car.model.ts. and ./packages/car-cc/src/car.controller.ts., refer to Run this project section.

Learn how to make the smart contract from scratch

A tutorial in Hacker Noon here.

Original smart contract code

You can find the original Go Fabcar example here as well the original NodeJS non-Convector file. That way you can compare how a Convector file helps you build better code.

This examples is provided under an Apache 2.0 license.

convector-example-fabcar's People

Contributors

walmon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

convector-example-fabcar's Issues

npm install failed

Hi, I git clone this example and run "npm install" and it fails and asks for "chai" so I install the chai as follows

npm install --save-dev @types/chai

then I run "npm install " again, but it still fails. Here is the error log:

lerna info Symlinking packages and binaries
lerna info lifecycle [email protected]~prepare: [email protected]

[email protected] prepare /home/osboxes/fabric/convector-example-fabcar/packages/car-cc
npm run build

[email protected] build /home/osboxes/fabric/convector-example-fabcar/packages/car-cc
npm run clean && npm run client:generate && tsc

[email protected] clean /home/osboxes/fabric/convector-example-fabcar/packages/car-cc
rimraf dist client

[email protected] client:generate /home/osboxes/fabric/convector-example-fabcar/packages/car-cc
generate-controller-interface -c CarController

../../node_modules/@types/chai/index.d.ts(121,9): error TS8020: JSDoc types can only be used inside documentation comments.
../../node_modules/@types/chai/index.d.ts(122,9): error TS8020: JSDoc types can only be used inside documentation comments.
../../node_modules/@types/chai/index.d.ts(126,16): error TS2370: A rest parameter must be of an array type.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: npm run clean && npm run client:generate && tsc
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/osboxes/.npm/_logs/2019-08-30T23_23_50_972Z-debug.log

Need Help - Did not create the api in the localhost:3000/

Hi,
Need help, Creating the chaincode was succesful but,

Running the command
npx lerna run dev:debug --scope myapp --stream
did not create the api in the localhost:3000/

Let me know something is missed

Result returned when running the command:

myapp: [nodemon] starting node -r ts-node/register --inspect-brk server/index.ts
myapp: Debugger listening on ws://127.0.0.1:9229/3e467566-5a70-441e-8509-a8f0c4b96d14
myapp: For help see https://nodejs.org/en/docs/inspector

Port in README.md reads 300

Port in read me are not the same of as the examples. Easy fix! It now reads A few API endpoints will be available at http://localhost:300. You can test them out with Postman. it should read A few API endpoints will be available at http://localhost:3000. You can test them out with Postman.. Also looking to help out with this project if any is needed !

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.