30 C
Gurgaon
Thursday, November 7, 2024

Blockchain Interview Questions

Must read

Did we get any default network during Hyperledger Fabric Installation?

When you download fabric, you get dev and test network as sample networks.

 What are the important files in Fabric Network?

·        crypto-config.yaml

·        configtx.yaml

·        docker-compose.yaml

 What is crypto-config file and why it is used?

This file consists of three below sections.

·        Orderers

·        Peers

·        Users

Purpose of this file to create crypto material for all the participants. Remember MSP that is used to store the issue and store the identity.

Which command you use to run crypto-config file?

cryptogen

 What is configtx file and why it is used?

This file is used to create genesis block (very first block in blockchain) and create channel artifacts.

 What is docker-compose file and why it is used?

As Fabric network is docker based so this contains details about all containers and command to start and stop the network.

What command you use to create new channel?

./network.sh createChannel -c <channelName>

What is chaincode in Fabric?

Chaincode also known as smart contract is program in Hyperledger Fabric that implements the business logic in network.

At high level, perform one of two tasks, either update the ledger or query the data from ledger.

Client application invokes the Chaincode only to read or update the data to ledger. It runs in separate docker container.

 List down Chaincode development language

·        Go Lang

·        Java

·        Java & Type Script

·        NodeJs

 Can you deploy multiple chaincode in one Fabric network?

Yes, you can deploy n number of chaincode in fabric network.

 Can you have one java chaincode and Go chaincode in Fabric network?

Yes, you have different chaincode running in Fabric network developed in different languages.

 Does Fabric support solidity language for chaincode development?

No, not as of today.

  List down Chaincode development API available in Go Lang

·        Low Level API

·        High Level API (2.x onwards)

 What are the steps for Chaincode development using Low Level API

At high level, you can categories chaincode in below sections in low level API.

·        Import section

·        Struct section     

·        Init function section  

·        Invoke function section

·        Custom functions section

·        Main function section

What is Chaincode Interface in Low Level API?

Chaincode interface must be implemented by all chaincodes. Below is the syntax of that. As you can see there are two functions defined one is Init and other is Invoke so every chaincode need to implement these functions.

type Chaincode interface {

                 // Init is called during Instantiate transaction after the chaincode container

                 // has been established for the first time, allowing the chaincode to

                 // initialize its internal data

                 Init(stub ChaincodeStubInterface) pb.Response

                 // Invoke is called to update or query the ledger in a proposal transaction.

                 // Updated state variables are not committed to the ledger until the

                 // transaction is committed.

                 Invoke(stub ChaincodeStubInterface) pb.Response}

 What is Init function and why it is used?

Init function is called when a chaincode receives an instantiate or upgrade transaction. This is where you will initialize any application state.

What is Invoke function and why it is used?

Invoke function is called when the invoke transaction is received to process any transaction proposals.

How many Init and Invoke functions we can have?

When you use low level API, you can have only one Init and one Invoke function only. Rather you can n number of custom functions that can be called from Invoke function.

Can you call Invoke function without initializing your chaincode?

No, you first need to initialize your chaincode before you call Invoke function.

 What is ChaincodeStubInterface ?

ChaincodeStubInterface provides the functions that are used to access and modify the ledger, and to make invocations between chaincodes. Below is short syntax of that.

As you see in below functions, there are many functions available that you can use in your chaincode to interact with level or counch DB and for other purposes.

type ChaincodeStubInterface interface {

                 GetArgs() [][]byte

                 GetStringArgs() []string

                 GetFunctionAndParameters() (string, []string)

                 GetArgsSlice() ([]byte, error)

                 GetTxID() string

                 GetChannelID() string

                 InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response

                 GetState(key string) ([]byte, error)

                 PutState(key string, value []byte) error

                 DelState(key string) error

                 GetStateValidationParameter(key string) ([]byte, error)

                 GetStateByRange(startKey, endKey string) (StateQueryIteratorI

What is High Level API?

High Level API also known as contract API. This API is used to develop chaincode using go language.

This comes in Fabric 2.x version and makes the development of chaincode easy.

 List down the high level steps for chaincode development using high level api?

At high level, you can categories chaincode in below sections in high level API.

·        Import section

·        Struct section     

·        Function section

·        Main function section

 Which package we need for high level api?

github.com/hyperledger/fabric-contract-api-go/contractapi

 Do you have any Init & Invoke function in high level api?

No, you need not to define Init & Invoke when you develop chaincode using high level api.

Although in backend high level API call low level API.

 What function you will use to catch the error?

Error() is the function used to capture error details.

 How many functions you can define using high level api?

You can define n number of functions inside your chaincode when you use high level api.

 What function is used to query and update the state?

You can use GetStub().PutState() function to update the state.

You can use GetStub().GetState() function to query the state.

All of these blockchain interview questions have a different level of difficulty attached to it. To ensure that you can go through them without any issue, we will group similar questions. These questions will help you engage with the answers thoroughly and prepare in the best form possible..Blockchain Tutorials is combination of two words, Block and chain so blockchain is chain of blocks and each block store transaction.Each block in blockchain store more than transaction and that transaction count vary for public and private blockchain.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article