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

Add page comparing ink! and CosmWasm #63

Merged
merged 7 commits into from
May 24, 2022
Merged

Add page comparing ink! and CosmWasm #63

merged 7 commits into from
May 24, 2022

Conversation

bernardoaraujor
Copy link
Contributor

@bernardoaraujor bernardoaraujor commented May 20, 2022

#62

Copy link
Contributor

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

Good start!

By the way, do you also mind wrapping lines at 90 characters?


The architecture philosophy is likely the point where CosmWasm and ink! differ the most. CosmWasm follows the actor model design pattern, while ink! follows a synchronous execution model. That means some fundamental differences in how the source code is structured.

After a CosmWasm contract is deployed to the chain, it needs to be instantiated before it is usable. An ink! contract on the other hand is usable right after it’s been deployed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Under the hood we also have a different deploy and instantiate steps, but the UIs just hide that for you. One benefit of this is that you can deploy a contract once (say, an ERC-20) and instantiate it multiple times with different parameters (token name, decimals, etc.).

Not sure if this need to be in the Architecture section though, could be closer to where we talk about the constructors

- `execute` which has the actor perform operations to its internal state.
- `query` which retrieves data from the actor’s internal state.

An ink! contract can have as many entry point functions as the developer desires, and differently from CosmWasm, it doesn’t rely on JSON schemas for defining how the messages are structured. Instead, ink! makes heavy usage of Rust macros. The main ink! macros are:
Copy link
Contributor

Choose a reason for hiding this comment

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

When you refer to "entry point functions" do you mean public dispatchables (e.g #[ink(message)])?

An ink! contract can have as many entry point functions as the developer desires, and differently from CosmWasm, it doesn’t rely on JSON schemas for defining how the messages are structured. Instead, ink! makes heavy usage of Rust macros. The main ink! macros are:
- `#[ink(storage)]` which annotates a struct with the main variables that represent a contract internal state.
- `#[ink(event)]` and `#[ink(topic)]` which annotates a struct and its members as the events and topics that the contract might emit.
- `#[ink(constructor)]` which is called when the contract is deployed, and is responsible for bootstrapping the initial contract state into the storage. It is analogous to the CosmWasm instantiate function, with the difference that it is called as soon as the contract is deployed onto the chain, not on separate instantiation calls.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- `#[ink(constructor)]` which is called when the contract is deployed, and is responsible for bootstrapping the initial contract state into the storage. It is analogous to the CosmWasm instantiate function, with the difference that it is called as soon as the contract is deployed onto the chain, not on separate instantiation calls.
- `#[ink(constructor)]` which is called when the contract is deployed, and is responsible for bootstrapping the initial contract state into the storage. It is analogous to the CosmWasm `instantiate` function, with the difference that it is called as soon as the contract is deployed onto the chain, not on separate instantiation calls.

- `query` which retrieves data from the actor’s internal state.

An ink! contract can have as many entry point functions as the developer desires, and differently from CosmWasm, it doesn’t rely on JSON schemas for defining how the messages are structured. Instead, ink! makes heavy usage of Rust macros. The main ink! macros are:
- `#[ink(storage)]` which annotates a struct with the main variables that represent a contract internal state.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- `#[ink(storage)]` which annotates a struct with the main variables that represent a contract internal state.
- `#[ink(storage)]` which annotates a struct which represents contract's internal state.

An ink! contract can have as many entry point functions as the developer desires, and differently from CosmWasm, it doesn’t rely on JSON schemas for defining how the messages are structured. Instead, ink! makes heavy usage of Rust macros. The main ink! macros are:
- `#[ink(storage)]` which annotates a struct with the main variables that represent a contract internal state.
- `#[ink(event)]` and `#[ink(topic)]` which annotates a struct and its members as the events and topics that the contract might emit.
- `#[ink(constructor)]` which is called when the contract is deployed, and is responsible for bootstrapping the initial contract state into the storage. It is analogous to the CosmWasm instantiate function, with the difference that it is called as soon as the contract is deployed onto the chain, not on separate instantiation calls.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- `#[ink(constructor)]` which is called when the contract is deployed, and is responsible for bootstrapping the initial contract state into the storage. It is analogous to the CosmWasm instantiate function, with the difference that it is called as soon as the contract is deployed onto the chain, not on separate instantiation calls.
- `#[ink(constructor)]` which is called when the contract is deployed, and is responsible for bootstrapping the initial contract state into the storage. It is analogous to the CosmWasm instantiate function.

The architecture philosophy is likely the point where CosmWasm and ink! differ the most. CosmWasm follows the actor model design pattern, while ink! follows a synchronous execution model. That means some fundamental differences in how the source code is structured.

After a CosmWasm contract is deployed to the chain, it needs to be instantiated before it is usable. An ink! contract on the other hand is usable right after it’s been deployed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add a section here like

# Development 


For CosmWasm development and on-chain testing, `wasmd` can be operated as a local setup (single or multiple nodes), or connected to the `cliffnet` public test network.

Ink! contracts can be deployed on a few different options:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Ink! contracts can be deployed on a few different options:
ink! contracts can be deployed on a few different options:


There are other ink! macros, for which details can be found at [Macros & Attributes](/macros-attributes).

# Node Template
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Node Template
# Local Development Network


# Node Template

CosmWasm is modular, meaning that any blockchain using the Cosmos SDK can add smart contract support to their chain. That is similar to the Substrate approach, where chains have the option to add pallet-contracts to their runtime.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd move this to the Architecture section


In terms of Substrate, `substrate-node-template` is a basic generic template of a node. Similar to `x/wasm`, `pallet-contracts` is the module that adds WebAssembly smart contract functionality to the chain. Parity provides [substrate-contracts-node](https://github.com/paritytech/substrate-contracts-node), which is analogous to `wasmd`: a basic template node for smart contract development.

# Testnets
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd move this after Unit Testing

@HCastano HCastano changed the title ink-vs-cosmwasm Add page comparing ink! and CosmWasm May 24, 2022
Copy link
Contributor

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

Thanks!

@HCastano HCastano merged commit 873ef8e into master May 24, 2022
@HCastano HCastano deleted the bar-cosmwasm branch May 24, 2022 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants