From b6bfe198846a77bf9dc7f4d8c68ff13eef416f60 Mon Sep 17 00:00:00 2001 From: Pino' Surace Date: Thu, 15 Aug 2024 14:29:54 +0200 Subject: [PATCH 1/2] Add queries to wasmd section --- src/pages/wasmd/getting-started/cli.mdx | 65 +++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/src/pages/wasmd/getting-started/cli.mdx b/src/pages/wasmd/getting-started/cli.mdx index 8c422ede..4c74183d 100644 --- a/src/pages/wasmd/getting-started/cli.mdx +++ b/src/pages/wasmd/getting-started/cli.mdx @@ -514,9 +514,9 @@ sleep 6 wasmd q tx $(echo "$RESP" | jq -r '.txhash') -o json | jq ``` -### Query contract state +### Query Contract State All -To query the state of a WASM contract, you can use the following command. +To query the state of a WASM contract, you can use the following command: ```sh wasmd query wasm contract-state all "$CONTRACT" -o json @@ -539,9 +539,10 @@ The output will look similar to this: } ``` -`Models` are key-value pairs representing the state data of the contract base64-encoded. +The `"models"` array contains key-value pairs representing the state data of the contract, with both +keys and values base64-encoded. -We can decode the contract state using the following command: +You can decode the contract state using the following command: ```sh wasmd query wasm contract-state all "$CONTRACT" -o json | jq -r '.models[0].value' | base64 -d @@ -557,6 +558,62 @@ The output will be similar to the following: } ``` +### Query Contract State Raw + +To query the state of a WASM contract for a specific key, you can use the following command: + +```sh +# Set the state key you want to query +KEY="636F6E666967" +wasmd q wasm contract-state raw $CONTRACT $KEY -o json +``` + +The output will look similar to this: + +```json +{ + "data": "eyJ2ZXJpZmllciI6Indhc20xNzlhdnc5NmFheTcwcHM5OXVtdWFlc3h4Y3p3YzBxbTVnd3VmeGciLCJiZW5lZmljaWFyeSI6Indhc20xNDI3a3BxOW1tbmZwMG1hZGs1YXhoMnVrbWpncGZoNnNremR4a3UiLCJmdW5kZXIiOiJ3YXNtMTc5YXZ3OTZhYXk3MHBzOTl1bXVhZXN4eGN6d2MwcW01Z3d1ZnhnIn0=" +} +``` + +`"data"` represents the base64-encoded state data of the contract for the given key. + +You can decode the `data` field using the following command: + +```sh +wasmd q wasm contract-state raw $CONTRACT $KEY -o json | jq -r '.data' | base64 -d +``` + +The output will be similar to the following: + +```json +{ + "verifier": "wasm1hvgm6p76gccgg4dl4caa8a7v03dsqww6r9sk4g", + "beneficiary": "wasm1pa29lac5s85kgj7pn9z6gc0t4sqgzllcguhf24", + "funder": "wasm1hvgm6p76gccgg4dl4caa8a7v03dsqww6r9sk4g" +} +``` + +### Query Contract State Smart + +To query the state of a WASM contract for specific data, you can use the following command: + +```sh +# Set the query for the data you want to retrieve +QUERY='{"verifier": {}}' +wasmd q wasm contract-state smart $CONTRACT $QUERY -o json +``` + +The output will look similar to this: + +```json +{ + "data": { + "verifier": "wasm179avw96aay70ps99umuaesxxczwc0qm5gwufxg" + } +} +``` + ## Migration Migration is the process of upgrading an existing contract to a new version without changing its From 29cbc60690d8be22395c1f4ca0af215e0e31d4a0 Mon Sep 17 00:00:00 2001 From: Pino' Surace Date: Fri, 11 Oct 2024 14:03:40 +0200 Subject: [PATCH 2/2] Fix comments --- src/pages/wasmd/getting-started/cli.mdx | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/pages/wasmd/getting-started/cli.mdx b/src/pages/wasmd/getting-started/cli.mdx index 4c74183d..1a1de482 100644 --- a/src/pages/wasmd/getting-started/cli.mdx +++ b/src/pages/wasmd/getting-started/cli.mdx @@ -514,7 +514,12 @@ sleep 6 wasmd q tx $(echo "$RESP" | jq -r '.txhash') -o json | jq ``` -### Query Contract State All +### Query Contract State: All + +`All` queries allow you to retrieve all the key-value pairs stored in the contract's state. This +method directly accesses the contract's underlying key-value storage without invoking any contract +logic. It's useful for inspecting the entire state of a contract, especially during development or +debugging. To query the state of a WASM contract, you can use the following command: @@ -558,7 +563,11 @@ The output will be similar to the following: } ``` -### Query Contract State Raw +### Query Contract State: Raw + +`Raw` queries allow you to fetch data directly from the contract's key-value storage using a +specific key. This method bypasses the contract's logic and retrieves the raw stored data, which is +base64-encoded. It's useful when you know the exact key of the data you're interested in. To query the state of a WASM contract for a specific key, you can use the following command: @@ -594,7 +603,13 @@ The output will be similar to the following: } ``` -### Query Contract State Smart +### Query Contract State: Smart + +`Smart` queries allow you to retrieve structured data by interacting with the contract's query +endpoints. This method invokes the contract's logic with a specific query message, allowing you to +get processed and meaningful data from the contract. The content of the query message depends on the +specific contract you're interacting with, as each contract defines its own set of query messages +and expected formats (see the [query section](../../core/entrypoints/query) for more details). To query the state of a WASM contract for specific data, you can use the following command: