Smart contract development takes go language as an example, and ChaincodeStubInterface is the core interface of smart contract. This article mainly explains all common methods of this interface. For video learning, you can refer to video tutorials

  • Stub.putstate (ARgs [0],[] Byte (args[1])) is used to store data in K-V format.
  • Stub.getstate (args[0]) gets value based on key
  • Stub.delstate (key) Deletes the value of a key
  • Stub.gethistoryforkey (key) Retrieves all history records based on a key
  • Stub.getqueryresult (Query) supports CouchDB, and uses rich query statements to query data, which is useful when storing data as JSON. Such as {” id “:” 123 “, “name” : “liwei”, “age” : “18”}, can according to the name attribute to query the records.
  • Stub. GetQueryResultWithPagination (query string, pageSize int32, bookmark string) paging query based on query paging query, pageSize is paging display the number of each page, Bookmark is the txId that you want to start the query with. If the input is empty at the beginning, the query will automatically start from scratch. The txId of the last record will be returned as the input parameter for the next query.
  • Stub. GetStateByRangeWithPagination (startKey, endKey string, pageSize int32, bookmark string) query must be within the scope of the data, followed by starting the key parameters, End key, paging size, txId, for example, such as query key from a to Z data, a total of 18, paging size is 10, then the first query txId is empty, query results return data and return the next txId, txId as a query parameter, in the second query.

Processing of private data

  • Stub.putprivatedata (Collection String, Key String, Value []byte) Collection is the name of the private data set
  • Stub. GetPrivateData(Collection, Key String) Obtains private data
  • Stub. GetPrivateDataByRange (collection, startKey endKey string) branch key range queries no paging
  • Stub. GetPrivateDataQueryResult (collection, query string) private data query * rich roam technology, enjoy life