DL Fabric Gateway™ User Guide— Section 8

This post is part of the ‘DL Fabric Gateway™ User Guide’ originally published as

This post continues our ongoing discussion regarding invoking chaincode on DL Fabric Gateway™.

Invoking Chaincode on DL Fabric Gateway™

Invocation is the primary method of interaction with chaincode — invocation being another way of saying “call a function from the chaincode”.

IMPORTANT — In order to invoke chaincode, it must be installed on a given channel. This was done in the previous section.

Goal

Invoke chaincode on DL Fabric Gateway™ using the fab_invokeChaincodeAPI:

POST
https://dlfabricnetwork.dltlabs.com/api/1.0/fab_invokeChaincode

Step 1

Open a Command Line Interface (CLI) of your choice (Terminal, cmd, etc.)

Step 2

Install curl (if not already installed): Download links — Linux/Windows

Step 3

Copy and paste the following API Call into your CLI of choice, and tap “enter” on your keyboard

curl -X POST \
‘https://dlfabricnetwork.dltlabs.com/api/1.0/fab_invokeChaincode' \
-H ‘Content-Type: application/json’ \
-H ‘Authorization: AUTH_TOKEN_HERE’ \
-d ‘{
“userName” : “your@email.com”,
“chaincodeName” : “YourChaincode”,
“args” : [“CAR1”, “Acura”, “MDX”, “Black”, “Jovan”],
“functionName” : “createCar”,
“channelName”:”yourchannel”
}’

a) functionName is the function to be called when invoking chaincode (in this case, createCar, as specified in fabcar.go), and args are the arguments to be passed into the function specified in functionName.

Example:

Image for post
Image for post

Which will return a success response:

{
“status”: “success”,
“message”: “Successfully invoked the chaincode.”
“transactionId”: “8bd4ec291e06a1016ab1e561cf6d6e04de604431e95d1af0cedc4da90900c4fd

}

b) The transactionId specified in the response is very important, as this is where you will be able to reference a permanent record of the chaincode invocation. When building applications, it is suggested that you store transactionIds (i.e. in a DB) so that they can be referenced in the future.

Image for post
Image for post

Written by

DLT Labs is a global leader in Distributed Ledger Technology and Enterprise Products. To know more, head over to: https://www.dltlabs.com/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store