|
1 | 1 | ---
|
2 | 2 | title: Smart Contracts Overview
|
3 |
| -description: Learn how developers can build smart contracts on Polkadot by leveraging either Wasm/ink! or EVM contracts across many parachains. |
| 3 | +description: Learn about smart contract development capabilities on Asset Hub, Polkadot's system parachain, featuring PolkaVM and Ethereum compatibility. |
4 | 4 | ---
|
5 | 5 |
|
6 |
| -# An Overview of the Smart Contract Landscape on Polkadot |
| 6 | +# Smart Contracts on Asset Hub |
7 | 7 |
|
8 | 8 | ## Introduction
|
9 | 9 |
|
10 |
| -Polkadot is designed to support an ecosystem of parachains, rather than hosting smart contracts directly. Developers aiming to build smart contract applications on Polkadot rely on parachains within the ecosystem that provide smart contract functionality. |
| 10 | +Asset Hub, Polkadot's system parachain, enables smart contract deployment and execution through PolkaVM, a cutting-edge virtual machine designed specifically for the Polkadot ecosystem. This native integration allows developers to deploy smart contracts directly on Polkadot's system chain while maintaining compatibility with Ethereum development tools and workflows. |
11 | 11 |
|
12 |
| -This guide outlines the primary approaches to developing smart contracts in the Polkadot ecosystem: |
| 12 | +## Smart Contract Development |
13 | 13 |
|
14 |
| -- **Wasm-based smart contracts** - using [ink!](https://use.ink/){target=\_blank}, a Rust-based embedded domain-specific language (eDSL), enabling developers to leverage Rust’s safety and tooling |
15 |
| -- **EVM-compatible contracts** - which support languages like [Solidity](https://soliditylang.org/){target=\_blank} and [Vyper](https://vyperlang.org/){target=\_blank}, offering compatibility with popular Ethereum tools and wallets |
16 |
| -<!-- This content is temporarily hidden and has been commented out to ensure it is preserved. --> |
17 |
| -<!-- - **PolkaVM-compatible contracts** - which support Solidity and Rust while maintaining compatibility with Ethereum based tools --> |
| 14 | +The smart contract platform on Asset Hub combines Polkadot's robust security and scalability with the extensive Ethereum development ecosystem. Developers can utilize familiar Ethereum libraries for contract interactions and leverage industry-standard development environments for writing and testing smart contracts. |
18 | 15 |
|
19 |
| -You'll explore the key differences between these development paths, along with considerations for parachain developers integrating smart contract functionality. |
| 16 | +Asset Hub provides full Ethereum JSON-RPC API compatibility, ensuring seamless integration with existing development tools and services. This compatibility enables developers to maintain their preferred workflows while building on Polkadot's native infrastructure. |
20 | 17 |
|
21 |
| -If you are a parachain developer looking to add smart contract functionality to your chain, please refer to the [Add Smart Contract Functionality](/develop/parachains/customize-parachain/add-smart-contract-functionality/){target=\_blank} page, which covers both Wasm and EVM-based contract implementations. |
| 18 | +## Technical Architecture |
22 | 19 |
|
23 |
| -## Smart Contracts Versus Parachains |
| 20 | +PolkaVM, the underlying virtual machine, utilizes a RISC-V-based register architecture optimized for the Polkadot ecosystem. This design choice offers several advantages: |
24 | 21 |
|
25 |
| -A smart contract is a program that executes specific logic isolated to the chain on which it is being executed. All the logic executed is bound to the same state transition rules determined by the underlying virtual machine (VM). Consequently, smart contracts are more streamlined to develop, and programs can easily interact with each other through similar interfaces. |
| 22 | +- Enhanced performance for smart contract execution |
| 23 | +- Improved gas efficiency for complex operations |
| 24 | +- Native compatibility with Polkadot's runtime environment |
| 25 | +- Optimized storage and state management |
26 | 26 |
|
27 |
| -``` mermaid |
28 |
| -flowchart LR |
29 |
| - subgraph A[Chain State] |
30 |
| - direction LR |
31 |
| - B["Program Logic and Storage<br/>(Smart Contract)"] |
32 |
| - C["Tx Relevant Storage"] |
33 |
| - end |
34 |
| - A --> D[[Virtual Machine]] |
35 |
| - E[Transaction] --> D |
36 |
| - D --> F[(New State)] |
37 |
| - D --> G[Execution Logs] |
38 |
| - style A fill:#ffffff,stroke:#000000,stroke-width:1px |
39 |
| -``` |
| 27 | +## Development Tools and Resources |
40 | 28 |
|
41 |
| -In addition, because smart contracts are programs that execute on top of existing chains, teams don't have to think about the underlying consensus they are built on. |
| 29 | +Asset Hub supports a comprehensive suite of development tools familiar to Ethereum developers. The platform integrates with popular development frameworks, testing environments, and deployment tools. Key features include: |
42 | 30 |
|
43 |
| -These strengths do come with certain limitations. Some smart contracts environments, like EVM, tend to be immutable by default. Developers have developed different [proxy strategies](https://blog.openzeppelin.com/proxy-patterns){target=\_blank} to be able to upgrade smart contracts over time. The typical pattern relies on a proxy contract which holds the program storage forwarding a call to an implementation contract where the execution logic resides. Smart contract upgrades require changing the implementation contract while retaining the same storage structure, necessitating careful planning. |
| 31 | +- Contract development in Solidity or Rust |
| 32 | +- Support for standard Ethereum development libraries |
| 33 | +- Integration with widely used development environments |
| 34 | +- Access to blockchain explorers and indexing solutions |
| 35 | +- Compatibility with contract monitoring and management tools |
44 | 36 |
|
45 |
| -Another downside is that smart contracts often follow a gas metering model, where program execution is associated with a given unit and a marketplace is set up to pay for such an execution unit. This fee system is often very rigid, and some complex flows, like account abstraction, have been developed to circumvent this problem. |
| 37 | +## Cross-Chain Capabilities |
46 | 38 |
|
47 |
| -In contrast, parachains can create their own custom logics (known as pallets or modules), and combine them as the state transition function (STF or runtime) thanks to the modularity provided by the [Polkadot-SDK](https://github.com/paritytech/polkadot-sdk/tree/{{dependencies.repositories.polkadot_sdk.version}}){target=\_blank}. The different pallets within the parachain runtime can give developers a lot of flexibility when building applications on top of it. |
| 39 | +Smart contracts deployed on Asset Hub can leverage the cross-consensus messaging (XCM) protocol to interact with other parachains in the Polkadot ecosystem. This native interoperability enables developers to build truly cross-chain applications, accessing functionality and assets across the entire Polkadot network. |
48 | 40 |
|
49 |
| -``` mermaid |
50 |
| -flowchart LR |
51 |
| - A[(Chain State)] --> B[["STF<br/>[Pallet 1]<br/>[Pallet 2]<br/>...<br/>[Pallet N]"]] |
52 |
| - C[Transaction<br/>Targeting Pallet 2] --> B |
53 |
| - B --> E[(New State)] |
54 |
| - B --> F[Execution Logs] |
55 |
| -``` |
| 41 | +## Use Cases |
56 | 42 |
|
57 |
| -Parachains inherently offer features such as logic upgradeability, flexible transaction fee mechanisms, and chain abstraction logic. More so, by using Polkadot, parachains can benefit from robust consensus guarantees with little engineering overhead. |
| 43 | +Asset Hub's smart contract platform is suitable for a wide range of applications: |
58 | 44 |
|
59 |
| -To learn more about the differences between smart contracts and parachain runtimes, please see the [Runtime vs. Smart Contracts](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/runtime_vs_smart_contract/index.html){target=\_blank} section of the Polkadot SDK Rust docs. For a more in-depth discussion on choosing between runtime development and smart contract development, see the post ["When should one build a Polkadot SDK runtime versus a Substrate (Polkadot SDK) smart contract?"](https://stackoverflow.com/a/56041305){target=\_blank} from Stack Overflow. |
| 45 | +- DeFi protocols leveraging cross-chain capabilities |
| 46 | +- NFT platforms utilizing Polkadot's native token standards |
| 47 | +- Governance systems integrated with Polkadot's democracy mechanisms |
| 48 | +- Cross-chain bridges and asset management solutions |
60 | 49 |
|
61 |
| -## Building a Smart Contract |
| 50 | +## Where to Go Next |
62 | 51 |
|
63 |
| -Polkadot's primary purpose is to provide security for parachains that connect to it. Therefore, it is not meant to support smart contract execution. Developers looking to build smart contract projects in Polkadot need to look into its ecosystem for parachains that support it. |
| 52 | +Developers can use their existing Ethereum development tools and connect to Asset Hub's RPC endpoints. The platform's Ethereum compatibility layer ensures a smooth transition for teams already building on EVM-compatible chains. |
64 | 53 |
|
65 |
| -The Polkadot SDK supports multiple smart contract execution environments: |
| 54 | +Subsequent sections of this guide provide detailed information about specific development tools, advanced features, and best practices for building on Asset Hub. |
66 | 55 |
|
67 |
| -- **EVM** - through [Frontier](https://github.com/polkadot-evm/frontier){target=\_blank}. It consists of a full Ethereum JSON RPC compatible client, an Ethereum emulation layer, and a [Rust-based EVM](https://github.com/rust-ethereum/evm){target=\_blank}. This is used by chains like [Acala](https://acala.network/){target=\_blank}, [Astar](https://astar.network/){target=\_blank}, [Moonbeam](https://moonbeam.network){target=\_blank} and more |
68 |
| -- **Wasm** - through the [Contracts pallet](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/contracts/){target=\_blank}. [ink!](https://use.ink/){target=\_blank} is a smart contract language that provides a compiler to Wasm. Wasm contracts can be used by chains like [Astar](https://astar.network/){target=\_blank} |
69 |
| -<!-- This content is temporarily hidden and has been commented out to ensure it is preserved. --> |
70 |
| -<!-- - **PolkaVM** - a cutting-edge virtual machine tailored to optimize smart contract execution on Polkadot. Unlike traditional EVMs, PolkaVM is built with a [RISC-V-based register architecture](https://en.wikipedia.org/wiki/RISC-V){target=\_blank} for increased performance and scalability --> |
| 56 | +<div class="grid cards" markdown> |
71 | 57 |
|
72 |
| -### EVM Contracts |
| 58 | +- <span class="badge guide">Guide</span> __Libraries__ |
73 | 59 |
|
74 |
| -The [Frontier](https://github.com/polkadot-evm/frontier){target=\_blank} project provides a set of modules that enables a Polkadot SDK-based chain to run an Ethereum emulation layer that allows the execution of EVM smart contracts natively with the same API/RPC interface. |
| 60 | + --- |
75 | 61 |
|
76 |
| -[Ethereum addresses (ECDSA)](https://ethereum.org/en/glossary/#address){target=\_blank} can also be mapped directly to and from the Polkadot SDK's SS58 scheme from existing accounts. Moreover, you can modify Polkadot SDK to use the ECDSA signature scheme directly to avoid any mapping. |
| 62 | + Explore essential libraries to optimize smart contract development and interaction. |
77 | 63 |
|
78 |
| -At a high level, [Frontier](https://github.com/polkadot-evm/frontier){target=\_blank} is composed of three main components: |
| 64 | + [:octicons-arrow-right-24: Reference](/develop/smart-contracts/evm-toolkit/libraries/) |
79 | 65 |
|
80 |
| -- [**Ethereum Client**](https://github.com/polkadot-evm/frontier/tree/master/client){target=\_blank} - an Ethereum JSON RPC compliant client that allows any request coming from an Ethereum tool, such as [Remix](https://remix.ethereum.org/){target=\_blank}, [Hardhat](https://hardhat.org/){target=\_blank} or [Foundry](https://getfoundry.sh/){target=\_blank}, to be admitted by the network |
81 |
| -- [**Pallet Ethereum**](https://docs.rs/pallet-ethereum/latest/pallet_ethereum/){target=\_blank} - a block emulation and Ethereum transaction validation layer that works jointly with the Ethereum client to ensure compatibility with Ethereum tools |
82 |
| -- [**Pallet EVM**](https://docs.rs/pallet-evm/latest/pallet_evm/){target=\_blank} - access layer to the [Rust-based EVM](https://github.com/rust-ethereum/evm){target=\_blank}, enabling the execution of EVM smart contract logic natively |
| 66 | +- <span class="badge guide">Guide</span> __Dev Environments__ |
83 | 67 |
|
84 |
| -Broadly speaking, in this configuration, an EVM transaction follows the path presented in the diagram below: |
| 68 | + --- |
85 | 69 |
|
86 |
| -``` mermaid |
87 |
| -flowchart TD |
88 |
| - A[Users and Devs] -->|Send Tx| B[Frontier RPC Ext] |
89 |
| - subgraph C[Pallet Ethereum] |
90 |
| - D[Validate Tx] |
91 |
| - E[Send<br/>Valid Tx] |
92 |
| - end |
93 |
| - B -->|Interact with| C |
94 |
| - D --> E |
95 |
| - subgraph F[Pallet EVM] |
96 |
| - G[Rust EVM] |
97 |
| - end |
98 |
| - I[(Current EVM<br/>Emulated State)] |
| 70 | + Set up your development environment for seamless contract deployment and testing. |
99 | 71 |
|
100 |
| - H[Smart Contract<br/>Solidity, Vyper...] <-->|Compiled to EVM<br/>Bytecode| I |
| 72 | + [:octicons-arrow-right-24: Reference](/develop/smart-contracts/evm-toolkit/dev-environments/) |
101 | 73 |
|
102 |
| - C --> F |
103 |
| - I --> F |
104 |
| - F --> J[(New Ethereum<br/>Emulated State)] |
105 |
| - F --> K[Execution Logs] |
| 74 | +- <span class="badge guide">Guide</span> __Indexers__ |
106 | 75 |
|
107 |
| - style C fill:#ffffff,stroke:#000000,stroke-width:1px |
108 |
| - style F fill:#ffffff,stroke:#000000,stroke-width:1px |
109 |
| -``` |
| 76 | + --- |
110 | 77 |
|
111 |
| -Although it seems complex, users and developers are abstracted of that complexity, and tools can easily interact with the parachain as they would with any other EVM-compatible environment. |
| 78 | + Leverage indexers to efficiently query on-chain data and improve dApp performance. |
112 | 79 |
|
113 |
| -The Rust EVM is capable of executing regular [EVM bytecode](https://www.ethervm.io/){target=\_blank}. Consequently, any language that compiles to EVM bytecode can be used to create programs that the parachain can execute. |
| 80 | + [:octicons-arrow-right-24: Reference](/develop/smart-contracts/evm-toolkit/indexers/) |
114 | 81 |
|
115 |
| -<!-- This content is temporarily hidden and has been commented out to ensure it is preserved. --> |
116 |
| -<!-- You can find more information on deploying EVM smart contracts to [Polkadot's native smart contract platform](/develop/smart-contracts/evm/native-evm-contracts/){target=\_blank}, or any of [the ecosystem parachains](/develop/smart-contracts/evm/parachain-contracts/){target=\_blank}. --> |
117 |
| - |
118 |
| -### Wasm Contracts |
119 |
| - |
120 |
| -The [`pallet_contracts`](https://docs.rs/pallet-contracts/latest/pallet_contracts/index.html#contracts-pallet){target=\_blank} provides the execution environment for Wasm-based smart contracts. Consequently, any smart contract language that compiles to Wasm can be executed in a parachain that enables this module. |
121 |
| - |
122 |
| -At the time of writing there are two main languages that can be used for Wasm programs: |
123 |
| - |
124 |
| -- [**ink!**](https://use.ink/){target=\_blank} - it is a Rust-based language that compiles to Wasm. It allows developers to inherit all its safety guarantees and use normal Rust tooling, being the dedicated domain-specific language |
125 |
| -- **Solidity** - it can be compiled to Wasm via the [Solang](https://github.com/hyperledger-solang/solang/){target=\_blank} compiler. Consequently, developers can write Solidity 0.8 smart contracts that can be executed as Wasm programs in parachains |
126 |
| - |
127 |
| -Broadly speaking, with [`pallet_contracts`](https://docs.rs/pallet-contracts/latest/pallet_contracts/index.html#contracts-pallet){target=\_blank}, a transaction follows the path presented in the diagram below: |
128 |
| - |
129 |
| -``` mermaid |
130 |
| -flowchart TD |
131 |
| - |
132 |
| - subgraph A[Wasm Bytecode API] |
133 |
| - C[Pallet Contracts] |
134 |
| - end |
135 |
| -
|
136 |
| - B[Users and Devs] -- Interact with ---> A |
137 |
| - |
138 |
| - D[(Current State)] |
139 |
| -
|
140 |
| - E[Smart Contract<br/>ink!, Solidity...] <-->|Compiled to Wasm<br/>Bytecode| D |
141 |
| -
|
142 |
| - D --> A |
143 |
| - A --> F[(New State)] |
144 |
| - A --> G[Execution Logs] |
145 |
| -
|
146 |
| - style A fill:#ffffff,stroke:#000000,stroke-width:1px |
147 |
| -``` |
148 |
| - |
149 |
| -Learn more on how to build and deploy Wasm smart contracts on the [Wasm Smart Contracts](/develop/smart-contracts/wasm-ink/){target=\_blank} page. |
150 |
| - |
151 |
| -<!-- This content is temporarily hidden and has been commented out to ensure it is preserved. --> |
152 |
| -<!-- ### PolkaVM Contracts |
153 |
| -
|
154 |
| -A component of the Asset Hub parachain, PolkaVM helps enable the deployment of Solidity-based smart contracts directly on Asset Hub. Learn more about how this cutting edge virtual machine facilitates using familiar EVM contracts and tools with Asset Hub by visiting the [Native EVM Contracts](/develop/smart-contracts/evm/native-evm-contracts/){target=\_blank} guide. --> |
| 82 | +</div> |
0 commit comments