From c7ef356d39564f3f8d7225d831965d6b64f55138 Mon Sep 17 00:00:00 2001 From: Bader Youssef Date: Mon, 9 Sep 2024 17:45:37 -0400 Subject: [PATCH 01/15] Add initial files for smart contracts --- .../application-devs/smart-contracts/.pages | 3 + .../application-devs/smart-contracts/index.md | 7 + .../smart-contracts/smart-contracts.md | 230 ++++++++++++++++++ 3 files changed, 240 insertions(+) create mode 100644 develop/application-devs/smart-contracts/.pages create mode 100644 develop/application-devs/smart-contracts/index.md create mode 100644 develop/application-devs/smart-contracts/smart-contracts.md diff --git a/develop/application-devs/smart-contracts/.pages b/develop/application-devs/smart-contracts/.pages new file mode 100644 index 000000000..f21e529af --- /dev/null +++ b/develop/application-devs/smart-contracts/.pages @@ -0,0 +1,3 @@ +title: Smart Contract Development +nav: + - index.md diff --git a/develop/application-devs/smart-contracts/index.md b/develop/application-devs/smart-contracts/index.md new file mode 100644 index 000000000..e2d06502f --- /dev/null +++ b/develop/application-devs/smart-contracts/index.md @@ -0,0 +1,7 @@ +--- +title: Smart Contract Development +description: TODO +hide: +- feedback +template: subsection-index-page.html +--- diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md new file mode 100644 index 000000000..7142eca36 --- /dev/null +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -0,0 +1,230 @@ +--- +title: Smart Contracts +description: Learn how to navigate the smart contract aspect of the Polkadot ecosystem, including available languages (Solidity, ink), platforms, and compilation targets. +--- + + + +Polkadot does not support smart contracts natively. Rather, parachains secured by Polkadot are equipped with the +functionality to support smart contracts. + +The two primary supported smart contract environments are [ink!](#ink) and EVM. There are multiple +[parachains that support both environments](#parachains). + +## Developing a Smart Contract Versus a Parachain + +[When should I build a Substrate runtime versus a Substrate smart contract](https://stackoverflow.com/a/56041305)? +This post answers the question more technically of when a developer might choose to develop a +runtime versus a smart contract. + +Here is the list of current resources available to developers who want to get started writing smart +contracts to deploy on parachains based on Substrate. + +- [ink!](https://use.ink/){target=\_blank} - Polkadot's "native" smart contract stack, based on WebAssembly. +- [ink! Workshop](https://use.ink/) - Walks you + through the basics of writing and deploying an ERC-20 token using `ink!`. + +### Layer of Abstraction + +When you write a smart contract, you are creating the instructions that associate with and deploy on +a specific chain address. + +In comparison, a runtime module on a parachain is the entire logic of a chain's state transitions +(what's called a state transition function). + +Smart contracts must consciously implement upgradability while parachains have the ability to swap +out their code entirely through a root command or via the governance pallet. + +When you build a smart contract, it will eventually be deployed to a target chain with its own +environment. Parachains allow the developer to declare the environment of their own chain, even +allowing others to write smart contracts for it. + +### Gas Fees + +Smart contracts must find a way to limit their own execution, or else full nodes are vulnerable to DOS attacks. An infinite loop in a smart contract, for example, could consume the computational resources of an entire chain, preventing others from using it. The [halting problem](https://en.wikipedia.org/wiki/Halting_problem){target=\_blank} shows that even with a powerful enough language, it is impossible to know ahead of time whether or not a program will ever cease execution. Some platforms, such as Bitcoin, get around this constraint by providing a very restricted scripting language. Others, such as Ethereum, "charge" the smart contract "gas" for the rights to execute their code. If a smart contract does get into a state where execution will never halt, it eventually runs out of gas, ceases execution, and any state transition that the smart contract would have made is rolled back. + +Parachains can implement arbitrarily powerful programming languages and contain no gas notion for their own native logic. This means that some functionality is easier to implement for the developer, but some constructs, such as a loop without a terminating condition, should _never_ be implemented. Leaving certain logic, such as complex loops that could run indefinitely, to a non-smart contract layer, or even trying to eliminate it, will often be a wiser choice. Parachains try to be proactive, while smart contract platforms are event-driven. + +Polkadot and its parachains typically use the _weight-fee model_ and not a _gas-metering model_. + +## Building a Smart Contract + +The relay chain does not natively support smart contracts. However, since the parachains that connect to can support arbitrary state transitions, they support smart contracts. + +The Polkadot SDK presently supports smart contracts out-of-the-box in several ways: + +- The EVM pallet offered by [Frontier](https://github.com/paritytech/frontier){target=\_blank} +- The [Contracts pallet](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/contracts/){target=\_blank} in the FRAME library for Wasm-based contracts + +### Frontier EVM Contracts + +[Frontier](https://github.com/paritytech/frontier) is the suite of tools that enables a Substrate chain to run Ethereum contracts (EVM) natively with the same API/RPC interface, Ethereum exposes on Substrate. Ethereum Addresses can also be mapped directly to and from Substrate's SS58 scheme from existing accounts. + + + +### Contracts Pallet + +The experience of deploying to an EVM-based chain may be more familiar to developers that have +written smart contracts before. However, the Contracts pallet makes some notable improvements to the +design of the EVM: + +1. **Wasm**. The Contracts pallet uses WebAssembly as its compilation target. Any language that + compiles to Wasm can potentially be used to write smart contracts. Nevertheless, it is better to + have a dedicated domain-specific language, and for that reason Parity offers the [ink!](#ink) + language. + +2. **Deposit**. Contracts must hold a deposit (named _ContractDeposit_ ) suitably large enough in + order to justify their existence on-chain. A deployer needs to deposit this into the new contract + on top of the _ExistentialDeposit_. +3. **Caching**. Contracts are cached by default and therefore means they only need to be deployed + once and afterward be instantiated as many times as you want. This helps to keep the storage load + on the chain down to the minimum. On top of this, when a contract is no longer being used and the + _existential deposit_ is drained, the code will be erased from storage (known as reaping). + +#### Storage Rent: Deprecated + +`pallet_contracts` was initially designed to combat unbounded state growth by charging contracts for +the state they consume but has since been deprecated. + +See the associated [pull request](https://github.com/paritytech/substrate/pull/9669) for more +details. + +### Ink + +[ink!](https://github.com/paritytech/ink) is a domain specific language for writing smart contracts +in Rust and compiles to Wasm code. As it states in its README, it is still in an experimental phase +so brave developers should be aware that they might have a bumpy - but workable - development +experience. There are some projects that have built projects in ink! with a decent level of +complexity such as Plasm's [Plasma contracts](https://github.com/staketechnologies/Plasm), so it is +mature enough to start building interesting things. + +For interested developers, they can get started writing smart contracts using ink! by studying the +[examples](https://github.com/paritytech/ink/tree/master/examples) that were already written. These +can be used as guideposts to writing more complex logic that will be deployable on smart contract +parachains. + +ink! has laid much of the groundwork for a new smart contract stack that is based on a Wasm virtual +machine and compatible with Substrate chains. + +#### Libraries for Smart Contracts in `ink!` + +Collected below are some community examples of smart contracts in `ink!`. **Are you working on a +smart contract example? Ask us to add it to this page!** + +- [OpenBrush](https://docs.openbrush.io/): an `ink!` library providing standard contracts based on + [PSP](https://github.com/w3f/PSPs) with useful contracts and macros for building. +- [ink!athon](https://inkathon.xyz/): Starterkit for full-stack dApps with ink! smart contracts & + frontend. +- [Metis](https://github.com/patractlabs/metis): a Wasm contract standard library, developed by + [Patract Labs](https://github.com/patractlabs). + +## Smart Contract Environments + +It is still early for smart contracts on {{ polkadot: Polkadot :polkadot }} +{{ kusama: Kusama :kusama }} and the development is only now stabilizing. We are actively producing +content to help developers get up to speed and will maintain the Wiki with the latest resources. You +should also keep up to date with the following links: + +### Parity Tech + +- [ink!](https://github.com/paritytech/ink) +- [Substrate contracts pallet](https://github.com/paritytech/polkadot-sdk/tree/master/substrate/frame/contracts) + +### Parachains + +- [Moonbeam](https://moonbeam.network/) +- [Astar](https://astar.network/) +- [Acala](https://acala.network/) +- [Phala](https://phala.network) +- [Darwinia](https://darwinia.network/) + +Many smart contract platforms are building to become a parachain in the ecosystem. A community +created and maintained list of different smart contract platforms building on +{{ polkadot: Polkadot :polkadot }}{{ kusama: Kusama :kusama }} can be found at +[PolkaProjects](https://www.polkaproject.com/#/projects?cateID=1&tagID=6). Additionally, information +about ink smart contracts can be accessed at +[use.ink](https://use.ink/#where-can-i-deploy-ink-contracts). + +#### Moonbeam + +- ink!: **Unsupported** +- EVM (Solidity): [**Supported**](https://moonbeam.network/networks/moonbeam/) + +[Moonbeam](https://moonbeam.network/) is another project that is planning to deploy to Polkadot as a +parachain and will support Ethereum compatible smart contracts. Since Moonbeam uses +[Frontier](https://github.com/paritytech/frontier), an interoperability layer with existing Ethereum +tooling, it will support all applications that are written to target the EVM environment with little +friction. + +[Moonriver](https://docs.moonbeam.network/networks/moonriver/), a companion network to Moonbeam, +launched as a parachain on Kusama. Parachain functionality is live, and features are being +incrementally released. The final phase of the launch will include EVM functionality and balance +transfers. + +Try deploying a smart contract to Moonbeam by following their +[documentation](https://docs.moonbeam.network/). + +#### Astar + +- ink!/Wasm: [**Supported**](https://docs.astar.network/docs/build/#wasm-smart-contracts) +- EVM (Solidity): [ **Supported**](https://docs.astar.network/docs/build/#evm-smart-contracts) + +[Astar Network](https://astar.network/) supports the building of dApps with EVM and WASM smart +contracts and offers developers true interoperability. True interoperability with cross-consensus +messaging [XCM](https://wiki.polkadot.network/docs/learn-xcm) and cross-virtual machine +[XVM](https://github.com/AstarNetwork/). We are made by developers and for developers. Astar’s +unique Build2Earn model empowers developers to get paid through a dApp staking mechanism for the +code they write and dApps they build. + +[Shiden Network](https://shiden.astar.network/) is the canary network of Astar Network, live as a +parachain on Kusama, and supports the EVM and WASM environment for all developers who want to build +out use-cases in a canary network with economic value. Shiden acts as a playground for developers. + +Try deploying an Ethereum or ink! smart contract by following their +[documentation](https://docs.astar.network/). + +#### Acala + +- ink!: **Unsupported** +- EVM (Solidity): [**Supported**](https://wiki.acala.network/build/development-guide) + +[Acala](https://acala.network/) is a decentralized finance consortium and DeFi infrastructure chain +delivering a set of protocols to serve as the DeFi hub on Polkadot. +[Karura](https://acala.network/karura), Acala's canary network is live as a parachain on Kusama. +Interested teams are now able to deploy DApps and smart contracts on Karura's platform. Acala is +also implementing the [Acala EVM](https://wiki.acala.network/learn/acala-evm/why-acala-evm). + +Try deploying an Acala EVM smart contract by following their +[documentation](https://wiki.acala.network/build/development-guide/smart-contracts). + +#### Phala + +- ink!: **Unsupported** +- EVM (Solidity): **Unsupported** +- See: [**Phat Contracts**](https://docs.phala.network/developers/phat-contract) powered by ink! + +[Phala](https://phala.network) is an off-chain trustless compute infrastructure that provides fully +verifiable computation. Using [Phat contracts](https://docs.phala.network/developers/phat-contract), +developers can write smart contracts that can interact with web2 services. +[Khala](https://phala.network/en/khala) is Phala's canary network and is live as a parachain on +Kusama. + +Try deploying a smart contract that interacts with Etherscan's web2 API by following their +[documentation](https://docs.phala.network/developers/build-on-phat-contract/create-contract). + +#### Darwinia + +- ink!: **Unsupported** +- EVM (Solidity) Support: + [**Supported**](https://docs.darwinia.network/libraries-4a4ce70014ba43b7977aeb16ce9634ab) + +[Darwinia](https://darwinia.network/) is a community-run technology and service powering the +cross-chain capabilities of decentralized applications. By crafting secure and efficient cross-chain +messaging protocols, Darwinia is at the forefront of facilitating seamless communication between +disparate blockchain networks. The newest addition to the suite of protocols is `Darwinia Msgport`, +an innovative messaging abstraction that has been successfully implemented across a wide array of +mainstream smart contract platforms, broadening the potential for interoperability and enabling +developers to create more versatile and connected blockchain ecosystems. + +Try deploying a smart contract to Darwinia by following their +[documentation](https://docs.darwinia.network/dapp-development-4b021f21c52d474aa08a8109eb55bbd1). \ No newline at end of file From a0fcdd90b1e9796cad7be10eb6e2ab4fded22f10 Mon Sep 17 00:00:00 2001 From: Bader Youssef Date: Tue, 10 Sep 2024 16:51:13 -0400 Subject: [PATCH 02/15] vale --- .../smart-contracts/smart-contracts.md | 135 ++++++------------ 1 file changed, 43 insertions(+), 92 deletions(-) diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index 7142eca36..df0f02599 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -3,27 +3,16 @@ title: Smart Contracts description: Learn how to navigate the smart contract aspect of the Polkadot ecosystem, including available languages (Solidity, ink), platforms, and compilation targets. --- - +Polkadot doesn't support smart contracts natively. Rather, parachains secured by Polkadot are equipped with the functionality to support smart contracts. -Polkadot does not support smart contracts natively. Rather, parachains secured by Polkadot are equipped with the -functionality to support smart contracts. - -The two primary supported smart contract environments are [ink!](#ink) and EVM. There are multiple -[parachains that support both environments](#parachains). +The two primary supported smart contract environments are [ink!](#ink) and EVM. There are multiple [parachains that support both environments](#parachains). ## Developing a Smart Contract Versus a Parachain -[When should I build a Substrate runtime versus a Substrate smart contract](https://stackoverflow.com/a/56041305)? +[When should one build a Substrate (Polkadot SDK) runtime versus a Substrate (Polkadot SDK) smart contract](https://stackoverflow.com/a/56041305){target=\_blank}? This post answers the question more technically of when a developer might choose to develop a runtime versus a smart contract. -Here is the list of current resources available to developers who want to get started writing smart -contracts to deploy on parachains based on Substrate. - -- [ink!](https://use.ink/){target=\_blank} - Polkadot's "native" smart contract stack, based on WebAssembly. -- [ink! Workshop](https://use.ink/) - Walks you - through the basics of writing and deploying an ERC-20 token using `ink!`. - ### Layer of Abstraction When you write a smart contract, you are creating the instructions that associate with and deploy on @@ -32,8 +21,8 @@ a specific chain address. In comparison, a runtime module on a parachain is the entire logic of a chain's state transitions (what's called a state transition function). -Smart contracts must consciously implement upgradability while parachains have the ability to swap -out their code entirely through a root command or via the governance pallet. +Smart contracts must consciously implement a path to upgrading in the future, while parachains have the ability to swap +out their code through a forkless upgrade. When you build a smart contract, it will eventually be deployed to a target chain with its own environment. Parachains allow the developer to declare the environment of their own chain, even @@ -49,7 +38,7 @@ Polkadot and its parachains typically use the _weight-fee model_ and not a _gas- ## Building a Smart Contract -The relay chain does not natively support smart contracts. However, since the parachains that connect to can support arbitrary state transitions, they support smart contracts. +The relay chain doesn't natively support smart contracts. However, since the parachains that connect to can support arbitrary state transitions, they support smart contracts. The Polkadot SDK presently supports smart contracts out-of-the-box in several ways: @@ -74,8 +63,9 @@ design of the EVM: language. 2. **Deposit**. Contracts must hold a deposit (named _ContractDeposit_ ) suitably large enough in - order to justify their existence on-chain. A deployer needs to deposit this into the new contract + order to justify their existence on-chain. The developer needs to deposit this into the new contract on top of the _ExistentialDeposit_. + 3. **Caching**. Contracts are cached by default and therefore means they only need to be deployed once and afterward be instantiated as many times as you want. This helps to keep the storage load on the chain down to the minimum. On top of this, when a contract is no longer being used and the @@ -86,137 +76,98 @@ design of the EVM: `pallet_contracts` was initially designed to combat unbounded state growth by charging contracts for the state they consume but has since been deprecated. -See the associated [pull request](https://github.com/paritytech/substrate/pull/9669) for more +See the associated [pull request](https://github.com/paritytech/substrate/pull/9669){target=\_blank} for more details. ### Ink -[ink!](https://github.com/paritytech/ink) is a domain specific language for writing smart contracts -in Rust and compiles to Wasm code. As it states in its README, it is still in an experimental phase -so brave developers should be aware that they might have a bumpy - but workable - development -experience. There are some projects that have built projects in ink! with a decent level of -complexity such as Plasm's [Plasma contracts](https://github.com/staketechnologies/Plasm), so it is -mature enough to start building interesting things. +[ink!](https://github.com/use-ink/ink) is a domain specific language for writing smart contracts +in Rust and compiles to Wasm code. + +Here is the list of current resources available to developers who want to get started writing smart +contracts to deploy on parachains based on Substrate. -For interested developers, they can get started writing smart contracts using ink! by studying the -[examples](https://github.com/paritytech/ink/tree/master/examples) that were already written. These -can be used as guideposts to writing more complex logic that will be deployable on smart contract -parachains. +- [ink!](https://use.ink/){target=\_blank} - Polkadot's "native" smart contract stack, based on WebAssembly +- [OpenBrush](https://docs.openbrush.io/){target=\_blank}: an `ink!` library providing standard contracts based on [PSP](https://github.com/w3f/PSPs){target=\_blank} with useful contracts and macros for building +- [ink!athon](https://inkathon.xyz/){target=\_blank}: Starter kit for full-stack dApps with ink! smart contracts and frontend ink! has laid much of the groundwork for a new smart contract stack that is based on a Wasm virtual machine and compatible with Substrate chains. -#### Libraries for Smart Contracts in `ink!` - -Collected below are some community examples of smart contracts in `ink!`. **Are you working on a -smart contract example? Ask us to add it to this page!** - -- [OpenBrush](https://docs.openbrush.io/): an `ink!` library providing standard contracts based on - [PSP](https://github.com/w3f/PSPs) with useful contracts and macros for building. -- [ink!athon](https://inkathon.xyz/): Starterkit for full-stack dApps with ink! smart contracts & - frontend. -- [Metis](https://github.com/patractlabs/metis): a Wasm contract standard library, developed by - [Patract Labs](https://github.com/patractlabs). - ## Smart Contract Environments -It is still early for smart contracts on {{ polkadot: Polkadot :polkadot }} -{{ kusama: Kusama :kusama }} and the development is only now stabilizing. We are actively producing -content to help developers get up to speed and will maintain the Wiki with the latest resources. You -should also keep up to date with the following links: - -### Parity Tech - -- [ink!](https://github.com/paritytech/ink) -- [Substrate contracts pallet](https://github.com/paritytech/polkadot-sdk/tree/master/substrate/frame/contracts) - -### Parachains - -- [Moonbeam](https://moonbeam.network/) -- [Astar](https://astar.network/) -- [Acala](https://acala.network/) -- [Phala](https://phala.network) -- [Darwinia](https://darwinia.network/) - -Many smart contract platforms are building to become a parachain in the ecosystem. A community -created and maintained list of different smart contract platforms building on -{{ polkadot: Polkadot :polkadot }}{{ kusama: Kusama :kusama }} can be found at -[PolkaProjects](https://www.polkaproject.com/#/projects?cateID=1&tagID=6). Additionally, information -about ink smart contracts can be accessed at -[use.ink](https://use.ink/#where-can-i-deploy-ink-contracts). +Many smart contract platforms are building to become a parachain in the ecosystem. A community created and maintained list of different smart contract platforms can be found at [PolkaProjects](https://www.polkaproject.com/#/projects?cateID=1&tagID=6){target=\_blank}. Additionally, information about ink smart contracts can be accessed at [use.ink](https://use.ink/#where-can-i-deploy-ink-contracts){target=\_blank}. #### Moonbeam - ink!: **Unsupported** -- EVM (Solidity): [**Supported**](https://moonbeam.network/networks/moonbeam/) +- EVM (Solidity): [**Supported**](https://moonbeam.network/networks/moonbeam/){target=\_blank} -[Moonbeam](https://moonbeam.network/) is another project that is planning to deploy to Polkadot as a +[Moonbeam](https://moonbeam.network/){target=\_blank} is another project that is planning to deploy to Polkadot as a parachain and will support Ethereum compatible smart contracts. Since Moonbeam uses -[Frontier](https://github.com/paritytech/frontier), an interoperability layer with existing Ethereum +[Frontier](https://github.com/paritytech/frontier){target=\_blank}, an interoperability layer with existing Ethereum tooling, it will support all applications that are written to target the EVM environment with little friction. -[Moonriver](https://docs.moonbeam.network/networks/moonriver/), a companion network to Moonbeam, +[Moonriver](https://docs.moonbeam.network/networks/moonriver/){target=\_blank}, a companion network to Moonbeam, launched as a parachain on Kusama. Parachain functionality is live, and features are being incrementally released. The final phase of the launch will include EVM functionality and balance transfers. -Try deploying a smart contract to Moonbeam by following their -[documentation](https://docs.moonbeam.network/). +Try deploying a smart contract to Moonbeam by following their [documentation](https://docs.moonbeam.network/){target=\_blank}. #### Astar -- ink!/Wasm: [**Supported**](https://docs.astar.network/docs/build/#wasm-smart-contracts) -- EVM (Solidity): [ **Supported**](https://docs.astar.network/docs/build/#evm-smart-contracts) +- ink!/Wasm: [**Supported**](https://docs.astar.network/docs/build/#wasm-smart-contracts){target=\_blank} +- EVM (Solidity): [ **Supported**](https://docs.astar.network/docs/build/#evm-smart-contracts){target=\_blank} -[Astar Network](https://astar.network/) supports the building of dApps with EVM and WASM smart +[Astar Network](https://astar.network/){target=\_blank} supports the building of dApps with EVM and Wasm smart contracts and offers developers true interoperability. True interoperability with cross-consensus -messaging [XCM](https://wiki.polkadot.network/docs/learn-xcm) and cross-virtual machine -[XVM](https://github.com/AstarNetwork/). We are made by developers and for developers. Astar’s +messaging [XCM](https://wiki.polkadot.network/docs/learn-xcm){target=\_blank} and cross-virtual machine +[XVM](https://github.com/AstarNetwork/){target=\_blank}. We are made by developers and for developers. Astar’s unique Build2Earn model empowers developers to get paid through a dApp staking mechanism for the code they write and dApps they build. -[Shiden Network](https://shiden.astar.network/) is the canary network of Astar Network, live as a -parachain on Kusama, and supports the EVM and WASM environment for all developers who want to build +[Shiden Network](https://shiden.astar.network/){target=\_blank} is the canary network of Astar Network, live as a +parachain on Kusama, and supports the EVM and Wasm environment for all developers who want to build out use-cases in a canary network with economic value. Shiden acts as a playground for developers. Try deploying an Ethereum or ink! smart contract by following their -[documentation](https://docs.astar.network/). +[documentation](https://docs.astar.network/){target=\_blank}. #### Acala - ink!: **Unsupported** -- EVM (Solidity): [**Supported**](https://wiki.acala.network/build/development-guide) +- EVM (Solidity): [**Supported**](https://wiki.acala.network/build/development-guide){target=\_blank} -[Acala](https://acala.network/) is a decentralized finance consortium and DeFi infrastructure chain +[Acala](https://acala.network/){target=\_blank} is a decentralized finance consortium and DeFi infrastructure chain delivering a set of protocols to serve as the DeFi hub on Polkadot. -[Karura](https://acala.network/karura), Acala's canary network is live as a parachain on Kusama. +[Karura](https://acala.network/karura){target=\_blank}, Acala's canary network is live as a parachain on Kusama. Interested teams are now able to deploy DApps and smart contracts on Karura's platform. Acala is -also implementing the [Acala EVM](https://wiki.acala.network/learn/acala-evm/why-acala-evm). +also implementing the [Acala EVM](https://wiki.acala.network/learn/acala-evm/why-acala-evm){target=\_blank}. -Try deploying an Acala EVM smart contract by following their -[documentation](https://wiki.acala.network/build/development-guide/smart-contracts). +Try deploying an Acala EVM smart contract by following their [documentation](https://wiki.acala.network/build/development-guide/smart-contracts){target=\_blank}. #### Phala - ink!: **Unsupported** - EVM (Solidity): **Unsupported** -- See: [**Phat Contracts**](https://docs.phala.network/developers/phat-contract) powered by ink! +- See: [**Phat Contracts**](https://docs.phala.network/developers/phat-contract){target=\_blank} powered by ink! -[Phala](https://phala.network) is an off-chain trustless compute infrastructure that provides fully -verifiable computation. Using [Phat contracts](https://docs.phala.network/developers/phat-contract), +[Phala](https://phala.network){target=\_blank} is an off-chain trustless compute infrastructure that provides fully +verifiable computation. Using [Phat contracts](https://docs.phala.network/developers/phat-contract){target=\_blank}, developers can write smart contracts that can interact with web2 services. -[Khala](https://phala.network/en/khala) is Phala's canary network and is live as a parachain on +[Khala](https://phala.network/en/khala){target=\_blank} is Phala's canary network and is live as a parachain on Kusama. Try deploying a smart contract that interacts with Etherscan's web2 API by following their -[documentation](https://docs.phala.network/developers/build-on-phat-contract/create-contract). +[documentation](https://docs.phala.network/developers/build-on-phat-contract/create-contract){target=\_blank}. #### Darwinia - ink!: **Unsupported** - EVM (Solidity) Support: - [**Supported**](https://docs.darwinia.network/libraries-4a4ce70014ba43b7977aeb16ce9634ab) + [**Supported**](https://docs.darwinia.network/libraries-4a4ce70014ba43b7977aeb16ce9634ab){target=\_blank} [Darwinia](https://darwinia.network/) is a community-run technology and service powering the cross-chain capabilities of decentralized applications. By crafting secure and efficient cross-chain @@ -227,4 +178,4 @@ mainstream smart contract platforms, broadening the potential for interoperabili developers to create more versatile and connected blockchain ecosystems. Try deploying a smart contract to Darwinia by following their -[documentation](https://docs.darwinia.network/dapp-development-4b021f21c52d474aa08a8109eb55bbd1). \ No newline at end of file +[documentation](https://docs.darwinia.network/dapp-development-4b021f21c52d474aa08a8109eb55bbd1){target=\_blank}. \ No newline at end of file From 9887371f74781dec1c5d1e7562e19b6c0b0c0b18 Mon Sep 17 00:00:00 2001 From: Bader Youssef Date: Thu, 12 Sep 2024 19:13:56 -0400 Subject: [PATCH 03/15] revision --- develop/application-devs/.pages | 1 + .../application-devs/smart-contracts/.pages | 1 + .../smart-contracts/smart-contracts.md | 34 ++++++------------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/develop/application-devs/.pages b/develop/application-devs/.pages index 073a4bc79..56eda9e33 100644 --- a/develop/application-devs/.pages +++ b/develop/application-devs/.pages @@ -4,3 +4,4 @@ nav: - interact - tooling - system-parachains + - smart-contracts diff --git a/develop/application-devs/smart-contracts/.pages b/develop/application-devs/smart-contracts/.pages index f21e529af..5ccdc9a69 100644 --- a/develop/application-devs/smart-contracts/.pages +++ b/develop/application-devs/smart-contracts/.pages @@ -1,3 +1,4 @@ title: Smart Contract Development nav: - index.md + - smart-contracts.md diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index df0f02599..89b878ed2 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -9,9 +9,10 @@ The two primary supported smart contract environments are [ink!](#ink) and EVM. ## Developing a Smart Contract Versus a Parachain +!!!info "For a more technical/thorough breakdown, refer to the [`polkadot_sdk_docs`](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/runtime_vs_smart_contract/index.html){target=\_blank}" + [When should one build a Substrate (Polkadot SDK) runtime versus a Substrate (Polkadot SDK) smart contract](https://stackoverflow.com/a/56041305){target=\_blank}? -This post answers the question more technically of when a developer might choose to develop a -runtime versus a smart contract. +This post also answers the question more technically of when a developer might choose to develop a runtime versus a smart contract. ### Layer of Abstraction @@ -28,13 +29,7 @@ When you build a smart contract, it will eventually be deployed to a target chai environment. Parachains allow the developer to declare the environment of their own chain, even allowing others to write smart contracts for it. -### Gas Fees - -Smart contracts must find a way to limit their own execution, or else full nodes are vulnerable to DOS attacks. An infinite loop in a smart contract, for example, could consume the computational resources of an entire chain, preventing others from using it. The [halting problem](https://en.wikipedia.org/wiki/Halting_problem){target=\_blank} shows that even with a powerful enough language, it is impossible to know ahead of time whether or not a program will ever cease execution. Some platforms, such as Bitcoin, get around this constraint by providing a very restricted scripting language. Others, such as Ethereum, "charge" the smart contract "gas" for the rights to execute their code. If a smart contract does get into a state where execution will never halt, it eventually runs out of gas, ceases execution, and any state transition that the smart contract would have made is rolled back. - -Parachains can implement arbitrarily powerful programming languages and contain no gas notion for their own native logic. This means that some functionality is easier to implement for the developer, but some constructs, such as a loop without a terminating condition, should _never_ be implemented. Leaving certain logic, such as complex loops that could run indefinitely, to a non-smart contract layer, or even trying to eliminate it, will often be a wiser choice. Parachains try to be proactive, while smart contract platforms are event-driven. - -Polkadot and its parachains typically use the _weight-fee model_ and not a _gas-metering model_. +The concept of *gas*, or *fees* in general, also are approached differently between the two. Smart contracts are bound by the gas-metering model, whereas runtimes (and their subsequent modules) are much more flexible in terms of the fee models that can be employed. ## Building a Smart Contract @@ -43,21 +38,20 @@ The relay chain doesn't natively support smart contracts. However, since the par The Polkadot SDK presently supports smart contracts out-of-the-box in several ways: - The EVM pallet offered by [Frontier](https://github.com/paritytech/frontier){target=\_blank} -- The [Contracts pallet](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/contracts/){target=\_blank} in the FRAME library for Wasm-based contracts +- The [contracts pallet](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/contracts/){target=\_blank} in the FRAME library for Wasm-based contracts ### Frontier EVM Contracts [Frontier](https://github.com/paritytech/frontier) is the suite of tools that enables a Substrate chain to run Ethereum contracts (EVM) natively with the same API/RPC interface, Ethereum exposes on Substrate. Ethereum Addresses can also be mapped directly to and from Substrate's SS58 scheme from existing accounts. - +- [Pallet EVM](https://docs.rs/pallet-evm/latest/pallet_evm/){target=\_blank} - enables functionality of running EVM (Solidity) contracts +- [Pallet Ethereum](https://docs.rs/pallet-ethereum/latest/pallet_ethereum/){target=\_blank} - Ethereum RPC implementation, block emulation, and Ethereum transaction validation ### Contracts Pallet -The experience of deploying to an EVM-based chain may be more familiar to developers that have -written smart contracts before. However, the Contracts pallet makes some notable improvements to the -design of the EVM: +The contracts pallet (`pallet_contracts`) implements a WebAssembly-based approach to smart contracts. -1. **Wasm**. The Contracts pallet uses WebAssembly as its compilation target. Any language that +1. **Wasm**. The contracts pallet uses WebAssembly as its compilation target. Any language that compiles to Wasm can potentially be used to write smart contracts. Nevertheless, it is better to have a dedicated domain-specific language, and for that reason Parity offers the [ink!](#ink) language. @@ -71,17 +65,9 @@ design of the EVM: on the chain down to the minimum. On top of this, when a contract is no longer being used and the _existential deposit_ is drained, the code will be erased from storage (known as reaping). -#### Storage Rent: Deprecated - -`pallet_contracts` was initially designed to combat unbounded state growth by charging contracts for -the state they consume but has since been deprecated. - -See the associated [pull request](https://github.com/paritytech/substrate/pull/9669){target=\_blank} for more -details. - ### Ink -[ink!](https://github.com/use-ink/ink) is a domain specific language for writing smart contracts +[ink!](https://github.com/use-ink/ink){target=\_blank} is a domain specific language for writing smart contracts in Rust and compiles to Wasm code. Here is the list of current resources available to developers who want to get started writing smart From 1f13de950695fea3483140979a6f4ce9658e6d75 Mon Sep 17 00:00:00 2001 From: Bader Youssef Date: Fri, 13 Sep 2024 09:34:38 -0400 Subject: [PATCH 04/15] update links --- .../smart-contracts/smart-contracts.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index 89b878ed2..6e5159d49 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -138,24 +138,22 @@ Try deploying an Acala EVM smart contract by following their [documentation](htt - ink!: **Unsupported** - EVM (Solidity): **Unsupported** -- See: [**Phat Contracts**](https://docs.phala.network/developers/phat-contract){target=\_blank} powered by ink! +- See: [**Phat Contracts** / **AI Agent Contracts**](https://phala.network/phat-contractt){target=\_blank} [Phala](https://phala.network){target=\_blank} is an off-chain trustless compute infrastructure that provides fully -verifiable computation. Using [Phat contracts](https://docs.phala.network/developers/phat-contract){target=\_blank}, -developers can write smart contracts that can interact with web2 services. -[Khala](https://phala.network/en/khala){target=\_blank} is Phala's canary network and is live as a parachain on +verifiable computation. [Khala](https://phala.network/en/khala){target=\_blank} is Phala's canary network and is live as a parachain on Kusama. Try deploying a smart contract that interacts with Etherscan's web2 API by following their -[documentation](https://docs.phala.network/developers/build-on-phat-contract/create-contract){target=\_blank}. +[documentation](https://docs.phala.network/ai-agent-contract/build){target=\_blank}. #### Darwinia - ink!: **Unsupported** - EVM (Solidity) Support: - [**Supported**](https://docs.darwinia.network/libraries-4a4ce70014ba43b7977aeb16ce9634ab){target=\_blank} + [**Supported**](https://docs.darwinia.network/build/getting-started/networks/overview/){target=\_blank} -[Darwinia](https://darwinia.network/) is a community-run technology and service powering the +[Darwinia](https://darwinia.network/){target=\_blank} is a community-run technology and service powering the cross-chain capabilities of decentralized applications. By crafting secure and efficient cross-chain messaging protocols, Darwinia is at the forefront of facilitating seamless communication between disparate blockchain networks. The newest addition to the suite of protocols is `Darwinia Msgport`, @@ -163,5 +161,4 @@ an innovative messaging abstraction that has been successfully implemented acros mainstream smart contract platforms, broadening the potential for interoperability and enabling developers to create more versatile and connected blockchain ecosystems. -Try deploying a smart contract to Darwinia by following their -[documentation](https://docs.darwinia.network/dapp-development-4b021f21c52d474aa08a8109eb55bbd1){target=\_blank}. \ No newline at end of file +Try deploying a smart contract to Darwinia by following their [documentation](https://docs.darwinia.network/build/ethereum-tools/interact-with-web3js/){target=\_blank}. \ No newline at end of file From 9bae6425b334c88676c4a2c3fdbec8a471edf727 Mon Sep 17 00:00:00 2001 From: Bader Youssef Date: Fri, 13 Sep 2024 09:34:51 -0400 Subject: [PATCH 05/15] space --- develop/application-devs/smart-contracts/smart-contracts.md | 1 + 1 file changed, 1 insertion(+) diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index 6e5159d49..884d03a42 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -128,6 +128,7 @@ Try deploying an Ethereum or ink! smart contract by following their [Acala](https://acala.network/){target=\_blank} is a decentralized finance consortium and DeFi infrastructure chain delivering a set of protocols to serve as the DeFi hub on Polkadot. + [Karura](https://acala.network/karura){target=\_blank}, Acala's canary network is live as a parachain on Kusama. Interested teams are now able to deploy DApps and smart contracts on Karura's platform. Acala is also implementing the [Acala EVM](https://wiki.acala.network/learn/acala-evm/why-acala-evm){target=\_blank}. From 5a906fafbda2be3074663ddf7f5b1caf440f63ff Mon Sep 17 00:00:00 2001 From: Bader Youssef Date: Fri, 13 Sep 2024 09:36:22 -0400 Subject: [PATCH 06/15] vale --- develop/application-devs/smart-contracts/smart-contracts.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index 884d03a42..f1ec4e001 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -29,7 +29,7 @@ When you build a smart contract, it will eventually be deployed to a target chai environment. Parachains allow the developer to declare the environment of their own chain, even allowing others to write smart contracts for it. -The concept of *gas*, or *fees* in general, also are approached differently between the two. Smart contracts are bound by the gas-metering model, whereas runtimes (and their subsequent modules) are much more flexible in terms of the fee models that can be employed. +The concept of *gas*, or *fees* in general, also are approached differently between the two. Smart contracts are bound by the gas-metering model, whereas runtimes (and their subsequent modules) are much more flexible in terms of the fee models that can be employed. ## Building a Smart Contract @@ -49,7 +49,7 @@ The Polkadot SDK presently supports smart contracts out-of-the-box in several wa ### Contracts Pallet -The contracts pallet (`pallet_contracts`) implements a WebAssembly-based approach to smart contracts. +The contracts pallet (`pallet_contracts`) implements a WebAssembly based approach to smart contracts. 1. **Wasm**. The contracts pallet uses WebAssembly as its compilation target. Any language that compiles to Wasm can potentially be used to write smart contracts. Nevertheless, it is better to From 177b7c247cdb20a5edf0c8535974d6015352af09 Mon Sep 17 00:00:00 2001 From: Bader Youssef Date: Mon, 7 Oct 2024 15:59:47 -0400 Subject: [PATCH 07/15] address most feedback --- .../application-devs/smart-contracts/index.md | 2 +- .../smart-contracts/smart-contracts.md | 50 +++++++------------ 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/develop/application-devs/smart-contracts/index.md b/develop/application-devs/smart-contracts/index.md index e2d06502f..e9a70c70c 100644 --- a/develop/application-devs/smart-contracts/index.md +++ b/develop/application-devs/smart-contracts/index.md @@ -1,6 +1,6 @@ --- title: Smart Contract Development -description: TODO +description: Learn about smart contract development, tooling, and options within the Polkadot ecosystem, including EVM, PVM, and ink! based approaches. hide: - feedback template: subsection-index-page.html diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index f1ec4e001..7c81d01ee 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -5,29 +5,24 @@ description: Learn how to navigate the smart contract aspect of the Polkadot eco Polkadot doesn't support smart contracts natively. Rather, parachains secured by Polkadot are equipped with the functionality to support smart contracts. -The two primary supported smart contract environments are [ink!](#ink) and EVM. There are multiple [parachains that support both environments](#parachains). +The two primary supported smart contract environments are [ink!](#ink) and EVM. There are multiple [parachains that support both environments](#smart-contract-environments). ## Developing a Smart Contract Versus a Parachain !!!info "For a more technical/thorough breakdown, refer to the [`polkadot_sdk_docs`](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/runtime_vs_smart_contract/index.html){target=\_blank}" -[When should one build a Substrate (Polkadot SDK) runtime versus a Substrate (Polkadot SDK) smart contract](https://stackoverflow.com/a/56041305){target=\_blank}? -This post also answers the question more technically of when a developer might choose to develop a runtime versus a smart contract. +[When should one build a Substrate (Polkadot SDK) runtime versus a Substrate (Polkadot SDK) smart contract](https://stackoverflow.com/a/56041305){target=\_blank}? This post also answers the question more technically of when a developer might choose to develop a runtime versus a smart contract. ### Layer of Abstraction When you write a smart contract, you are creating the instructions that associate with and deploy on a specific chain address. -In comparison, a runtime module on a parachain is the entire logic of a chain's state transitions -(what's called a state transition function). +In comparison, a runtime module on a parachain is the entire logic of a chain's state transitions (what's called a state transition function). -Smart contracts must consciously implement a path to upgrading in the future, while parachains have the ability to swap -out their code through a forkless upgrade. +Smart contracts must consciously implement a path to upgrading in the future, while parachains have the ability to swap out their code through a forkless upgrade. -When you build a smart contract, it will eventually be deployed to a target chain with its own -environment. Parachains allow the developer to declare the environment of their own chain, even -allowing others to write smart contracts for it. +When you build a smart contract, it will eventually be deployed to a target chain with its own environment. Parachains allow the developer to declare the environment of their own chain, even allowing others to write smart contracts for it. The concept of *gas*, or *fees* in general, also are approached differently between the two. Smart contracts are bound by the gas-metering model, whereas runtimes (and their subsequent modules) are much more flexible in terms of the fee models that can be employed. @@ -42,16 +37,16 @@ The Polkadot SDK presently supports smart contracts out-of-the-box in several wa ### Frontier EVM Contracts -[Frontier](https://github.com/paritytech/frontier) is the suite of tools that enables a Substrate chain to run Ethereum contracts (EVM) natively with the same API/RPC interface, Ethereum exposes on Substrate. Ethereum Addresses can also be mapped directly to and from Substrate's SS58 scheme from existing accounts. +[Frontier](https://github.com/paritytech/frontier) is the suite of tools that enables a Polkadot SDK-based chain to run Ethereum contracts (EVM) natively with the same API/RPC interface. Ethereum addresses can also be mapped directly to and from the Polkadot SDK's SS58 scheme from existing accounts. - [Pallet EVM](https://docs.rs/pallet-evm/latest/pallet_evm/){target=\_blank} - enables functionality of running EVM (Solidity) contracts - [Pallet Ethereum](https://docs.rs/pallet-ethereum/latest/pallet_ethereum/){target=\_blank} - Ethereum RPC implementation, block emulation, and Ethereum transaction validation ### Contracts Pallet -The contracts pallet (`pallet_contracts`) implements a WebAssembly based approach to smart contracts. +The contracts pallet (`pallet_contracts`) implements a Wasm based approach to smart contracts. -1. **Wasm**. The contracts pallet uses WebAssembly as its compilation target. Any language that +1. **Wasm**. The contracts pallet uses Wasm as its compilation target. Any language that compiles to Wasm can potentially be used to write smart contracts. Nevertheless, it is better to have a dedicated domain-specific language, and for that reason Parity offers the [ink!](#ink) language. @@ -67,18 +62,15 @@ The contracts pallet (`pallet_contracts`) implements a WebAssembly based approac ### Ink -[ink!](https://github.com/use-ink/ink){target=\_blank} is a domain specific language for writing smart contracts -in Rust and compiles to Wasm code. +[ink!](https://github.com/use-ink/ink){target=\_blank} is a domain specific language for writing smart contracts in Rust and compiles to Wasm code. -Here is the list of current resources available to developers who want to get started writing smart -contracts to deploy on parachains based on Substrate. +Here is the list of current resources available to developers who want to get started writing smart contracts to deploy on parachains based on Substrate. -- [ink!](https://use.ink/){target=\_blank} - Polkadot's "native" smart contract stack, based on WebAssembly +- [ink!](https://use.ink/){target=\_blank} - Polkadot's "native" smart contract stack, based on Wasm - [OpenBrush](https://docs.openbrush.io/){target=\_blank}: an `ink!` library providing standard contracts based on [PSP](https://github.com/w3f/PSPs){target=\_blank} with useful contracts and macros for building - [ink!athon](https://inkathon.xyz/){target=\_blank}: Starter kit for full-stack dApps with ink! smart contracts and frontend -ink! has laid much of the groundwork for a new smart contract stack that is based on a Wasm virtual -machine and compatible with Substrate chains. +ink! has laid much of the groundwork for a new smart contract stack that is based on a Wasm virtual machine and compatible with Polkadot SDK-based chains. ## Smart Contract Environments @@ -87,12 +79,12 @@ Many smart contract platforms are building to become a parachain in the ecosyste #### Moonbeam - ink!: **Unsupported** -- EVM (Solidity): [**Supported**](https://moonbeam.network/networks/moonbeam/){target=\_blank} +- EVM (Solidity): [**Supported**](https://docs.moonbeam.network/builders/get-started/quick-start/){target=\_blank} [Moonbeam](https://moonbeam.network/){target=\_blank} is another project that is planning to deploy to Polkadot as a parachain and will support Ethereum compatible smart contracts. Since Moonbeam uses [Frontier](https://github.com/paritytech/frontier){target=\_blank}, an interoperability layer with existing Ethereum -tooling, it will support all applications that are written to target the EVM environment with little +tooling, supports all applications that are written to target the EVM environment with little friction. [Moonriver](https://docs.moonbeam.network/networks/moonriver/){target=\_blank}, a companion network to Moonbeam, @@ -107,12 +99,8 @@ Try deploying a smart contract to Moonbeam by following their [documentation](ht - ink!/Wasm: [**Supported**](https://docs.astar.network/docs/build/#wasm-smart-contracts){target=\_blank} - EVM (Solidity): [ **Supported**](https://docs.astar.network/docs/build/#evm-smart-contracts){target=\_blank} -[Astar Network](https://astar.network/){target=\_blank} supports the building of dApps with EVM and Wasm smart -contracts and offers developers true interoperability. True interoperability with cross-consensus -messaging [XCM](https://wiki.polkadot.network/docs/learn-xcm){target=\_blank} and cross-virtual machine -[XVM](https://github.com/AstarNetwork/){target=\_blank}. We are made by developers and for developers. Astar’s -unique Build2Earn model empowers developers to get paid through a dApp staking mechanism for the -code they write and dApps they build. +[Astar Network](https://astar.network/){target=\_blank} supports the building of dApps with EVM and Wasm smart contracts and offers developers true interoperability. True interoperability with cross-consensus messaging [XCM](https://wiki.polkadot.network/docs/learn-xcm){target=\_blank} and cross-virtual machine [XVM](https://astar.network/developers){target=\_blank}. We are made by developers and for developers. Astar’s +unique Build2Earn model empowers developers to get paid through a dApp staking mechanism for the code they write and dApps they build. [Shiden Network](https://shiden.astar.network/){target=\_blank} is the canary network of Astar Network, live as a parachain on Kusama, and supports the EVM and Wasm environment for all developers who want to build @@ -139,11 +127,9 @@ Try deploying an Acala EVM smart contract by following their [documentation](htt - ink!: **Unsupported** - EVM (Solidity): **Unsupported** -- See: [**Phat Contracts** / **AI Agent Contracts**](https://phala.network/phat-contractt){target=\_blank} +- See: [**Phat Contracts** / **AI Agent Contracts**](https://phala.network/phat-contract){target=\_blank} -[Phala](https://phala.network){target=\_blank} is an off-chain trustless compute infrastructure that provides fully -verifiable computation. [Khala](https://phala.network/en/khala){target=\_blank} is Phala's canary network and is live as a parachain on -Kusama. +[Phala](https://phala.network){target=\_blank} is an off-chain trustless compute infrastructure that provides fully verifiable computation. [Khala](https://phala.network/en/khala){target=\_blank} is Phala's canary network and is live as a parachain on Kusama. Try deploying a smart contract that interacts with Etherscan's web2 API by following their [documentation](https://docs.phala.network/ai-agent-contract/build){target=\_blank}. From aee01728f89bd5f6965b66f036792441166dfb2e Mon Sep 17 00:00:00 2001 From: bader y Date: Mon, 7 Oct 2024 16:00:37 -0400 Subject: [PATCH 08/15] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolás Hussein <80422357+nhussein11@users.noreply.github.com> Co-authored-by: 0xLucca <95830307+0xLucca@users.noreply.github.com> --- .../smart-contracts/smart-contracts.md | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index 7c81d01ee..5960f4c83 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -28,7 +28,7 @@ The concept of *gas*, or *fees* in general, also are approached differently betw ## Building a Smart Contract -The relay chain doesn't natively support smart contracts. However, since the parachains that connect to can support arbitrary state transitions, they support smart contracts. +The relay chain doesn't support smart contracts natively. However, since the parachains that connect to it can support arbitrary state transitions, they can also support smart contracts. The Polkadot SDK presently supports smart contracts out-of-the-box in several ways: @@ -51,14 +51,9 @@ The contracts pallet (`pallet_contracts`) implements a Wasm based approach to sm have a dedicated domain-specific language, and for that reason Parity offers the [ink!](#ink) language. -2. **Deposit**. Contracts must hold a deposit (named _ContractDeposit_ ) suitably large enough in - order to justify their existence on-chain. The developer needs to deposit this into the new contract - on top of the _ExistentialDeposit_. +2. **Deposit** - contracts must hold a deposit (named `_ContractDeposit_` ) suitably large enough to justify their existence on-chain. The developer must deposit this into the new contract on top of the `_ExistentialDeposit_` -3. **Caching**. Contracts are cached by default and therefore means they only need to be deployed - once and afterward be instantiated as many times as you want. This helps to keep the storage load - on the chain down to the minimum. On top of this, when a contract is no longer being used and the - _existential deposit_ is drained, the code will be erased from storage (known as reaping). +3. **Caching** - contracts are cached by default, and therefore means they only need to be deployed once and afterward be instantiated as many times as you want. This helps keep the chain's storage load down to the minimum. On top of this, when a contract is no longer being used and the `_existential deposit_` is drained, the code will be erased from storage (known as reaping) ### Ink @@ -67,8 +62,8 @@ The contracts pallet (`pallet_contracts`) implements a Wasm based approach to sm Here is the list of current resources available to developers who want to get started writing smart contracts to deploy on parachains based on Substrate. - [ink!](https://use.ink/){target=\_blank} - Polkadot's "native" smart contract stack, based on Wasm -- [OpenBrush](https://docs.openbrush.io/){target=\_blank}: an `ink!` library providing standard contracts based on [PSP](https://github.com/w3f/PSPs){target=\_blank} with useful contracts and macros for building -- [ink!athon](https://inkathon.xyz/){target=\_blank}: Starter kit for full-stack dApps with ink! smart contracts and frontend +- [OpenBrush](https://docs.openbrush.io/){target=\_blank} - an `ink!` library providing standard contracts based on [PSP](https://github.com/w3f/PSPs){target=\_blank} with useful contracts and macros for building +- [ink!athon](https://inkathon.xyz/){target=\_blank} - starter kit for full-stack dApps with ink! smart contracts and frontend ink! has laid much of the groundwork for a new smart contract stack that is based on a Wasm virtual machine and compatible with Polkadot SDK-based chains. @@ -96,8 +91,8 @@ Try deploying a smart contract to Moonbeam by following their [documentation](ht #### Astar -- ink!/Wasm: [**Supported**](https://docs.astar.network/docs/build/#wasm-smart-contracts){target=\_blank} -- EVM (Solidity): [ **Supported**](https://docs.astar.network/docs/build/#evm-smart-contracts){target=\_blank} +- ink! - [**Supported**](https://docs.astar.network/docs/build/#wasm-smart-contracts){target=\_blank} +- EVM (Solidity) - [ **Supported**](https://docs.astar.network/docs/build/#evm-smart-contracts){target=\_blank} [Astar Network](https://astar.network/){target=\_blank} supports the building of dApps with EVM and Wasm smart contracts and offers developers true interoperability. True interoperability with cross-consensus messaging [XCM](https://wiki.polkadot.network/docs/learn-xcm){target=\_blank} and cross-virtual machine [XVM](https://astar.network/developers){target=\_blank}. We are made by developers and for developers. Astar’s unique Build2Earn model empowers developers to get paid through a dApp staking mechanism for the code they write and dApps they build. @@ -111,8 +106,8 @@ Try deploying an Ethereum or ink! smart contract by following their #### Acala -- ink!: **Unsupported** -- EVM (Solidity): [**Supported**](https://wiki.acala.network/build/development-guide){target=\_blank} +- ink! - **Unsupported** +- EVM (Solidity) - [**Supported**](https://wiki.acala.network/build/development-guide){target=\_blank} [Acala](https://acala.network/){target=\_blank} is a decentralized finance consortium and DeFi infrastructure chain delivering a set of protocols to serve as the DeFi hub on Polkadot. @@ -136,9 +131,8 @@ Try deploying a smart contract that interacts with Etherscan's web2 API by follo #### Darwinia -- ink!: **Unsupported** -- EVM (Solidity) Support: - [**Supported**](https://docs.darwinia.network/build/getting-started/networks/overview/){target=\_blank} +- ink! - **Unsupported** +- EVM (Solidity) - [**Supported**](https://docs.darwinia.network/build/getting-started/networks/overview/){target=\_blank} [Darwinia](https://darwinia.network/){target=\_blank} is a community-run technology and service powering the cross-chain capabilities of decentralized applications. By crafting secure and efficient cross-chain From 8f0b039889be38ff661b1bffc5e024b7c7ba0bb6 Mon Sep 17 00:00:00 2001 From: Bader Youssef Date: Mon, 7 Oct 2024 16:17:04 -0400 Subject: [PATCH 09/15] improvements to writing --- .../smart-contracts/smart-contracts.md | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index 5960f4c83..783e6b9b4 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -10,17 +10,13 @@ The two primary supported smart contract environments are [ink!](#ink) and EVM. ## Developing a Smart Contract Versus a Parachain !!!info "For a more technical/thorough breakdown, refer to the [`polkadot_sdk_docs`](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/runtime_vs_smart_contract/index.html){target=\_blank}" + [When should one build a Substrate (Polkadot SDK) runtime versus a Substrate (Polkadot SDK) smart contract](https://stackoverflow.com/a/56041305){target=\_blank}? This post also answers the question more technically of when a developer might choose to develop a runtime versus a smart contract. -[When should one build a Substrate (Polkadot SDK) runtime versus a Substrate (Polkadot SDK) smart contract](https://stackoverflow.com/a/56041305){target=\_blank}? This post also answers the question more technically of when a developer might choose to develop a runtime versus a smart contract. +### Pallets vs. Smart Contracts -### Layer of Abstraction +When you write a smart contract, you are creating a sandboxed program that contains instructions that associate with and deploy on a specific chain address. Pallets, which are modules that make up the core business logic of a Wasm runtime, run directly as part of the blockchain. Pallets can either be domain specific or they can be something critical, like block production. -When you write a smart contract, you are creating the instructions that associate with and deploy on -a specific chain address. - -In comparison, a runtime module on a parachain is the entire logic of a chain's state transitions (what's called a state transition function). - -Smart contracts must consciously implement a path to upgrading in the future, while parachains have the ability to swap out their code through a forkless upgrade. +Smart contracts must consciously implement a path to upgrading in the future, while parachains have the ability to swap out their code through a forkless upgrade. Pallets can be added, removed, or modified in a forkless upgrade. When you build a smart contract, it will eventually be deployed to a target chain with its own environment. Parachains allow the developer to declare the environment of their own chain, even allowing others to write smart contracts for it. @@ -46,10 +42,7 @@ The Polkadot SDK presently supports smart contracts out-of-the-box in several wa The contracts pallet (`pallet_contracts`) implements a Wasm based approach to smart contracts. -1. **Wasm**. The contracts pallet uses Wasm as its compilation target. Any language that - compiles to Wasm can potentially be used to write smart contracts. Nevertheless, it is better to - have a dedicated domain-specific language, and for that reason Parity offers the [ink!](#ink) - language. +1. **Wasm**. The contracts pallet uses Wasm as its compilation target. Any language that compiles to Wasm can potentially be used to write smart contracts. Nevertheless, it is better to have a dedicated domain-specific language, and for that reason Parity offers the [ink!](#ink) language. 2. **Deposit** - contracts must hold a deposit (named `_ContractDeposit_` ) suitably large enough to justify their existence on-chain. The developer must deposit this into the new contract on top of the `_ExistentialDeposit_` From cb8d7686e6348ecb22f42c3dd4eba371bbb7d146 Mon Sep 17 00:00:00 2001 From: Bader Youssef Date: Mon, 7 Oct 2024 17:22:33 -0400 Subject: [PATCH 10/15] more content fixes --- .../smart-contracts/smart-contracts.md | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index 783e6b9b4..fb76a4d24 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -69,16 +69,10 @@ Many smart contract platforms are building to become a parachain in the ecosyste - ink!: **Unsupported** - EVM (Solidity): [**Supported**](https://docs.moonbeam.network/builders/get-started/quick-start/){target=\_blank} -[Moonbeam](https://moonbeam.network/){target=\_blank} is another project that is planning to deploy to Polkadot as a -parachain and will support Ethereum compatible smart contracts. Since Moonbeam uses -[Frontier](https://github.com/paritytech/frontier){target=\_blank}, an interoperability layer with existing Ethereum -tooling, supports all applications that are written to target the EVM environment with little -friction. +[Moonbeam](https://moonbeam.network/){target=\_blank} is a Polkadot parachain that supports Ethereum compatible smart contracts. Since Moonbeam uses [Frontier](https://github.com/paritytech/frontier){target=\_blank}, an interoperability layer with existing Ethereum tooling, it supports all applications that are written to target the EVM environment with little friction. [Moonriver](https://docs.moonbeam.network/networks/moonriver/){target=\_blank}, a companion network to Moonbeam, -launched as a parachain on Kusama. Parachain functionality is live, and features are being -incrementally released. The final phase of the launch will include EVM functionality and balance -transfers. +launched as a parachain on Kusama. Try deploying a smart contract to Moonbeam by following their [documentation](https://docs.moonbeam.network/){target=\_blank}. @@ -87,12 +81,9 @@ Try deploying a smart contract to Moonbeam by following their [documentation](ht - ink! - [**Supported**](https://docs.astar.network/docs/build/#wasm-smart-contracts){target=\_blank} - EVM (Solidity) - [ **Supported**](https://docs.astar.network/docs/build/#evm-smart-contracts){target=\_blank} -[Astar Network](https://astar.network/){target=\_blank} supports the building of dApps with EVM and Wasm smart contracts and offers developers true interoperability. True interoperability with cross-consensus messaging [XCM](https://wiki.polkadot.network/docs/learn-xcm){target=\_blank} and cross-virtual machine [XVM](https://astar.network/developers){target=\_blank}. We are made by developers and for developers. Astar’s -unique Build2Earn model empowers developers to get paid through a dApp staking mechanism for the code they write and dApps they build. +[Astar Network](https://astar.network/){target=\_blank} supports the building of dApps with EVM and Wasm smart contracts and offers developers true interoperability. True interoperability with cross-consensus messaging [XCM](https://wiki.polkadot.network/docs/learn-xcm){target=\_blank} and cross-virtual machine [XVM](https://astar.network/developers){target=\_blank}.Astar’s unique [Build2Earn](https://docs.astar.network/docs/build/#build2earn){target=\_blank} model empowers developers to get paid through a dApp staking mechanism for the code they write and dApps they build. -[Shiden Network](https://shiden.astar.network/){target=\_blank} is the canary network of Astar Network, live as a -parachain on Kusama, and supports the EVM and Wasm environment for all developers who want to build -out use-cases in a canary network with economic value. Shiden acts as a playground for developers. +[Shiden Network](https://shiden.astar.network/){target=\_blank} is the canary network of Astar Network, live as a parachain on Kusama, and supports the EVM and Wasm environment for all developers who want to build out use-cases in a canary network with economic value. Shiden acts as a playground for developers. Try deploying an Ethereum or ink! smart contract by following their [documentation](https://docs.astar.network/){target=\_blank}. @@ -105,9 +96,7 @@ Try deploying an Ethereum or ink! smart contract by following their [Acala](https://acala.network/){target=\_blank} is a decentralized finance consortium and DeFi infrastructure chain delivering a set of protocols to serve as the DeFi hub on Polkadot. -[Karura](https://acala.network/karura){target=\_blank}, Acala's canary network is live as a parachain on Kusama. -Interested teams are now able to deploy DApps and smart contracts on Karura's platform. Acala is -also implementing the [Acala EVM](https://wiki.acala.network/learn/acala-evm/why-acala-evm){target=\_blank}. +[Karura](https://acala.network/karura){target=\_blank}, Acala's canary network is live as a parachain on Kusama. Interested teams are now able to deploy DApps and smart contracts on Karura's platform. Acala is also implementing the [Acala EVM](https://wiki.acala.network/learn/acala-evm/why-acala-evm){target=\_blank}. Try deploying an Acala EVM smart contract by following their [documentation](https://wiki.acala.network/build/development-guide/smart-contracts){target=\_blank}. From 12198f8c6ca353e04cb1a411a6424374da871a44 Mon Sep 17 00:00:00 2001 From: Bader Youssef Date: Mon, 7 Oct 2024 17:25:13 -0400 Subject: [PATCH 11/15] slight vale --- develop/application-devs/smart-contracts/smart-contracts.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index fb76a4d24..f33eaca61 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -14,9 +14,9 @@ The two primary supported smart contract environments are [ink!](#ink) and EVM. ### Pallets vs. Smart Contracts -When you write a smart contract, you are creating a sandboxed program that contains instructions that associate with and deploy on a specific chain address. Pallets, which are modules that make up the core business logic of a Wasm runtime, run directly as part of the blockchain. Pallets can either be domain specific or they can be something critical, like block production. +When you write a smart contract, you are creating a sandboxed program that contains instructions that associate with and deploy on a specific chain address. Pallets, which are modules that make up the core business logic of a Wasm runtime, run directly as part of the blockchain. Pallets can either be domain specific or they can be something critical, like block production. -Smart contracts must consciously implement a path to upgrading in the future, while parachains have the ability to swap out their code through a forkless upgrade. Pallets can be added, removed, or modified in a forkless upgrade. +Smart contracts must consciously implement a path to upgrading in the future, while parachains have the ability to swap out their code through a forkless upgrade. Pallets can be added, removed, or modified in a forkless upgrade. When you build a smart contract, it will eventually be deployed to a target chain with its own environment. Parachains allow the developer to declare the environment of their own chain, even allowing others to write smart contracts for it. From 79024f3a6e9e3cce328329aa487300d76a226e1a Mon Sep 17 00:00:00 2001 From: 0xLucca <95830307+0xLucca@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:06:05 -0300 Subject: [PATCH 12/15] Apply suggestions from code review --- .../smart-contracts/smart-contracts.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index f33eaca61..0d68493cb 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -40,9 +40,9 @@ The Polkadot SDK presently supports smart contracts out-of-the-box in several wa ### Contracts Pallet -The contracts pallet (`pallet_contracts`) implements a Wasm based approach to smart contracts. +The contracts pallet ([`pallet_contracts`](https://docs.rs/pallet-contracts/latest/pallet_contracts/index.html#contracts-pallet){target=\_blank}) implements a Wasm based approach to smart contracts. -1. **Wasm**. The contracts pallet uses Wasm as its compilation target. Any language that compiles to Wasm can potentially be used to write smart contracts. Nevertheless, it is better to have a dedicated domain-specific language, and for that reason Parity offers the [ink!](#ink) language. +1. **Wasm** - the contracts pallet uses Wasm as its compilation target. Any language that compiles to Wasm can potentially be used to write smart contracts. Nevertheless, it is better to have a dedicated domain-specific language, and for that reason Parity offers the [ink!](#ink) language 2. **Deposit** - contracts must hold a deposit (named `_ContractDeposit_` ) suitably large enough to justify their existence on-chain. The developer must deposit this into the new contract on top of the `_ExistentialDeposit_` @@ -66,8 +66,8 @@ Many smart contract platforms are building to become a parachain in the ecosyste #### Moonbeam -- ink!: **Unsupported** -- EVM (Solidity): [**Supported**](https://docs.moonbeam.network/builders/get-started/quick-start/){target=\_blank} +- ink! - **Unsupported** +- EVM (Solidity) - [**Supported**](https://docs.moonbeam.network/builders/get-started/quick-start/){target=\_blank} [Moonbeam](https://moonbeam.network/){target=\_blank} is a Polkadot parachain that supports Ethereum compatible smart contracts. Since Moonbeam uses [Frontier](https://github.com/paritytech/frontier){target=\_blank}, an interoperability layer with existing Ethereum tooling, it supports all applications that are written to target the EVM environment with little friction. @@ -102,9 +102,9 @@ Try deploying an Acala EVM smart contract by following their [documentation](htt #### Phala -- ink!: **Unsupported** -- EVM (Solidity): **Unsupported** -- See: [**Phat Contracts** / **AI Agent Contracts**](https://phala.network/phat-contract){target=\_blank} +- ink! - **Unsupported** +- EVM (Solidity) - **Unsupported** +- See - [**Phat Contracts** / **AI Agent Contracts**](https://phala.network/phat-contract){target=\_blank} [Phala](https://phala.network){target=\_blank} is an off-chain trustless compute infrastructure that provides fully verifiable computation. [Khala](https://phala.network/en/khala){target=\_blank} is Phala's canary network and is live as a parachain on Kusama. From 56c6c1be5bc535768310bcff2fb13f7c86d72a77 Mon Sep 17 00:00:00 2001 From: DAWN KELLY Date: Fri, 11 Oct 2024 14:39:22 -0400 Subject: [PATCH 13/15] formatting review, edits made --- .../application-devs/smart-contracts/.pages | 2 +- .../smart-contracts/smart-contracts.md | 49 ++++++++++--------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/develop/application-devs/smart-contracts/.pages b/develop/application-devs/smart-contracts/.pages index 5ccdc9a69..3a34b03c7 100644 --- a/develop/application-devs/smart-contracts/.pages +++ b/develop/application-devs/smart-contracts/.pages @@ -1,4 +1,4 @@ title: Smart Contract Development nav: - index.md - - smart-contracts.md + - 'Smart Contracts': smart-contracts.md diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index 0d68493cb..832cac80c 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -3,30 +3,31 @@ title: Smart Contracts description: Learn how to navigate the smart contract aspect of the Polkadot ecosystem, including available languages (Solidity, ink), platforms, and compilation targets. --- -Polkadot doesn't support smart contracts natively. Rather, parachains secured by Polkadot are equipped with the functionality to support smart contracts. +# Smart Contracts -The two primary supported smart contract environments are [ink!](#ink) and EVM. There are multiple [parachains that support both environments](#smart-contract-environments). +## Introduction -## Developing a Smart Contract Versus a Parachain +Polkadot's unique multi-chain ecosystem allows parachains to support smart contracts, even though the relay chain itself does not. Developers can build decentralized applications using both [ink!](#ink), a Rust-based language for Wasm, and the Solidity-based Ethereum Virtual Machine (EVM) smart contract environments. Multiple [parachains that support both environments](#smart-contract-environments) are available. -!!!info "For a more technical/thorough breakdown, refer to the [`polkadot_sdk_docs`](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/runtime_vs_smart_contract/index.html){target=\_blank}" - [When should one build a Substrate (Polkadot SDK) runtime versus a Substrate (Polkadot SDK) smart contract](https://stackoverflow.com/a/56041305){target=\_blank}? This post also answers the question more technically of when a developer might choose to develop a runtime versus a smart contract. +This guide explores key differences between developing smart contracts and parachains, details the available platforms and supported languages, and outlines best practices for building smart contracts within Polkadot's scalable and interoperable framework. -### Pallets vs. Smart Contracts +## Smart Contracts Versus Pallets -When you write a smart contract, you are creating a sandboxed program that contains instructions that associate with and deploy on a specific chain address. Pallets, which are modules that make up the core business logic of a Wasm runtime, run directly as part of the blockchain. Pallets can either be domain specific or they can be something critical, like block production. +When developing a smart contract, you create a sandboxed program that executes specific logic associated with a chain address. Unlike pallets, which integrate directly into a blockchain's runtime and define its core logic, smart contracts operate independently in a more isolated environment. Pallets can manage critical tasks like block production or governance and can be added, modified, or removed through forkless runtime upgrades. -Smart contracts must consciously implement a path to upgrading in the future, while parachains have the ability to swap out their code through a forkless upgrade. Pallets can be added, removed, or modified in a forkless upgrade. +Smart contracts, on the other hand, require careful upgrade planning, as their functionality can't be updated without explicitly coding mechanisms for future changes. Parachains offer flexibility, allowing developers to define the environment where these contracts run and enabling others to build on it. -When you build a smart contract, it will eventually be deployed to a target chain with its own environment. Parachains allow the developer to declare the environment of their own chain, even allowing others to write smart contracts for it. +These two options also differ in how they handle fees. Smart contracts follow a gas metering model for execution costs, while pallets and runtimes offer more flexible options for fee models. -The concept of *gas*, or *fees* in general, also are approached differently between the two. Smart contracts are bound by the gas-metering model, whereas runtimes (and their subsequent modules) are much more flexible in terms of the fee models that can be employed. +!!!info "Additional information" + - Refer to 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 Rustdocs + - This post answers the question of when a developer might choose to develop a runtime versus a smart contract with more technical depth: [When should one build a Substrate (Polkadot SDK) runtime versus a Substrate (Polkadot SDK) smart contract?](https://stackoverflow.com/a/56041305){target=\_blank} ## Building a Smart Contract -The relay chain doesn't support smart contracts natively. However, since the parachains that connect to it can support arbitrary state transitions, they can also support smart contracts. +Remember, the relay chain doesn't support smart contracts natively. However, since the parachains that connect to it support arbitrary state transitions, they also support smart contracts. -The Polkadot SDK presently supports smart contracts out-of-the-box in several ways: +The Polkadot SDK presently supports smart contracts out-of-the-box in multiple ways: - The EVM pallet offered by [Frontier](https://github.com/paritytech/frontier){target=\_blank} - The [contracts pallet](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/contracts/){target=\_blank} in the FRAME library for Wasm-based contracts @@ -42,17 +43,17 @@ The Polkadot SDK presently supports smart contracts out-of-the-box in several wa The contracts pallet ([`pallet_contracts`](https://docs.rs/pallet-contracts/latest/pallet_contracts/index.html#contracts-pallet){target=\_blank}) implements a Wasm based approach to smart contracts. -1. **Wasm** - the contracts pallet uses Wasm as its compilation target. Any language that compiles to Wasm can potentially be used to write smart contracts. Nevertheless, it is better to have a dedicated domain-specific language, and for that reason Parity offers the [ink!](#ink) language +1. **Wasm** - the contracts pallet uses Wasm as its compilation target. Any language that compiles to Wasm could be used to write smart contracts. Nevertheless, it is better to have a dedicated domain-specific language, so Parity offers the [ink!](#ink) language 2. **Deposit** - contracts must hold a deposit (named `_ContractDeposit_` ) suitably large enough to justify their existence on-chain. The developer must deposit this into the new contract on top of the `_ExistentialDeposit_` -3. **Caching** - contracts are cached by default, and therefore means they only need to be deployed once and afterward be instantiated as many times as you want. This helps keep the chain's storage load down to the minimum. On top of this, when a contract is no longer being used and the `_existential deposit_` is drained, the code will be erased from storage (known as reaping) +3. **Caching** - contracts are cached by default, which means they only need to be deployed once and can be instantiated as many times as you want afterward. Caching helps minimize on-chain storage requirements. Additionally, contracts that are no longer in use and have an `_ExistentialDeposit_` balance of zero are erased from storage in a process called reaping ### Ink -[ink!](https://github.com/use-ink/ink){target=\_blank} is a domain specific language for writing smart contracts in Rust and compiles to Wasm code. +[ink!](https://github.com/use-ink/ink){target=\_blank} is a domain-specific language for writing smart contracts in Rust and compiles to Wasm code. -Here is the list of current resources available to developers who want to get started writing smart contracts to deploy on parachains based on Substrate. +Additional resources available to developers who want to start writing smart contracts to deploy on Polkadot SDK-based parachains: - [ink!](https://use.ink/){target=\_blank} - Polkadot's "native" smart contract stack, based on Wasm - [OpenBrush](https://docs.openbrush.io/){target=\_blank} - an `ink!` library providing standard contracts based on [PSP](https://github.com/w3f/PSPs){target=\_blank} with useful contracts and macros for building @@ -62,33 +63,33 @@ ink! has laid much of the groundwork for a new smart contract stack that is base ## Smart Contract Environments -Many smart contract platforms are building to become a parachain in the ecosystem. A community created and maintained list of different smart contract platforms can be found at [PolkaProjects](https://www.polkaproject.com/#/projects?cateID=1&tagID=6){target=\_blank}. Additionally, information about ink smart contracts can be accessed at [use.ink](https://use.ink/#where-can-i-deploy-ink-contracts){target=\_blank}. +Many smart contract platforms are building to become a parachain in the ecosystem. A community-created and maintained list of different smart contract platforms can be found at [PolkaProjects](https://www.polkaproject.com/#/projects?cateID=1&tagID=6){target=\_blank}. Additionally, information about ink smart contracts can be accessed at [use.ink](https://use.ink/#where-can-i-deploy-ink-contracts){target=\_blank}. -#### Moonbeam +### Moonbeam - ink! - **Unsupported** - EVM (Solidity) - [**Supported**](https://docs.moonbeam.network/builders/get-started/quick-start/){target=\_blank} -[Moonbeam](https://moonbeam.network/){target=\_blank} is a Polkadot parachain that supports Ethereum compatible smart contracts. Since Moonbeam uses [Frontier](https://github.com/paritytech/frontier){target=\_blank}, an interoperability layer with existing Ethereum tooling, it supports all applications that are written to target the EVM environment with little friction. +[Moonbeam](https://moonbeam.network/){target=\_blank} is a Polkadot parachain that supports Ethereum-compatible smart contracts. Since Moonbeam uses [Frontier](https://github.com/paritytech/frontier){target=\_blank}, an interoperability layer with existing Ethereum tooling, it supports all applications that are written to target the EVM environment with little friction. [Moonriver](https://docs.moonbeam.network/networks/moonriver/){target=\_blank}, a companion network to Moonbeam, launched as a parachain on Kusama. Try deploying a smart contract to Moonbeam by following their [documentation](https://docs.moonbeam.network/){target=\_blank}. -#### Astar +### Astar - ink! - [**Supported**](https://docs.astar.network/docs/build/#wasm-smart-contracts){target=\_blank} - EVM (Solidity) - [ **Supported**](https://docs.astar.network/docs/build/#evm-smart-contracts){target=\_blank} -[Astar Network](https://astar.network/){target=\_blank} supports the building of dApps with EVM and Wasm smart contracts and offers developers true interoperability. True interoperability with cross-consensus messaging [XCM](https://wiki.polkadot.network/docs/learn-xcm){target=\_blank} and cross-virtual machine [XVM](https://astar.network/developers){target=\_blank}.Astar’s unique [Build2Earn](https://docs.astar.network/docs/build/#build2earn){target=\_blank} model empowers developers to get paid through a dApp staking mechanism for the code they write and dApps they build. +[Astar Network](https://astar.network/){target=\_blank} supports the building of dApps with EVM and Wasm smart contracts and offers developers true interoperability. True interoperability with cross-consensus messaging [XCM](https://wiki.polkadot.network/docs/learn-xcm){target=\_blank} and cross-virtual machine [XVM](https://astar.network/developers){target=\_blank}.Astar's unique [Build2Earn](https://docs.astar.network/docs/build/#build2earn){target=\_blank} model empowers developers to get paid through a dApp staking mechanism for the code they write and dApps they build. [Shiden Network](https://shiden.astar.network/){target=\_blank} is the canary network of Astar Network, live as a parachain on Kusama, and supports the EVM and Wasm environment for all developers who want to build out use-cases in a canary network with economic value. Shiden acts as a playground for developers. Try deploying an Ethereum or ink! smart contract by following their [documentation](https://docs.astar.network/){target=\_blank}. -#### Acala +### Acala - ink! - **Unsupported** - EVM (Solidity) - [**Supported**](https://wiki.acala.network/build/development-guide){target=\_blank} @@ -100,7 +101,7 @@ delivering a set of protocols to serve as the DeFi hub on Polkadot. Try deploying an Acala EVM smart contract by following their [documentation](https://wiki.acala.network/build/development-guide/smart-contracts){target=\_blank}. -#### Phala +### Phala - ink! - **Unsupported** - EVM (Solidity) - **Unsupported** @@ -111,7 +112,7 @@ Try deploying an Acala EVM smart contract by following their [documentation](htt Try deploying a smart contract that interacts with Etherscan's web2 API by following their [documentation](https://docs.phala.network/ai-agent-contract/build){target=\_blank}. -#### Darwinia +### Darwinia - ink! - **Unsupported** - EVM (Solidity) - [**Supported**](https://docs.darwinia.network/build/getting-started/networks/overview/){target=\_blank} From 67f3d01cac2640c780a21865b7f4978e3bd416db Mon Sep 17 00:00:00 2001 From: Dawn Kelly <83190195+dawnkelly09@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:08:59 -0400 Subject: [PATCH 14/15] Apply suggestions from code review Co-authored-by: Erin Shaben --- .../smart-contracts/smart-contracts.md | 64 ++++++++----------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index 832cac80c..0612e1faa 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -20,8 +20,8 @@ Smart contracts, on the other hand, require careful upgrade planning, as their f These two options also differ in how they handle fees. Smart contracts follow a gas metering model for execution costs, while pallets and runtimes offer more flexible options for fee models. !!!info "Additional information" - - Refer to 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 Rustdocs - - This post answers the question of when a developer might choose to develop a runtime versus a smart contract with more technical depth: [When should one build a Substrate (Polkadot SDK) runtime versus a Substrate (Polkadot SDK) smart contract?](https://stackoverflow.com/a/56041305){target=\_blank} + - Refer to 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 + - A Stack Overflow post answers the question of when a developer might choose to develop a runtime versus a smart contract with more technical depth: [When should one build a Substrate (Polkadot SDK) runtime versus a Substrate (Polkadot SDK) smart contract?](https://stackoverflow.com/a/56041305){target=\_blank} ## Building a Smart Contract @@ -30,18 +30,18 @@ Remember, the relay chain doesn't support smart contracts natively. However, sin The Polkadot SDK presently supports smart contracts out-of-the-box in multiple ways: - The EVM pallet offered by [Frontier](https://github.com/paritytech/frontier){target=\_blank} -- The [contracts pallet](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/contracts/){target=\_blank} in the FRAME library for Wasm-based contracts +- The [Contracts pallet](https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/contracts/){target=\_blank} in the FRAME library for Wasm-based contracts ### Frontier EVM Contracts [Frontier](https://github.com/paritytech/frontier) is the suite of tools that enables a Polkadot SDK-based chain to run Ethereum contracts (EVM) natively with the same API/RPC interface. Ethereum addresses can also be mapped directly to and from the Polkadot SDK's SS58 scheme from existing accounts. -- [Pallet EVM](https://docs.rs/pallet-evm/latest/pallet_evm/){target=\_blank} - enables functionality of running EVM (Solidity) contracts -- [Pallet Ethereum](https://docs.rs/pallet-ethereum/latest/pallet_ethereum/){target=\_blank} - Ethereum RPC implementation, block emulation, and Ethereum transaction validation +- [**Pallet EVM**](https://docs.rs/pallet-evm/latest/pallet_evm/){target=\_blank} - enables functionality of running EVM (Solidity) contracts +- [**Pallet Ethereum**](https://docs.rs/pallet-ethereum/latest/pallet_ethereum/){target=\_blank} - Ethereum RPC implementation, block emulation, and Ethereum transaction validation ### Contracts Pallet -The contracts pallet ([`pallet_contracts`](https://docs.rs/pallet-contracts/latest/pallet_contracts/index.html#contracts-pallet){target=\_blank}) implements a Wasm based approach to smart contracts. +The Contracts pallet ([`pallet_contracts`](https://docs.rs/pallet-contracts/latest/pallet_contracts/index.html#contracts-pallet){target=\_blank}) implements a Wasm-based approach to smart contracts. 1. **Wasm** - the contracts pallet uses Wasm as its compilation target. Any language that compiles to Wasm could be used to write smart contracts. Nevertheless, it is better to have a dedicated domain-specific language, so Parity offers the [ink!](#ink) language @@ -49,53 +49,50 @@ The contracts pallet ([`pallet_contracts`](https://docs.rs/pallet-contracts/late 3. **Caching** - contracts are cached by default, which means they only need to be deployed once and can be instantiated as many times as you want afterward. Caching helps minimize on-chain storage requirements. Additionally, contracts that are no longer in use and have an `_ExistentialDeposit_` balance of zero are erased from storage in a process called reaping -### Ink +### ink! [ink!](https://github.com/use-ink/ink){target=\_blank} is a domain-specific language for writing smart contracts in Rust and compiles to Wasm code. Additional resources available to developers who want to start writing smart contracts to deploy on Polkadot SDK-based parachains: -- [ink!](https://use.ink/){target=\_blank} - Polkadot's "native" smart contract stack, based on Wasm -- [OpenBrush](https://docs.openbrush.io/){target=\_blank} - an `ink!` library providing standard contracts based on [PSP](https://github.com/w3f/PSPs){target=\_blank} with useful contracts and macros for building -- [ink!athon](https://inkathon.xyz/){target=\_blank} - starter kit for full-stack dApps with ink! smart contracts and frontend +- [**ink!**](https://use.ink/){target=\_blank} - Polkadot's "native" smart contract stack, based on Wasm +- [**OpenBrush**](https://docs.openbrush.io/){target=\_blank} - an `ink!` library providing standard contracts based on [PSP](https://github.com/w3f/PSPs){target=\_blank} with useful contracts and macros for building +- [**ink!athon**](https://inkathon.xyz/){target=\_blank} - starter kit for full-stack dApps with ink! smart contracts and frontend ink! has laid much of the groundwork for a new smart contract stack that is based on a Wasm virtual machine and compatible with Polkadot SDK-based chains. ## Smart Contract Environments -Many smart contract platforms are building to become a parachain in the ecosystem. A community-created and maintained list of different smart contract platforms can be found at [PolkaProjects](https://www.polkaproject.com/#/projects?cateID=1&tagID=6){target=\_blank}. Additionally, information about ink smart contracts can be accessed at [use.ink](https://use.ink/#where-can-i-deploy-ink-contracts){target=\_blank}. +Many smart contract platforms are building to become a parachain in the ecosystem. A community-created and maintained list of different smart contract platforms can be found at [PolkaProjects](https://www.polkaproject.com/#/projects?cateID=1&tagID=6){target=\_blank}. Additionally, information about ink! smart contracts can be accessed at [use.ink](https://use.ink/#where-can-i-deploy-ink-contracts){target=\_blank}. ### Moonbeam -- ink! - **Unsupported** -- EVM (Solidity) - [**Supported**](https://docs.moonbeam.network/builders/get-started/quick-start/){target=\_blank} +- **ink!**- unsupported +- **EVM (Solidity)** - [supported](https://docs.moonbeam.network/builders/get-started/quick-start/){target=\_blank} [Moonbeam](https://moonbeam.network/){target=\_blank} is a Polkadot parachain that supports Ethereum-compatible smart contracts. Since Moonbeam uses [Frontier](https://github.com/paritytech/frontier){target=\_blank}, an interoperability layer with existing Ethereum tooling, it supports all applications that are written to target the EVM environment with little friction. -[Moonriver](https://docs.moonbeam.network/networks/moonriver/){target=\_blank}, a companion network to Moonbeam, -launched as a parachain on Kusama. +[Moonriver](https://docs.moonbeam.network/networks/moonriver/){target=\_blank}, a companion network to Moonbeam, launched as a parachain on Kusama. Try deploying a smart contract to Moonbeam by following their [documentation](https://docs.moonbeam.network/){target=\_blank}. ### Astar -- ink! - [**Supported**](https://docs.astar.network/docs/build/#wasm-smart-contracts){target=\_blank} -- EVM (Solidity) - [ **Supported**](https://docs.astar.network/docs/build/#evm-smart-contracts){target=\_blank} +- **ink!** - [supported](https://docs.astar.network/docs/build/#wasm-smart-contracts){target=\_blank} +- **EVM (Solidity)** - [supported](https://docs.astar.network/docs/build/#evm-smart-contracts){target=\_blank} [Astar Network](https://astar.network/){target=\_blank} supports the building of dApps with EVM and Wasm smart contracts and offers developers true interoperability. True interoperability with cross-consensus messaging [XCM](https://wiki.polkadot.network/docs/learn-xcm){target=\_blank} and cross-virtual machine [XVM](https://astar.network/developers){target=\_blank}.Astar's unique [Build2Earn](https://docs.astar.network/docs/build/#build2earn){target=\_blank} model empowers developers to get paid through a dApp staking mechanism for the code they write and dApps they build. [Shiden Network](https://shiden.astar.network/){target=\_blank} is the canary network of Astar Network, live as a parachain on Kusama, and supports the EVM and Wasm environment for all developers who want to build out use-cases in a canary network with economic value. Shiden acts as a playground for developers. -Try deploying an Ethereum or ink! smart contract by following their -[documentation](https://docs.astar.network/){target=\_blank}. +Try deploying an Ethereum or ink! smart contract by following their [documentation](https://docs.astar.network/){target=\_blank}. ### Acala -- ink! - **Unsupported** -- EVM (Solidity) - [**Supported**](https://wiki.acala.network/build/development-guide){target=\_blank} +- **ink!** - unsupported +- **EVM (Solidity)** - [supported](https://wiki.acala.network/build/development-guide){target=\_blank} -[Acala](https://acala.network/){target=\_blank} is a decentralized finance consortium and DeFi infrastructure chain -delivering a set of protocols to serve as the DeFi hub on Polkadot. +[Acala](https://acala.network/){target=\_blank} is a decentralized finance consortium and DeFi infrastructure chain delivering a set of protocols to serve as the DeFi hub on Polkadot. [Karura](https://acala.network/karura){target=\_blank}, Acala's canary network is live as a parachain on Kusama. Interested teams are now able to deploy DApps and smart contracts on Karura's platform. Acala is also implementing the [Acala EVM](https://wiki.acala.network/learn/acala-evm/why-acala-evm){target=\_blank}. @@ -103,26 +100,19 @@ Try deploying an Acala EVM smart contract by following their [documentation](htt ### Phala -- ink! - **Unsupported** -- EVM (Solidity) - **Unsupported** -- See - [**Phat Contracts** / **AI Agent Contracts**](https://phala.network/phat-contract){target=\_blank} +- **ink!** - unsupported +- **EVM (Solidity)** - unsupported +- **Phat Contracts** / **AI Agent Contracts** - [supported](https://phala.network/phat-contract){target=\_blank} [Phala](https://phala.network){target=\_blank} is an off-chain trustless compute infrastructure that provides fully verifiable computation. [Khala](https://phala.network/en/khala){target=\_blank} is Phala's canary network and is live as a parachain on Kusama. -Try deploying a smart contract that interacts with Etherscan's web2 API by following their -[documentation](https://docs.phala.network/ai-agent-contract/build){target=\_blank}. +Try deploying a smart contract that interacts with Etherscan's Web2 API by following their [documentation](https://docs.phala.network/ai-agent-contract/build){target=\_blank}. ### Darwinia -- ink! - **Unsupported** -- EVM (Solidity) - [**Supported**](https://docs.darwinia.network/build/getting-started/networks/overview/){target=\_blank} +- **ink!** - unsupported +- **EVM (Solidity)** - [supported](https://docs.darwinia.network/build/getting-started/networks/overview/){target=\_blank} -[Darwinia](https://darwinia.network/){target=\_blank} is a community-run technology and service powering the -cross-chain capabilities of decentralized applications. By crafting secure and efficient cross-chain -messaging protocols, Darwinia is at the forefront of facilitating seamless communication between -disparate blockchain networks. The newest addition to the suite of protocols is `Darwinia Msgport`, -an innovative messaging abstraction that has been successfully implemented across a wide array of -mainstream smart contract platforms, broadening the potential for interoperability and enabling -developers to create more versatile and connected blockchain ecosystems. +[Darwinia](https://darwinia.network/){target=\_blank} is a community-run technology and service powering the cross-chain capabilities of decentralized applications. By crafting secure and efficient cross-chain messaging protocols, Darwinia is at the forefront of facilitating seamless communication between disparate blockchain networks. The newest addition to the suite of protocols is Darwinia Msgport, an innovative messaging abstraction that has been successfully implemented across a wide array of mainstream smart contract platforms, broadening the potential for interoperability and enabling developers to create more versatile and connected blockchain ecosystems. Try deploying a smart contract to Darwinia by following their [documentation](https://docs.darwinia.network/build/ethereum-tools/interact-with-web3js/){target=\_blank}. \ No newline at end of file From 15038a072a9ac727fe6a8666e32d8937ebb240eb Mon Sep 17 00:00:00 2001 From: DAWN KELLY Date: Tue, 15 Oct 2024 13:19:16 -0400 Subject: [PATCH 15/15] edits per review feedback --- develop/application-devs/smart-contracts/smart-contracts.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/develop/application-devs/smart-contracts/smart-contracts.md b/develop/application-devs/smart-contracts/smart-contracts.md index 0612e1faa..5a6a18f06 100644 --- a/develop/application-devs/smart-contracts/smart-contracts.md +++ b/develop/application-devs/smart-contracts/smart-contracts.md @@ -21,7 +21,7 @@ These two options also differ in how they handle fees. Smart contracts follow a !!!info "Additional information" - Refer to 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 - - A Stack Overflow post answers the question of when a developer might choose to develop a runtime versus a smart contract with more technical depth: [When should one build a Substrate (Polkadot SDK) runtime versus a Substrate (Polkadot SDK) smart contract?](https://stackoverflow.com/a/56041305){target=\_blank} + - Refer to this Stack Overflow post for a technically deeper discussion of when a developer might choose to develop a runtime versus a smart contract: [When should one build a Substrate (Polkadot SDK) runtime versus a Substrate (Polkadot SDK) smart contract?](https://stackoverflow.com/a/56041305){target=\_blank} ## Building a Smart Contract @@ -45,9 +45,9 @@ The Contracts pallet ([`pallet_contracts`](https://docs.rs/pallet-contracts/late 1. **Wasm** - the contracts pallet uses Wasm as its compilation target. Any language that compiles to Wasm could be used to write smart contracts. Nevertheless, it is better to have a dedicated domain-specific language, so Parity offers the [ink!](#ink) language -2. **Deposit** - contracts must hold a deposit (named `_ContractDeposit_` ) suitably large enough to justify their existence on-chain. The developer must deposit this into the new contract on top of the `_ExistentialDeposit_` +2. **Deposit** - contracts must hold a deposit (named `ContractDeposit` ) suitably large enough to justify their existence on-chain. The developer must deposit this into the new contract on top of the `ExistentialDeposit` -3. **Caching** - contracts are cached by default, which means they only need to be deployed once and can be instantiated as many times as you want afterward. Caching helps minimize on-chain storage requirements. Additionally, contracts that are no longer in use and have an `_ExistentialDeposit_` balance of zero are erased from storage in a process called reaping +3. **Caching** - contracts are cached by default, which means they only need to be deployed once and can be instantiated as many times as you want afterward. Caching helps minimize on-chain storage requirements. Additionally, contracts that are no longer in use and have an `ExistentialDeposit` balance of zero are erased from storage in a process called reaping ### ink!