Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add queries to wasmd section #141

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 61 additions & 4 deletions src/pages/wasmd/getting-started/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,9 @@ sleep 6
wasmd q tx $(echo "$RESP" | jq -r '.txhash') -o json | jq
```

### Query contract state
### Query Contract State All
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Query Contract State All
### Query Contract State: All

Just feels a little easier to read when separated like that!


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
Expand All @@ -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
Expand All @@ -557,6 +558,62 @@ The output will be similar to the following:
}
```

### Query Contract State Raw
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Query Contract State Raw
### 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Query Contract State Smart
### Query Contract State: Smart


To query the state of a WASM contract for specific data, you can use the following command:
chipshort marked this conversation as resolved.
Show resolved Hide resolved

```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
Expand Down