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

Build an oapp #790

Merged
merged 26 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e51a245
Add a guide to create, deploy, and interact with a simple Hello World…
alijnmerchant21 Sep 3, 2024
a15fe43
Remove quick start.
alijnmerchant21 Sep 3, 2024
22dd097
Remove under construction tag
alijnmerchant21 Sep 3, 2024
0a8af85
Remove API reference from docs
alijnmerchant21 Sep 3, 2024
7b16721
Remove front-end reference till we have said capabilities
alijnmerchant21 Sep 3, 2024
70e59b3
Remove test so it can be moved under run a node section
alijnmerchant21 Sep 3, 2024
70a7047
Update hierarchy
alijnmerchant21 Sep 3, 2024
99aac7d
Move to folder
alijnmerchant21 Sep 3, 2024
abbef51
Add build with warenjs
alijnmerchant21 Sep 3, 2024
58c21f3
Add categorization
alijnmerchant21 Sep 3, 2024
13d9493
Add spaces
alijnmerchant21 Sep 3, 2024
ee327b3
A detailed tutorial on how spaceward works
alijnmerchant21 Sep 3, 2024
8585812
fixed broken links
ijonele Sep 3, 2024
4656a34
quick fixes
ijonele Sep 4, 2024
477afcd
fixed a broken link
ijonele Sep 4, 2024
73b2c5b
fixed the Intro and WardenJS docs
ijonele Sep 4, 2024
ce755d0
fixed the prerequisites part
ijonele Sep 4, 2024
bff51f2
fixed a broken link
ijonele Sep 5, 2024
86a1baf
Merge branch 'main' into build-an-oapp
alijnmerchant21 Sep 5, 2024
03b82d9
coderabbit
ijonele Sep 5, 2024
d8cb9ee
Merge branch 'build-an-oapp' of https://github.com/warden-protocol/wa…
ijonele Sep 5, 2024
703c70e
coderabbit
ijonele Sep 5, 2024
035d69b
Merge branch 'main' into build-an-oapp
alijnmerchant21 Sep 5, 2024
fab36f1
a minor fix
ijonele Sep 6, 2024
c94c878
Merge branch 'build-an-oapp' of https://github.com/warden-protocol/wa…
ijonele Sep 6, 2024
0b057d5
Merge branch 'main' into build-an-oapp
alijnmerchant21 Sep 6, 2024
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
218 changes: 213 additions & 5 deletions docs/developer-docs/docs/build-an-app/build-a-custom-smart-contract.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,221 @@
---
sidebar_position: 5
sidebar_position: 2
---

# Build a custom smart contract

*Coming soon*
## Overview

<!---
This guide explains how to create and deploy a simple "Hello World" smart contract on the Warden chain. Since it's intended for testing purposes, you'll be running a local chain.

- A step-by-step guide based on a custom example showing unique capabilities of Warden smart contracts. For example, a contract that evaluates Approval Rules.
## Prerequisites

--->
Before you start, complete the following prerequisites:

- Install Rust by running the following:

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

- Set up the CosmWasm development environment:

- [CosmWasm](https://book.cosmwasm.com/setting-up-env.html): The CosmWasm binary and its dependencies.

- [cargo-generate](https://cargo-generate.github.io/cargo-generate/installation.html): A tool to help you get up and running quickly with a new Rust project by leveraging a pre-existing git repository as a template.

- [wasm-opt](https://docs.rs/wasm-opt/latest/wasm_opt/index.html): A tool for optimizing the compiled WebAssembly (Wasm) code.

To install these tools, run the following commands:

```bash
rustup target add wasm32-unknown-unknown
cargo install cargo-generate --features vendored-openssl
brew install binaryen
```

- [Run a local chain](test/run-a-local-chain) and make sure you have `wardend` correctly installed. You can stop the chain for now if you wish.
Copy link
Contributor

Choose a reason for hiding this comment

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

You can stop the chain for now if you wish.

I'd rather either explain the benefit of stopping the chain, or avoid suggesting it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ijonele please take note.

Copy link
Collaborator

@ijonele ijonele Sep 6, 2024

Choose a reason for hiding this comment

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

But In Step 6 the node has to be running? I guess in this case we can just say - Run a local chain and not mention stopping it.


The next steps require your local account name, or key name, which is referenced as `my-key-name` in the provided command-line examples. You can check the list of available keys by executing this command (while the node is running):
Copy link
Contributor

Choose a reason for hiding this comment

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

it doesn't require the node to be running

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it doesn't require the node to be running

The chain needs to be running only while deploying a contract. We can either do it at the beginning or middle of the tutorial. I think in the start looks clean. But I'm open to moving it to later part of the tutorial too.


```bash
wardend keys list
```
:::tip
In development genesis files, you'll typically find an account named shulgin that is preconfigured and ready for use.
:::
## 1. Create a new CosmWasm project
Create a new CosmWasm project by running the following:
```bash
cargo generate --git https://github.com/CosmWasm/cw-template.git --name hello-world
cd hello-world
```
## 2. Modify the contract code
1. Open `src/contract.rs` and replace its contents with this code:
```rust
use cosmwasm_std::{
entry_point, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult,
};
use cw2::set_contract_version;
use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
const CONTRACT_NAME: &str = "crates.io:hello-world";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
#[entry_point]
pub fn instantiate(
deps: DepsMut,
_env: Env,
info: MessageInfo,
_msg: InstantiateMsg,
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::new().add_attribute("method", "instantiate")
.add_attribute("owner", info.sender))
}
#[entry_point]
pub fn execute(
_deps: DepsMut,
_env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
match msg {
ExecuteMsg::SayHello {} => Ok(Response::new()
.add_attribute("method", "say_hello")
.add_attribute("sender", info.sender)),
}
}
#[entry_point]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::GetGreeting {} => to_binary(&"Hello, World!"),
}
}
```
2. Open `src/msg.rs` and replace its contents with this code:
```rust
use cosmwasm_schema::{cw_serde, QueryResponses};
#[cw_serde]
pub struct InstantiateMsg {}
#[cw_serde]
pub enum ExecuteMsg {
SayHello {},
}
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(String)]
GetGreeting {},
}
```
## 4. Compile the contract
To compile the contract, run the following:
```bash
cargo wasm
```
The contract should be compiled without any errors.
## 5. Optimize the compiled Wasm code
Now you need to optimize your compiled Wasm code:
```bash
wasm-opt -Os -o target/wasm32-unknown-unknown/release/hello_world.wasm /
target/wasm32-unknown-unknown/release/hello_world.wasm
```
## 6. Run the chain
If your local chain isn't running, start it:

```bash
wardend start
```

## 7. Store the contract on-chain

To store your contract on the Warden chain, run the command below. Replace `my-key-name` with your key name (typically `shulgin`).

```bash
wardend tx wasm store target/wasm32-unknown-unknown/release/hello_world.wasm /
--from my-key-name --gas auto --gas-adjustment 1.3 --gas-prices 0.1uward -y
```

The transaction should be successful without any errors.

## 8. Get the code ID

Get the code ID, which identifies your Wasm code:

```bash
wardend query wasm list-code
```

Note down `code_id` from the output.

## 9. Instantiate the contract

You can instantiate the contract by using the command below.

Before you proceed, should replace replace `1` with the actual code ID you retrieved in previous step and replace `my-key-name` with your key name. Also note that you can either define an admin or pass `--no-admin` to make it immutable, like in this example.

```bash
wardend tx wasm instantiate 1 '{}' --from my-key-name /
--label "Hello World" --gas auto --gas-adjustment 1.3 /
--gas-prices 0.1uward --no-admin -y
```

## 10. Get the contract address

To get the contract address, run the following command. Replace `1` with the actual code ID:

```bash
wardend query wasm list-contract-by-code 1
```

Note down the contract address.

## 11. Execute the contract

Use the command below to exectute your contract. Replace `my-contract-address` with your contract address and `my-key-name` with your key name.

```bash
wardend tx wasm execute my-contract-address '{"say_hello":{}}' /
--from my-key-name --gas auto --gas-adjustment 1.3 --gas-prices 0.1uward -y
```

## Result

Now your contract is ready!

You can query it with the following command. Replace `my-contract-address` with your contract address.

```bash
wardend query wasm contract-state smart my-contract-address '{"get_greeting":{}}'
```

In the output, you should see `data: Hello, World!`

If you encounter any issues, please reach out to us via [Discord](https://discord.com/invite/warden) or [Twitter](https://twitter.com/wardenprotocol).

Happy Coding! 🚀

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

13 changes: 3 additions & 10 deletions docs/developer-docs/docs/build-an-app/build-with-wardenjs.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
---
sidebar_position: 4
sidebar_position: 3
---

# Build with WardenJS

*Coming soon*
**WardenJS** is a tool helping you to build the frontend part of your application. It makes it easy to compose and broadcast messages, with all of the proto and amino encoding handled for you.

<!---
- An overview of functions related to different modules
- Implement Spaces, implement Keychains, etc.
**Note**: In this section, we'll show how to use WardenJS using SpaceWard as an example.
--->
You can find basic WardenJS documentation here: [WardenJS](https://www.npmjs.com/package/@wardenprotocol/wardenjs)
2 changes: 1 addition & 1 deletion docs/developer-docs/docs/build-an-app/examples-of-oapps.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 2
sidebar_position: 4
---

# Examples of OApps
Expand Down
24 changes: 10 additions & 14 deletions docs/developer-docs/docs/build-an-app/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,18 @@ sidebar_position: 1

**Omnichain Applications** (**OApps**) are a powerful evolution of traditional smart contracts. They allow signing transactions at any chain, while traditional smart contract applications only target users of a single chain.

An example of an OApp is [SpaceWard](https://help.wardenprotocol.org) – our application functioning as the front-end interface for Warden. For a full list of available OApps, see [Examples of OApps](examples-of-oapps).
An example of an OApp is [SpaceWard](https://help.wardenprotocol.org) – our application functioning as the front-end interface for Warden.

This section explains how to build the backend and frontend of an OApp. Here you'll also find guides for running a [node](/learn/glossary#warden-protocol-node) and a [Keychain](/learn/glossary#keychain) in the test mode.
## Section overview

## Get started
- [Build a custom smart contract](build-a-custom-smart-contract)
Get started with OApps and build a basic **Omnichain Contract**, which is the main part of any Omnichain Application.

The main part of any Omnichain Application is an **Omnichain Contract**: a smart contract that allows signing transactions and messages at any destination chain. For this reason, OApp development starts with building a custom Omnichain Contract with [CosmWasm](https://cosmwasm.com).
- [Build with WardenJS](build-with-wardenjs)
Here you'll find information on WardenJS – a tool used for building the frontend part of your application. Stay tuned in for more frontend guides.

To learn more, check our list of CosmWasm resources in the [Useful links](useful-links) section.
- [Useful links](useful-links)
To learn more about building smart contracts, check our list of CosmWasm resources and developer guides.

*Please note that this section is under construction. More information is coming soon.*

<!--- Contents:
- What is an OApp and how is it built? (briefly)
- Links to other docs related to this section
- A link to the article with CosmWasm docs and tutorials
--->
- [Examples of OApps](examples-of-oapps)
Here you can find a full list of available OApps.
21 changes: 0 additions & 21 deletions docs/developer-docs/docs/build-an-app/quick-start.md

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion docs/developer-docs/docs/build-an-app/useful-links.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 7
sidebar_position: 3
---

# Useful links
Expand Down
Loading
Loading