Confusion about Smart contract

Dear guys

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.

  1. 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.
  2. 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
  1. Only a smart contract can change its state. Using a dApp that writes into its state what is given on its ApplicationArgs is the only solution.
  2. The account endpoint (accessible through the SDK too) v2 - Algorand Developer Portal should give you all you need for local state. For global state, you can also use the application endpoint v2 - Algorand Developer Portal

Thanks, fabrice.

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).

For reading it just use the method shown here: Using the SDKs - Algorand Developer Portal

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
}
}]

Explanations of how the state is represented are there: Your First Application - Algorand Developer Portal

In your case, you have two key/values:

  • 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.