Skip to content

Commit

Permalink
remove old prgh
Browse files Browse the repository at this point in the history
  • Loading branch information
costa2400 committed Mar 4, 2024
1 parent 0446538 commit 2ef9d35
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 88 deletions.
79 changes: 0 additions & 79 deletions src/basics/entry-points.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,3 @@
# Entry points

Typical Rust application starts with the `fn main()` function called by the operating system.
Smart contracts are not significantly different. When the message is sent to the contract, a
function called "entry point" is called. Unlike native applications, which have only a single
`main` entry point, smart contracts have a couple corresponding to different message types:
`instantiate`, `execute`, `query`, `sudo`, `migrate` and more.

To start, we will go with three basic entry points:

* `instantiate` which is called once per smart contract lifetime - you can think about it as
a constructor or initializer of a contract.
* `execute` for handling messages which are able to modify contract state - they are used to
perform some actual actions.
* `query` for handling messages requesting some information from a contract; unlike `execute`,
they can never affect any contract state, and are used just like database queries.

Go to your `src/lib.rs` file, and start with an `instantiate` entry point:

```rust,noplayground
use cosmwasm_std::{
entry_point, Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult,
};
#[entry_point]
pub fn instantiate(
_deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: Empty,
) -> StdResult<Response> {
Ok(Response::new())
}
```

In fact, `instantiate` is the only entry point required for a smart contract to be valid. It is not
very useful in this form, but it is a start. Let's take a closer look at the entry point structure.

First, we start with importing couple of types just for more consistent usage. Then we define our
entry point. The `instantiate` takes four arguments:

* [`deps: DepsMut`](https://docs.rs/cosmwasm-std/1.0.0/cosmwasm_std/struct.DepsMut.html)
is a utility type for communicating with the outer world - it allows querying
and updating the contract state, querying other contracts state, and gives access to an `Api`
object with a couple of helper functions for dealing with CW addresses.
* [`env: Env`](https://docs.rs/cosmwasm-std/1.0.0/cosmwasm_std/struct.Env.html)
is an object representing the blockchains state when executing the message - the
chain height and id, current timestamp, and the called contract address.
* [`info: MessageInfo`](https://docs.rs/cosmwasm-std/1.0.0/cosmwasm_std/struct.MessageInfo.html)
contains metainformation about the message which triggered an execution -
an address that sends the message, and chain native tokens sent with the message.
* [`msg: Empty`](https://docs.rs/cosmwasm-std/1.0.0/cosmwasm_std/struct.Empty.html)
is the message triggering execution itself - for now, it is `Empty` type that
represents `{}` JSON, but the type of this argument can be anything that is deserializable,
and we will pass more complex types here in the future.

If you are new to the blockchain, those arguments may not have much sense to you, but while
progressing with this guide, I will explain their usage one by one.

Notice an essential attribute decorating our entry point
[`#[entry_point]`](https://docs.rs/cosmwasm-std/1.0.0/cosmwasm_std/attr.entry_point.html). Its purpose is to
wrap the whole entry point to the form Wasm runtime understands. The proper Wasm entry points
can use only basic types supported natively by Wasm specification, and Rust structures and enums
are not in this set. Working with such entry points would be rather overcomplicated, so CosmWasm
creators delivered the `entry_point` macro. It creates the raw Wasm entry point, calling the
decorated function internally and doing all the magic required to build our high-level Rust arguments
from arguments passed by Wasm runtime.

The next thing to look at is the return type. I used
[`StdResult<Response>`](https://docs.rs/cosmwasm-std/1.0.0/cosmwasm_std/type.StdResult.html) for this simple example,
which is an alias for `Result<Response, StdError>`. The return entry point type would always be a
[`Result`](https://doc.rust-lang.org/std/result/enum.Result.html) type, with some error type implementing
[`ToString`](https://doc.rust-lang.org/std/string/trait.ToString.html) trait and a well-defined type for success
case. For most entry points, an "Ok" case would be the
[`Response`](https://docs.rs/cosmwasm-std/1.0.0/cosmwasm_std/struct.Response.html) type that allows fitting the contract
into our actor model, which we will discuss very soon.

The body of the entry point is as simple as it could be - it always succeeds with a trivial empty response.

# **Entry Points in CosmWasm Smart Contracts**

In CosmWasm, the concept of an entry point is fundamental to the operation of smart contracts. Unlike traditional Rust applications that start with a **`fn main()`** function, smart contracts utilize specific functions called entry points to interact with the blockchain. These entry points are crucial for the lifecycle of a smart contract, allowing it to be deployed, executed, and queried securely and predictably.
Expand Down
9 changes: 0 additions & 9 deletions src/wasmd-quick-start.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# Quick start with `wasmd`

In the past, we suggested playing with contracts on the `malaga` testnet using `wasmd`.
Now `malaga` is no longer operative, and the best way to test the contract in the
real environment is to use one of the big CosmWasm chains testnets - Osmosis, Juno,
Terra, or other ones.
[Here](https://docs.osmosis.zone/cosmwasm/testnet/cosmwasm-deployment/) is the
recommended introduction on how to start with the Osmosis testnet.

# Getting Started with wasmd

Welcome to the world of CosmWasm development! If you want to dive into smart contract development on the Cosmos network, starting with wasmd is a fantastic choice. wasmd is the backbone for deploying and managing CosmWasm smart contracts on various Cosmos SDK-based blockchains. This guide will walk you through the initial steps of getting started with wasmd, focusing on using the Osmosis testnet as your playground for deploying and testing your contracts.
Expand Down

0 comments on commit 2ef9d35

Please sign in to comment.