Skip to content

Commit

Permalink
Update cosmwasm docs (#520)
Browse files Browse the repository at this point in the history
* Update to the smart contracts introduction doc

* Updates to the multi chain contracts doc

* Updates to the Actor model page

* Update to the name and address doc

* Updates to the querying architecture doc

* Updates to the serialization doc

* Updates to the contract composition doc in the smart contract architecture section

* Update the ethereum comparison docs

* Updates to the docs covering cosmwasm messages

* Update contract semantics

* Updates to the state smart contract docs

* Update the result and option smart contract docs

* Updates to the entry points smart contract docs

* Updates to the contract integration smart contract docs

* Updates to the query smart contract doc

* Updates to the events smart contract docs

* Updates to the math smart contract doc

* Remove the migrate dapp from another network smart contract doc

* Updates to the testing smart contract docs

* Updates to the sudo execution smart contract doc

* Updates to the cosmwasm IBC docs

* Updates to the verify smart contract doc

* Fixed the parent section and parent section paths
  • Loading branch information
emperorjm authored Aug 14, 2024
1 parent 2550299 commit 107190a
Show file tree
Hide file tree
Showing 25 changed files with 1,988 additions and 966 deletions.
68 changes: 59 additions & 9 deletions content/2.developers/3.smart-contracts/0.introduction.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,75 @@
---
objectID: developers_cosm_wasm_introduction
title: Introduction
description: CosmWasm Introduction
parentSection: CosmWasm
description: An introduction to smart contracts
parentSection: Smart Contracts
---

# Introduction

## What is cosmwasm?
Archway is a blockchain that utilizes the CosmWasm engine to power its smart contracts. CosmWasm is a smart contract platform that uses WebAssembly (Wasm) to run contracts in a secure and efficient virtual machine and designed to enable multi-chain smart contracts.

CosmWasm is a smart contract platform written as a module that can be integrated into any blockchain built on top of the <a href="https://github.com/cosmos/cosmos-sdk" target="_blank">Cosmos SDK</a>. In simple terms, it is the Cosmos (Cosm) way of utilizing WebAssembly (Wasm), hence its name.
## What are smart contracts?

<a href="https://www.rust-lang.org" target="_blank">Rust</a> is currently the most widely used programming language for CosmWasm. In the future, other programming languages, such as Go, may also be utilized. Read CosmWasm’s launch article <a href="https://blog.cosmos.network/announcing-the-launch-of-cosmwasm-cc426ab88e12" target="_blank">here</a>.
Smart contracts are self-executing programs stored on the Archway blockchain that run when predetermined conditions are met. On Archway, these contracts are built using the [Rust](https://www.rust-lang.org) programming language, known for its performance and safety features. Smart contracts form the basis of decentralized applications (dapps), enabling complex, automated interactions on the blockchain.

## Sections
On Archway, smart contracts are possible through CosmWasm. CosmWasm is a smart contract platform written as a module that can be integrated into any blockchain built on top of the <a href="https://github.com/cosmos/cosmos-sdk" target="_blank">Cosmos SDK</a>. In simple terms, it is the Cosmos (Cosm) way of utilizing WebAssembly (Wasm), hence its name.

* [Getting Started](/developers/cosmwasm-documentation/getting-started/introduction) guides you through modifying, deploying, and executing a smart contract on the blockchain. It is the ideal place to familiarize yourself with all aspects of the system without delving too deep into coding.
### How smart contracts operate

* [Architecture](/developers/cosmwasm-documentation/architecture/multi-chain-contracts) explains much of the high-level design and architecture of CosmWasm. It is crucial to understand the mental model and capabilities of the system before designing products with it. However, if you prefer to learn through coding, you can skip this section and revisit it as needed.
1. **Automated Execution**: Smart contracts automatically execute actions when specific conditions are met, without the need for intermediaries.

* [Smart Contracts](/developers/cosmwasm-documentation/smart-contracts/contract-semantics) explores the various components that make up smart contracts and how they interact with the wider CosmWasm environment.
2. **Flexible Mutability**: Contracts on Archway can be designed as either mutable or immutable. Immutable contracts provide unchangeable logic, ensuring transparency and preventing tampering. Mutable contracts allow for upgrades, enabling developers to improve functionality over time while maintaining appropriate governance mechanisms.

3. **Decentralized Storage**: The contract and its state are stored across the blockchain network, making them resistant to single points of failure.

4. **Deterministic Outcomes**: Given the same input and state, a smart contract will always produce the same result, ensuring predictability.

5. **Interaction via Transactions**: Users interact with smart contracts by sending transactions to the contract's address on the blockchain.

### Why smart contracts are useful

1. **Trust and Transparency**: Smart contracts remove the need for trusted intermediaries in many transactions, as their execution is transparent and verifiable.

2. **Efficiency**: By automating processes, smart contracts can significantly reduce transaction times and costs.

3. **Accuracy**: Smart contracts eliminate the errors that can occur in manually processed transactions.

4. **Security**: The decentralized nature of blockchain and the immutability of smart contracts provide a high level of security against fraud and tampering.

5. **Programmable Money**: Smart contracts enable complex financial instruments and agreements to be encoded directly into the blockchain.

6. **Interoperability**: In ecosystems like Cosmos, smart contracts can facilitate interactions between different blockchain networks.

## Rust

Rust is the language used for developing smart contracts on Archway. Here’s why Rust is an excellent choice:

1. **Memory Safety**: Rust’s unique ownership model ensures memory safety without needing a garbage collector. This feature helps prevent common bugs and vulnerabilities, such as null pointer dereferencing and buffer overflows.

2. **Performance**: Rust provides performance on par with C and C++, making it ideal for blockchain applications where efficiency is critical.

3. **Concurrency**: Rust’s concurrency model allows for safe and efficient multi-threading, which is essential for handling the high transaction throughput required by blockchain networks.

4. **Developer Experience**: Rust’s syntax is modern and expressive, with a robust tooling ecosystem that includes features like Cargo (the Rust package manager), Rustfmt (code formatting), and Clippy (linting). These tools enhance the developer experience and productivity.

5. **Active Community and Ecosystem**: Rust has a growing and active community, which means continuous improvements and extensive libraries and frameworks that developers can leverage.

### Learning resources for Rust

To help you get started with Rust, here are some valuable resources:

- **[The Rust Programming Language Book](https://doc.rust-lang.org/book/)**: This is the official book on Rust, often referred to as "The Rust Book." It's an excellent resource for learning Rust from scratch.

- **[Rust by Example](https://doc.rust-lang.org/rust-by-example/)**: This resource offers a collection of runnable examples that cover various Rust concepts and standard libraries.

- **[Rustlings](https://github.com/rust-lang/rustlings)**: An interactive tutorial that helps you learn Rust through small exercises.

- **[Rust Language Cheat Sheet](https://cheats.rs/)**: A handy reference guide for common Rust syntax and concepts.

- **[The Rust Programming Language Forum](https://users.rust-lang.org/)**: A community forum where you can ask questions, share knowledge, and discuss Rust-related topics.

- **[Rust's Official YouTube Channel](https://www.youtube.com/@RustVideos)**: Contains tutorials, talks, and other educational videos about Rust.

## Additional resources

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,56 @@
objectID: developers_cosm_wasm_architecture_multi-chain-contracts
title: What are multi-chain contracts
description: Multi-Chain contracts
parentSection: CosmWasm
parentSectionPath: /developers/cosmwasm-documentation/introduction
parentSection: Smart Contracts
parentSectionPath: /developers/smart-contracts/introduction
---

# What are multi-chain contracts?
CosmWasm is designed and built from the ground up to be a multi-chain solution for smart contracts. As it comes from the Cosmos ecosystem, it was designed for networks of blockchains, rather than siloed chains. But what exactly is meant by multi-chain?
# Understanding multi-chain contracts

## Different chain, same contract
All code is designed to be agnostic to the details of the underlying chain, so by writing a CosmWasm contract, you will be able to run it on different chains within the Cosmos ecosystem.
In the evolving landscape of blockchain technology, interoperability and flexibility are key to building robust decentralized applications. CosmWasm, a smart contract platform originating from the Cosmos ecosystem, was designed with these principles in mind. It stands out as a multi-chain solution, empowering developers to create contracts that are not limited to a single blockchain but can operate seamlessly across multiple chains. But what does "multi-chain" truly mean in the context of CosmWasm?

## Inter blockchain contracts
CosmWasm contracts leverage the Inter-Blockchain Communication protocol (IBC), making it possible to handle authentication and data transport between blockchains. Because IBC provides a permissionless way for relaying data packets between blockchains, CosmWasm allows you to write code on one chain that can execute a transaction on another chain.
## What does multi-chain mean in CosmWasm?

In order to achieve this, CosmWasm fully adopts the [actor model](/developers/cosmwasm-documentation/architecture/actor-model-intro), ensuring that the code is designed with IBC usage in mind. As a result, in CosmWasm, messages follow a "**fire-and-forget**" approach, eliminating the need to await promises and reducing concerns about race conditions and reentrancy attacks. By incorporating IBC primitives into CosmWasm's libraries, you can unlock the full potential of inter-chain messaging and execution.
At its core, CosmWasm was conceived to support a network of interconnected blockchains, as opposed to isolated, standalone chains. This design philosophy aligns with the broader vision of the Cosmos ecosystem, which aims to create an "Internet of Blockchains" where multiple chains can communicate, share data, and work together to deliver more complex and powerful applications. The term "multi-chain" in CosmWasm encompasses several key capabilities:

## Easy to integrate
CosmWasm has been designed more as a library than a framework, minimizing required APIs. This allows you to take advantage of CosmWasm without being heavily dependent on it.
1. **Chain-Agnostic Contract Deployment**: The ability to deploy the same contract across different blockchains without modification.
2. **Inter-Chain Communication**: Utilizing the Inter-Blockchain Communication protocol (IBC) to allow contracts on different chains to interact and execute transactions across those chains.
3. **Scalability and Flexibility**: Building applications that can scale by leveraging multiple chains for different purposes or functions within a broader ecosystem.

This offers two significant advantages:
## Chain-Agnostic contracts: one code, multiple chains

- It simplifies the process of adding support for multiple languages to write smart contracts.
One of the standout features of CosmWasm is its chain-agnostic design. This means that the code you write for a CosmWasm contract is not tied to the specifics of any single blockchain. Whether you're deploying on Archway, or any other Cosmos SDK-based chain, your contract will function as intended without requiring much alterations.

- As it places limited demands on the host system, it can be integrated into other frameworks besides just the Cosmos SDK. The core runtime logic **cosmwasm-vm** is written in Rust, while **wasmvm** offers a generic Go binding to it.
### Benefits of chain-agnostic contracts

CosmWasm is designed to be adaptable to different blockchains and coding languages. This makes it a solid foundation to build upon, as all your smart contracts and dapps can be migrated to another chain.
- **Portability**: Developers can write a contract once and deploy it across multiple chains, reducing development time and costs.
- **Consistency**: A single codebase for a contract ensures consistency in behavior and functionality across different environments.
- **Ecosystem Synergy**: By enabling contracts to operate across various chains, CosmWasm fosters greater synergy within the Cosmos ecosystem, allowing applications to tap into the unique features and user bases of different blockchains.

## Inter-Chain contracts: bridging blockchains with IBC

Beyond simply deploying the same contract on different chains, CosmWasm leverages the power of the Inter-Blockchain Communication protocol (IBC) to enable truly inter-chain contracts. IBC is a groundbreaking protocol that allows different blockchains to communicate with each other, facilitating the transfer of data, assets, and even executable messages between chains.

### How inter-chain contracts work

In a typical inter-chain contract scenario, a smart contract on one blockchain can trigger actions on another blockchain through IBC. For example, a contract on Chain A might send a message to Chain B to release tokens or execute a specific function. This is done securely and trustlessly, with IBC handling the authentication and transport of messages between chains.

### Actor model and fire-and-forget messaging

CosmWasm incorporates the [actor model](/developers/smart-contracts/architecture/actor-model-intro) to handle inter-chain messaging efficiently. In this model, contracts are treated as independent "actors" that communicate through messages. These messages follow a "fire-and-forget" approach, meaning that once a message is sent, the sender does not wait for a response, reducing the risk of race conditions and reentrancy attacks. This model is particularly well-suited for IBC, where messages between chains may have varying delivery times.

### Unlocking new possibilities

Inter-chain contracts open up new possibilities for decentralized applications. For instance, a cross-chain decentralized exchange (DEX) could allow users to swap assets between different blockchains directly from their wallets, without relying on centralized exchanges or intermediaries. Similarly, a cross-chain governance protocol could enable token holders on one chain to vote on proposals affecting another chain.

## Integration and adaptability: a modular approach

CosmWasm's design is modular and adaptable, making it more of a library than a rigid framework. This modularity is crucial for enabling multi-chain functionality, as it allows CosmWasm to integrate easily with various blockchain environments and programming languages.

### Multi-language and cross-framework support

By reducing its dependencies on specific frameworks, CosmWasm enables developers to write contracts in multiple programming languages and deploy them across various blockchain environments. This flexibility is a significant advantage in a multi-chain world, where different blockchains may have different native languages and development ecosystems. Currently, Rust is the primary language used, but other languages are being actively ported to expand CosmWasm's versatility.

### Future-Proofing your dapps

Building on CosmWasm allows developers to future-proof their decentralized applications. As the blockchain ecosystem evolves, your smart contracts can be migrated to new chains or adapted to new environments with minimal effort, ensuring long-term viability and flexibility.
Loading

0 comments on commit 107190a

Please sign in to comment.