-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from CosmWasm/init-core
Initial docs for core
- Loading branch information
Showing
15 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
tags: ["core"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
import Tags from "@/components/Tags"; | ||
|
||
<Tags /> | ||
|
||
# Introduction | ||
|
||
This chapter will give you an overview over CosmWasm from a contract developer | ||
perspective, its capabilities, and guide you through initializing your first | ||
smart contract. | ||
|
||
<Callout> | ||
We assume you have basic knowledge of Rust and Cargo (its standard build | ||
system) | ||
</Callout> | ||
|
||
## What is CosmWasm? | ||
|
||
CosmWasm is a platform for writing smart contracts for Cosmos chains using Rust | ||
and WebAssembly. | ||
Meaning CosmWasm is your one-stop shop for developing, testing, and running | ||
smart contracts on enabled chains. | ||
|
||
## What does CosmWasm provide? | ||
|
||
For you, a contract developer, CosmWasm provides a set of high-quality | ||
primitives through our standard library. These primitives include: | ||
|
||
- extended precision arithmetic (128, 256, 512-bit integers) | ||
- cryptographic primitives (for example, secp256k1 verification) | ||
- interaction with the Cosmos SDK | ||
|
||
## What does CosmWasm _not_ provide? | ||
|
||
- Abstractions to simplify contract development (for this, check out | ||
[Sylvia](/sylvia)) | ||
- Storage abstractions (for this, check out [Storey](/storey)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"installation": "Installation", | ||
"entrypoints": "Entrypoints", | ||
"standard-library": "Standard Library" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
tags: ["core"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
import Tags from "@/components/Tags"; | ||
|
||
<Tags /> | ||
|
||
# Entrypoints | ||
|
||
Entrypoints are where your contract can be called from the outside world. You | ||
can equate that to your `main` function in C, Rust, Java, etc. | ||
However, there is one _small_ difference: In CosmWasm, you have multiple of | ||
these entrypoints, each one different from the last. | ||
|
||
In this section we want to give you a quick overview over all the entrypoints | ||
and when they are called. | ||
|
||
## Define entrypoints | ||
|
||
While you will learn all about entrypoints in the next sections, we want to give | ||
you an idea on how to define an entrypoint in the first place. | ||
|
||
CosmWasm defines the handy `#[entry_point]` attribute macro. You simply annotate | ||
a function with it, and it automatically generates code that communicates to the | ||
VM: "Hey! This is an entrypoint, please use it when needed!" | ||
|
||
<Callout> | ||
When defining an entrypoint, it is important to use the correct types for the | ||
parameters and return type. Incorrect types will cause errors when trying to | ||
call the contract. | ||
<br /> In the following sections we will take a look at all possible entrypoints, | ||
including the correct function signature. | ||
</Callout> | ||
|
||
```rust | ||
#[entry_point] | ||
pub fn instantiate( | ||
deps: DepsMut, | ||
env: Env, | ||
info: MessageInfo, | ||
msg: InstantiateMsg, | ||
) -> Result<Response, StdError> { | ||
// Do some logic here | ||
Ok(Response::default()) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"instantiate": "Instantiate", | ||
"execute": "Execute", | ||
"query": "Query", | ||
"migrate": "Migrate", | ||
"sudo": "Sudo" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
tags: ["core", "entrypoints"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
import Tags from "@/components/Tags"; | ||
|
||
<Tags /> | ||
|
||
# Execute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
tags: ["core", "entrypoints"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
import Tags from "@/components/Tags"; | ||
|
||
<Tags /> | ||
|
||
# Instantiate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
tags: ["core", "entrypoints"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
import Tags from "@/components/Tags"; | ||
|
||
<Tags /> | ||
|
||
# Migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
tags: ["core", "entrypoints"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
import Tags from "@/components/Tags"; | ||
|
||
<Tags /> | ||
|
||
# Query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
tags: ["core", "entrypoints"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
import Tags from "@/components/Tags"; | ||
|
||
<Tags /> | ||
|
||
# Sudo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
tags: ["core"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
import Tags from "@/components/Tags"; | ||
|
||
<Tags /> | ||
|
||
# Installation | ||
|
||
## Setting up the environment | ||
|
||
Before diving right into writing code, you need to install some tooling in order | ||
to compile your contract. | ||
|
||
CosmWasm is luckily rather self-contained and therefore needs little external | ||
tooling to compile. | ||
Our only external dependency is Rust, which you need to install for your | ||
platform. | ||
|
||
<Callout> | ||
We recommend installing Rust using the official [rustup | ||
installer](https://rustup.rs). This makes it easy to stay on the most recent | ||
Rust version and to install compiler targets. | ||
</Callout> | ||
|
||
<Callout> | ||
For production builds you probably also want to install | ||
[Docker](https://www.docker.com/), too. | ||
<br /> This is because we offer the [CosmWasm Optimizing Compiler](https://github.com/CosmWasm/optimizer), | ||
which uses a Docker image to build the smallest contract possible in a deterministic | ||
fashion. | ||
</Callout> | ||
|
||
After installing Rust, you need to add the WebAssembly target. This is needed so | ||
Rust knows how to build your code to WebAssembly. | ||
|
||
To install the target using `rustup`, run the following command: | ||
|
||
```sh | ||
rustup target add wasm32-unknown-unknown | ||
``` | ||
|
||
Perfect! | ||
Now that we set up the foundation we just need two more tools: | ||
|
||
1. `cargo-generate` | ||
2. `cargo-run-script` (this is required to later optimize your contract for | ||
production) | ||
|
||
To install those, run the following commands: | ||
|
||
```sh | ||
cargo install cargo-generate --features vendored-openssl | ||
cargo install cargo-run-script | ||
``` | ||
|
||
## Setting up the contract | ||
|
||
Now that the environment is all done, let's create the project! | ||
|
||
Luckily you don't need to start from scratch, we already took care of the most | ||
tedious parts of setting up a new project in form of a template! | ||
|
||
In order to generate a fresh project, run this command and off we go: | ||
|
||
<Callout> | ||
Make sure to change `PROJECT_NAME` to the name of your contract! | ||
</Callout> | ||
|
||
```sh | ||
cargo generate --git https://github.com/CosmWasm/cw-template.git --name PROJECT_NAME | ||
``` | ||
|
||
Now you should have a ready contract project in a new folder called | ||
`PROJECT_NAME` (or whatever you changed it to). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
tags: ["core"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
import Tags from "@/components/Tags"; | ||
|
||
<Tags /> | ||
|
||
# Standard Library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"math": "Math", | ||
"cryptography": "Cryptography" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
tags: ["core"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
import Tags from "@/components/Tags"; | ||
|
||
<Tags /> | ||
|
||
# Cryptography |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
tags: ["core"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
import Tags from "@/components/Tags"; | ||
|
||
<Tags /> | ||
|
||
# Math |