How to use the command minifab (with examples)
This article will guide you through various use cases of the minifab
command, a utility tool that automates the setup and deployment of Hyperledger Fabric networks.
Use case 1: Bringing up the default Hyperledger Fabric network
Code:
minifab up -i minifab_version
Motivation: Bringing up the default Hyperledger Fabric network is the first step in setting up a Fabric network for development or testing purposes. This command helps automate this process, making it quick and easy.
Explanation:
up
: This argument tells theminifab
command to bring up the Fabric network.-i minifab_version
: This optional argument specifies the version of theminifab
utility to use.
Example output:
Bringing up the default Hyperledger Fabric network...
Successfully brought up the network.
Use case 2: Bringing down the Hyperledger Fabric network
Code:
minifab down
Motivation: Bringing down the Hyperledger Fabric network is necessary after you have finished working with it. This command automates the process and ensures that all network resources are properly released.
Explanation:
down
: This argument tells theminifab
command to bring down the Fabric network.
Example output:
Bringing down the Hyperledger Fabric network...
Successfully brought down the network.
Use case 3: Installing chaincode onto a specified channel
Code:
minifab install -n chaincode_name
Motivation: Installing chaincode onto a specified channel is necessary to deploy and update smart contracts in a Fabric network. This command simplifies the installation process by automating it.
Explanation:
install
: This argument tells theminifab
command to install the specified chaincode.-n chaincode_name
: This argument specifies the name of the chaincode to be installed.
Example output:
Installing chaincode onto channel "mychannel"...
Successfully installed chaincode "mychaincode" on channel "mychannel".
Use case 4: Installing a specific chaincode version onto a channel
Code:
minifab install -n chaincode_name -v chaincode_version
Motivation: Installing a specific chaincode version onto a channel allows for easy management and deployment of different versions of smart contracts. This command enables the installation of a specific version of chaincode onto a Fabric network.
Explanation:
install
: This argument tells theminifab
command to install the specified chaincode.-n chaincode_name
: This argument specifies the name of the chaincode to be installed.-v chaincode_version
: This argument specifies the version of the chaincode to be installed.
Example output:
Installing chaincode "mychaincode" version "1.0" onto channel "mychannel"...
Successfully installed chaincode "mychaincode" version "1.0" on channel "mychannel".
Use case 5: Initializing the chaincode after installation/upgrade
Code:
minifab approve,commit,initialize,discover
Motivation: Initializing the chaincode after installation or upgrade is essential to set initial values or perform other necessary setup actions. This command automates the approval, commit, initialization, and discovery process of the chaincode.
Explanation:
approve
: This argument tells theminifab
to perform approval for the chaincode.commit
: This argument tells theminifab
to commit the chaincode changes.initialize
: This argument tells theminifab
to initialize the chaincode.discover
: This argument tells theminifab
to discover the chaincode.
Example output:
Approving chaincode "mychaincode"...
Committing chaincode "mychaincode"...
Initializing chaincode "mychaincode"...
Discovering chaincode "mychaincode"...
Use case 6: Invoking a chaincode method with the specified arguments
Code:
minifab invoke -n chaincode_name -p '"method_name", "argument1", "argument2", ...'
Motivation: Invoking a chaincode method is necessary to interact with the smart contract running on the Fabric network. This command simplifies the invocation process by providing a convenient way to specify the method and its arguments.
Explanation:
invoke
: This argument tells theminifab
command to invoke the specified chaincode method.-n chaincode_name
: This argument specifies the name of the chaincode to be invoked.-p '"method_name", "argument1", "argument2", ...'
: This argument specifies the method name and its arguments.
Example output:
Invoking method "myMethod" with arguments ["arg1", "arg2"] on chaincode "mychaincode"...
Successfully invoked method "myMethod" on chaincode "mychaincode".
Use case 7: Making a query on the ledger
Code:
minifab blockquery block_number
Motivation: Making a query on the ledger allows for retrieving specific information stored on the Fabric network. This command simplifies the query process by providing a convenient way to specify the block number.
Explanation:
blockquery
: This argument tells theminifab
command to query the specified block number.block_number
: This argument specifies the number of the block to be queried.
Example output:
Querying block number 12345...
Block retrieved:
{
"blockNumber": 12345,
"transactions": [...]
}
Use case 8: Quickly running an application
Code:
minifab apprun -l app_programming_language
Motivation: Running an application quickly is useful for testing or showcasing purposes. This command allows for easily running an application on the Fabric network, supporting multiple programming languages.
Explanation:
apprun
: This argument tells theminifab
command to run the application.-l app_programming_language
: This argument specifies the programming language of the application to be run.
Example output:
Running application in Node.js...
Application started successfully.
Conclusion
The minifab
command is a powerful utility tool that offers various functionalities to automate the setup and deployment of Hyperledger Fabric networks. By utilizing the examples provided in this article, you can streamline the development and management of Fabric networks, making the process more efficient and straightforward.