Skip to content

Commit 03e5003

Browse files
committed
Add documentation for some entrypoints
1 parent 4e0c5f5 commit 03e5003

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

src/pages/core/entrypoints.mdx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ these entrypoints, each one different from the last.
1717
In this section we want to give you a quick overview over all the entrypoints
1818
and when they are called.
1919

20-
## Define entrypoints
20+
## Defining entrypoints
2121

2222
While you will learn all about entrypoints in the next sections, we want to give
2323
you an idea on how to define an entrypoint in the first place.
@@ -34,14 +34,22 @@ VM: "Hey! This is an entrypoint, please use it when needed!"
3434
including the correct function signature.
3535
</Callout>
3636

37+
<Callout>
38+
Even though the sections will show you to use `#[entry_point]`, it is
39+
recommended to define your endpoints as `#[cfg_attr(not(feature = "library"),
40+
entry_point)]`.
41+
<br /> The reason behind that is that it allows you to reuse your contract as a
42+
library.
43+
</Callout>
44+
3745
```rust
3846
#[entry_point]
3947
pub fn instantiate(
4048
deps: DepsMut,
4149
env: Env,
4250
info: MessageInfo,
4351
msg: InstantiateMsg,
44-
) -> Result<Response, StdError> {
52+
) -> StdResult<Response> {
4553
// Do some logic here
4654
Ok(Response::default())
4755
}

src/pages/core/entrypoints/execute.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,25 @@ import Tags from "@/components/Tags";
88
<Tags />
99

1010
# Execute
11+
12+
Execute pretty much does what it says on the tin: It executes some routine in
13+
your contract after a remote (either another contract or some client) sent a
14+
message.
15+
What sets it apart from other functions is that the contract has mutable access
16+
to the underlying storage.
17+
This allows you to, for example, increment a counter or add a user to a lottery.
18+
19+
## Definition
20+
21+
```rust filename="contract.rs"
22+
#[entry_point]
23+
pub fn execute(
24+
deps: DepsMut,
25+
env: Env,
26+
info: MessageInfo,
27+
msg: ExecuteMsg,
28+
) -> StdResult<Response> {
29+
// Increment some counter, register a user, spread liberty for super earth!
30+
Ok(Response::new())
31+
}
32+
```

src/pages/core/entrypoints/instantiate.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,25 @@ import Tags from "@/components/Tags";
88
<Tags />
99

1010
# Instantiate
11+
12+
This is one of the most fundamental entrypoints. This entrypoint is called once
13+
during the contract lifecycle.
14+
It essentially is there to initialise the state of your contract (for example,
15+
initialising a counter in storage, etc.).
16+
17+
You can imagine it as the constructor of your contract.
18+
19+
The most basic definition of this endpoint looks like this:
20+
21+
```rust filename="contract.rs"
22+
#[entry_point]
23+
pub fn instantiate(
24+
_deps: DepsMut,
25+
_env: Env,
26+
_info: MessageInfo,
27+
_msg: InstantiateMsg,
28+
) -> StdResult<Response> {
29+
// TODO: Initialise storage, send out metrics, do mischief
30+
Ok(Response::new())
31+
}
32+
```

src/pages/core/entrypoints/query.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,23 @@ import Tags from "@/components/Tags";
88
<Tags />
99

1010
# Query
11+
12+
In the previous section we talked about the
13+
[`execute` endpoint](./execute.mdx).
14+
The `query` endpoint is actually pretty similar to execute with one key
15+
difference: The storage is only accessible immutably.
16+
17+
This means you can only _read_ from the storage but not _write_ to it.
18+
19+
## Definition
20+
21+
```rust filename="contract.rs"
22+
#[entry_point]
23+
pub fn query(
24+
_deps: Deps,
25+
_env: Env,
26+
_msg: QueryMsg,
27+
) -> StdResult<QueryResponse> {
28+
Ok(QueryResponse::default())
29+
}
30+
```

0 commit comments

Comments
 (0)