Skip to content

Instantly share code, notes, and snippets.

@Vishwas1
Last active April 9, 2019 03:54
Show Gist options
  • Save Vishwas1/f2dfba54ba0495d5f37dba0692b0f057 to your computer and use it in GitHub Desktop.
Save Vishwas1/f2dfba54ba0495d5f37dba0692b0f057 to your computer and use it in GitHub Desktop.

Hurl

  • hurl is a tool create hyperledger easily. Its just a wrapper over native HL fabric.
  • Analogy to hurl could be Ganache.
  • After network creation via hurl, we can see the configurations files in the folder:

Install Hurl

sudo npm install -g @worldsibu/hurley --unsafe-perm=true
hurl --version

o/p

1.0.4

Note: Previous version 1.0.3 had bug.

Create HL Fabric Network

hurl new

Network topology after running this command:

[hurley] - Ran network restart script
[hurley] - ************ Success!
[hurley] - Complete network deployed at /home/vishswasb/hyperledger-fabric-network
[hurley] - Setup:
        - Organizations: 2
            * org1
            * org2
        - Users per organization: user1 
            * admin 
            * user1
        - Channels deployed: 1
            * ch1
        
[hurley] - You can find the network topology (ports, names) here: /home/vishswasb/hyperledger-fabric-network/docker-compose.yaml
  • The above command will create a network with 2 org, 1 user per org, 1 admin per org, 1 peer per org.
  • You can configure hurl to create multiple org nodes using command something like this hurl new -o 3 -u 5 // will create 3 org with 5 user each
  • Follow this doc for more.

Installing ChainCode

cd to the chaincode directory, and run hurl install <nameOfChainCode> <programmingLanguage> command to install the chaincode to the HL fabric ledger. In this case, I am going to install the fabcar chaincode.

cd fabric-samples/chaincode/chaincode_example02/node
hurl install example02 node --ctor '{"Args":["Init","walter","100","diego","200"]}'     

O/p

Installing Chaincode example02 version 1.0 at org1
2019-04-08 08:13:53.846 IST [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-04-08 08:13:53.846 IST [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2019-04-08 08:13:53.890 IST [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" > 
Installed Chaincode example02 version 1.0 at org1
Installing Chaincode example02 version 1.0 at org2
2019-04-08 08:13:53.945 IST [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-04-08 08:13:53.945 IST [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
2019-04-08 08:13:53.954 IST [chaincodeCmd] install -> INFO 003 Installed remotely response:<status:200 payload:"OK" > 
Installed Chaincode example02 version 1.0 at org2
Instantiating Chaincode at org1 for channel ch1
It may take a few minutes depending on the chaincode dependencies
2019-04-08 08:14:04.019 IST [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2019-04-08 08:14:04.020 IST [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
Instantiated Chaincode at org1

Upgrade ChainCode

Format: hurl upgrade <chaincode> <programmingLanguage> <version>

hurl upgrade example02 node 1.1

Invoke ChainCode

hurl invoke example02 query "walter"

O/P

[hurley] - walter
[hurley] - Sending transaction as user1 in org org1...
[hurley] - Transaction sent! VALID  SUCCESS 46d5e20ef8a7d6533eeade1810dab8c32cfe4e77708e0e3f7310f0c0c7eca53a
[hurley] - Result: 100

For any help: https://medium.com/worldsibu/fabric-samples-made-easier-with-hurley-the-development-environment-manager-c75b44fa6ac6 https://github.com/WorldSibu/hurley https://discordapp.com/channels/411401661714792449/411401661714792451

Convector

  • Convector is a framework to write smart contract on HL fabric. It creates a boiler plate for you to write contract. It also make smart contract writing a lot easier.
  • Moreover, you can updagrade your contract, if need by just using one simple command.
  • It also provides framework to test your code.
  • Sitting on convector itself, you can deploy your contract on the network created by hurl
  • Analogy to Convector could be Truffle.
npm i -g @worldsibu/convector-cli

# Create a new project with a default chaincode package
conv new PROJECT-NAME -c CHAINCODE-NAME

cd PROJECT-NAME

npm i

# Bring up a development blockchain in your computer
npm run env:restart

# Install the chaincode to the blockchain
npm run cc:start -- CHAINCODE-NAME 1

# Apply all the changes you want to the project.
# When you need to upgrade your chaincode in the blockchain, you can simply do
npm run cc:upgrade -- CHAINCODE-NAME 2

conv generate chaincode participant

Install Convector

npm i -g @worldsibu/convector-cli
conv --version

Create a new project

conv new <projectName> -c <chainCodeName>

Ex:

conv new fabcar -c car
cd fabcar
npm i

It will create a boiler plate project called, fabcar with chaincode car.

Note*: It is not mandatory to use Convector, we can simply use Hurley to create our and network and deploy chaincode written outside the Convector

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment