Now I have implemented data access by writing the keys of key-value pair in the smart contract and passing the values written in the sdk to the smart contract via the ApplicationArgs parameter.
But I have some doubts about smart contracts.
Can I write the keys of the key-value pair in the sdk, i.e. the data is written entirely in the sdk, so that I can dynamically pass the data to the smart contract via an external function.
How can I quickly query the value in the key-value pair by key in the sdk? I.e., implement the indexing function for key-value pairs
About the second question,you are still fetching data from a large pile of raw data, which is inconvenient.
Now I’m talking to you about my access needs and if you can give me some suggestions for improvement.
I dynamically pass data to the smart contract via an external function (write, including some attributes), and then the external function queries the smart contract for the corresponding value via the primary key (read).
I mean I can quickly look up the value by the key, and the method you describe is to query the entire structure of the local state as follows,which is too complicated.
[{
“key”: “dGltZXN0YW1w”,
“value”: {
“bytes”: “MjAyMS0wNy0wNyBhdCAxNjoyMTo0Mw==”,
“type”: 1,
“uint”: 0
}
}, {
“key”: “Y291bnRlcg==”,
“value”: {
“bytes”: “”,
“type”: 2,
“uint”: 1
}
}]
key = "dGltZXN0YW1w" in base64, that is "timestamp". Associated value is a byte array "MjAyMS0wNy0wNyBhdCAxNjoyMTo0Mw==" in base64, that is "2021-07-07 at 16:21:43"
key = "Y291bnRlcg==" in base64, that is "counter". Associated value is an integer 2
To convert a base64 value into a string, use the following command line:
$ base64 -d <<< MjAyMS0wNy0wNyBhdCAxNjoyMTo0Mw==
2021-07-07 at 16:21:43
PS: Please write any output/code inside triple backquotes ``` to make it much easier to read. I’ve modified your post.