Hyper Ledger allows you to deploy custom code (today written in the Go programming language, with Java support under development) to the block chain. This code (knows as chaincode) is called in response to transactions being submitted to the block chain, or the state of the block chain being queried.

Chaincode exposes three main entry point functions:

  • func (t *SimpleChaincode) Init(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error)
  • func (t *SimpleChaincode) Invoke(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error)
  • func (t *SimpleChaincode) Query(stub *shim.ChaincodeStub, function string, args []string) ([]byte, error)

Note: the signatures of these methods has changed in the latest Hyper Ledger code.

The Init function is called when chaincode is deployed to allow the chaincode to initialize state as required.

The Invoke function is called when the client wishes to interact with the block chain in read/write mode (e.g. submitting a transaction).

The Query function is called when the client wishes to interact with the block chain in read-only mode (e.g. querying the state).

Here is a simple example chain code that allows a numeric value to be associated with a named party, and for transfers to be performed between named parties.

Chaincode uses a stub to interact with a key/value store, allowing the chaincode to store (read or write) arbitrary state outside the block chain.

For example, the code linked above uses the stub to associate the named-party (as the key), with their current value (a long serialized as a string).

err = stub.PutState(A, []byte(strconv.Itoa(Aval)))

The key/value pairs for Hyper Ledger are not stored on the block chain itself, but are currently stored in a RocksDB instance (though Hyper Ledger are working to make this pluggable).