// Retrieve value from state using GetState func (cc *MyChaincode) GetValue(stub shim.ChaincodeStubInterface, key string) (string, error) { bytes, err := stub.GetState(key) if err != nil { return "", err } return string(bytes), nil }
// Check if value is present in state using GetState func (cc *MyChaincode) ValueExists(stub shim.ChaincodeStubInterface, key string) (bool, error) { bytes, err := stub.GetState(key) if err != nil { return false, err } return bytes != nil, nil }In this example, `ValueExists` function is defined which takes a `key` as input parameter and checks if the corresponding value exists in the blockchain ledger using `GetState` function. It returns `true` if the value exists and `false` otherwise.