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

Describe building contract and query creation #182

Open
wants to merge 1 commit into
base: cw-tutorial/contract-creation
Choose a base branch
from

Conversation

jawoznia
Copy link
Contributor

@jawoznia jawoznia commented Nov 7, 2024

Part of #176

Copy link

vercel bot commented Nov 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cosmwasm-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 7, 2024 0:45am

Copy link
Contributor

@uint uint left a comment

Choose a reason for hiding this comment

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

Nice! Please don't get discouraged by the number of comments - they're mostly nitpicks. The one thing I think is sort of important is the snake case one.

Overall it's still a very solid guide! :)

@@ -1,4 +1,6 @@
{
"contract-creation": "Contract creation",
"entry-points": "Entry points"
"entry-points": "Entry points",
"building-contract": "Building contract",
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
"building-contract": "Building contract",
"building-contract": "Building the contract",


The `--target` argument tells cargo to perform cross-compilation for a given target instead of
building a native binary for an OS it is running on - in this case, `wasm32-unknown-unknown`, which
is a fancy name for Wasm target.
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
is a fancy name for Wasm target.
is a fancy name for the Wasm target.

building even smaller binaries. For production, all the contracts should be compiled using this
tool, but for learning purposes, it is not an essential thing to do.

## Aliasing build command
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
## Aliasing build command
## Aliasing the build command


## Aliasing build command

Now I can see you are disappointed in building your contracts with some overcomplicated command
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
Now I can see you are disappointed in building your contracts with some overcomplicated command
Now I can imagine you are disappointed in building your contracts with some overcomplicated command


## Checking contract validity

When the contract is built, the last step is to ensure it is a valid CosmWasm contract is to call
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
When the contract is built, the last step is to ensure it is a valid CosmWasm contract is to call
Once the contract is built, the last step is to ensure it is a valid CosmWasm contract by calling

Note that our entry point still has the same `Empty` type for its `msg` argument - it means that the
query message we would send to the contract is still an empty JSON: `{}`

The last thing that changed is the return type. Instead of returning the `Response` type on the
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
The last thing that changed is the return type. Instead of returning the `Response` type on the
The last thing that changed is the return type. Instead of returning the `Response` type for the

query message we would send to the contract is still an empty JSON: `{}`

The last thing that changed is the return type. Instead of returning the `Response` type on the
success case, we return an arbitrary serializable object. This is because queries are not using a
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
success case, we return an arbitrary serializable object. This is because queries are not using a
success case, we return an arbitrary serializable object. This is because queries do not use a

JSON. It is terrible - if we would like to add another query in the future, it would be difficult to
have any reasonable distinction between query variants.

In practice, we address this by using a non-empty query message type. Improve our contract:
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
In practice, we address this by using a non-empty query message type. Improve our contract:
In practice, we address this by using a non-empty query message type. Let's improve our contract:

message: String,
}

#[derive(Serialize, Deserialize)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Our convention is to encode enum variants as snake_case JSON names. We either use the rename_all Serde attribute or go through the cw_serde macro.


Straightforward top-level module. Definition of submodules and entry points, nothing more.

Now, when we have the contract ready to do something, let's go and test it.
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
Now, when we have the contract ready to do something, let's go and test it.
Now, since our contract is ready to do something, let's go and test it.

I'm guessing this better conveys what you meant, could be wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants