The ChaincodeStub Interface

In the The Contract Class section, we mentioned that every transaction function takes a transaction context as the first parameter. The context object itself contains an implementation of the ChaincodeStub interface in the stub field.

The ChaincodeStub interface encapsulates API to interact with the world state, private collections, transaction proposal, etc. This interface is essential for smart contracts and widely used in chaincode implementations.

The functions provided by the ChaincodeStub interface can be divided into several groups. Click to expand each box and learn more.

ChaincodeStub Function Groups

  • Get/Put data into the ledger or private collections

    • getState

    • putState

    • getPrivateData

    • ...

  • Perform complex queries

    • getStateByRange

    • getStateByPartialCompositeKey

    • getQueryResult

    • ...

    ****

  • Fetch transaction proposal details

    • getArgs

    • getCreator

    • getChannelID

    • ...

    ****

  • Make invocations between chaincodes

    • invokeChaincode

    ****

  • Emit chaincode events

    • setEvent

    ****

  • Simplify chaincode development (helper functions)

    • getFunctionAndParameters

    • splitCompositeKey

    • ...

Last updated

Was this helpful?