Udemy

Hands On: Chaincode Interface

A free video tutorial from Rajeev Sakhuja
11xAWS Certified, Consultant, Mentor, Innovation evangelist
Rating: 4.5 out of 5Instructor rating
8 courses
114,650 students
Hands On: Chaincode Interface

Lecture description

Students will learn about the required functions in the chaincode. After that students will test the chaincode using the dev environment and the utility scripts.

Learn more from the full course

Mastering Hyperledger Chaincode Development using GoLang

Design and develop Fabric 2.1 applications from end-to-end using GoLang & Fabric Node SDK

10:04:53 of on-demand video • Updated March 2024

Chaincode development using GoLang
Application Development using Fabric Node SDK
Use of Private Data
Use of Instantiation & Endorsement policies
Building support for Rich Queries & Asset History
Building Programmatic access control with "Client Identity Library"
Testing tools for Chaincode such as Golang Testing framework & MockStub
English [Auto]
Chain called Interface Functions in this walk through an exercise, I will be showing you the code in the minimal implementation of a chain code. We will go through the code and in it in walk and the main function, and then you will execute commands against this minimalistic implementation of the chain code in this lecture order, referring to the version one of the token chain code, the testing instructions that are following this lecture are available in the V1 readme, not modified. In the last lecture I talked about the fact that all chain code instances must register with the fabric runtime. This registration is carried out in the main method by way of the invocation of the Chambord Start function. The symbolic start function registers the instance of the chain code with the fabric runtime, and it takes an instance of the type structure that represents the chain code. For instance, chain code interface functions in it and invoke have the same function signature. Both of these functions apply to the instance of the structure representing the chain code. They both take the argument of type or chain code, stop interface and response. Back to the caller with an instance of here dot response. I will be covering the note chain code, stop interface and product response in later lectures. Open the version one of coconut go file and in this file you will find there are three import statements. The first one is the import of the format package. This is for printing or messages to the console. Second one is the Shim package and third one is the pure package. I will be discussing the package in a later lecture type. Token code represents the Chanko object in this setup to which the chain code interface will apply. It is the in a method which takes as input an object of type chain code style interface and responds back with a response within the implementation of the Init method. We are simply printing out a message to the console in it, executed and then returning success by executing Chiemgauer success, which indicates to the fabric runtime that the execution of the chain code was successful. This is the invoke method that takes as input an object of type Shinda chain code, stub, interface and response backward pirot response type object. In the implementation, we're simply printing a message to the console, invoke, executed and then returning success as a response. This is the main function that gets executed when the chain code is launched. The first thing it does is print start a chain code and then in walks the Chiemgauer start function that registers the chain code with the fabric runtime. If there is an error, the error message is printed out to the console and the execution of the chain code stops. So version one of the chain code has all the required functions implemented and it is ready to be launched and tested. And to test this chain code, we are going to use the instructions in the read me not empty file. I suggest that at this point you pause the video and try out the instructions in the lead me, not me on your own. Open the file, first thing we need to do is launch the dev environment with the dashi options so that we have access to the Explorer. This will take a minute or so. Noninvolvement environment has launched, let's clear the window reset into the next step, we need to set up the environment so we will use the Sedergreen as hardscape set the context to Achmat set of the chain code environment songer to copy the line from here for setting up the chain code environment. Please notice we are setting the name of the chain token and the path is tokens. We won after this. We need to install the chain code, but first we have to package it. So I'm going to copy the chain as a package from here and execute a search package after the package is created. We need to carry out the installation. So I'm going to copy Chinderah as such, install and pasted here, Chenard, etc. install is successful. So let me just reset the screen or the next step. We have to approve and commit the chain code to approve. We will use the command chain assets approved for my org and this will approve the chain code for the Acme Organization. To create the cummock. We will use the command chain, the asset command and the command was successful. Now let's go ahead and check out the transactions in the Explorer. Our orders follow link here. You will see that there are five transactions. These first three transactions are for the channel creation and channel joint for Ackmann budget. This transaction is for the approval and this one is for the comet. We on stuff for which requires us to read the logs from the Chilkoot container. So Kiddush logs dot S.H. Dashty ten dash f. Now we are reading the log messages as they will come in from the chain code for the next step. We need to open up another terminal window and do that. Click on the split terminal, log in to vagrant vagrant as has each set the environment. So copy this and set up the environment as a next step. We need to initialize the chain code because if you don't initialize the chain code, it would lead to an error. So sextape is in it. And now observe terminal number one and you can see this in it. Executed in V1. I want to end it is executed. You ready to execute the Cendant S.A.T. and Tejinder S.H. invokes. So let's execute query and as you can see here and walk executed in vivants. Similarly, if I execute in invoke I will see the same message there. Now if you want, you can check out the explorer as well and you will see additional transactions for the invoke. And these are the two transactions for invoke. And you will observe that these two transactions have the chain called cocain in it because they were executed only cocain chain called Time to Go Over the key points and empty structure is used as a representation of the chain called chain code. Instances register with the fabric runtime by executing the Chiemgauer start function within the main function, both in it and invoke functions. Take an argument of by Chhim Dogen Chain Code Stub Interface and respond back with an instance of biproduct response.