Building a Multichain Network with XVM

Our cross-virtual machine (XVM) will allow developers to build smart contracts across WASM and EVM.

Jerad | Astar
Astar Network

--

Introduction

We are constructing a multichain network that not only allows developers to build smart contracts in either Solidity or ink!, but encourages developers to build across and between EVM and WASM. The first step was to bootstrap Astar Network by creating an ecosystem of dApps built with already successful smart contracts found on other chains, yet we do not believe this is the entire solution for the long-term success of Astar or Polkadot. Instead, we are betting on WASM and multichain smart contracts. Our team is laser-focused on bringing WASM to Astar Network. Recently, we accomplished a great milestone in realizing a multichain network: using our xvm_pallet to interact EVM-to-WASM.

Inspiration for XVM

The concept of Cross-Virtual Machine (XVM) was first conceived by our team during the time when the Frontier framework (the EVM compatibility layer for Substrate) introduced precompiled contracts for interoperability with Substrate pallets from the EVM environment. At that time Hoon thought, since the WASM smart contracts are also a pallet, that is contracts pallets, then we can create an interface for this pallet as a precompiled–so that contracts on EVM can make calls to WASM contracts. At first, this was just a random idea and part of a wish list, but during a Parity and Friends Crowdcast in 2021, this became a real goal. Our team was invited to talk and share what we were working on. Since we did not have much to show at the time, we decided to be ambitious and see if we could create a simple PoC of a precompiled contract for the contracts pallet and give it a cool name, specifically Cross-Virtual Machine (XVM). Our principal developer quickly built a PoC precompiled interface and executed an argumentless cross-virtual environment contract execution from EVM to WASM. After showcasing this achievement at the Crowdcast, we saw huge potential for the multi-virtual machine blockchain.

There are countless WASM-based smart contract VMs like CosmWasm and Near, but they always struggle to compete with EVM. We see existing dApps on the EVM environment as a crucial part of current blockchains, and in order to boost WASM adoption, we shouldn’t compete with EVM, but work together. That is the vision behind XVM.

The lay of the land on Astar

Before further discussing Astar’s Cross Virtual Machine, and how we will build a new Substrate-based solution, it’s important to frame where we are now on Shiden and Astar.

Today, we are rapidly opening channels to other parachains, facilitating the transfer of assets on Dotsama. Users now choose where to use their assets, anywhere on Polkadot. For instance, using your native assets in a neighboring chain’s pool of liquidity thereby earning you another valuable governance token. We could use GLMR (Moonbeam’s native coin) on AthSwap (an Astar Native Dex) to earn aUSD (Acala’s token) rewards. Astar becomes a space for teams to launch their project and build new use cases for their token.

Enabling contracts pallet on Shiden is the first time a developer can build WASM dApps on a Kusama Layer 1. These dApps can directly interact with other native Shiden smart contracts or call to pallets that execute functions built into the Substrate framework. The Shiden network becomes modular, where different dApps and projects can leverage each other through open channels and complex smart contracts. All are secured by Kusama Relay Chain and upgradeable without forking.

Bringing WASM contracts to Shiden was only the first step to building a smart contract platform for WASM developers. We also created the first iteration of Swanky Suite, our all-in-one tool for building WASM smart contracts. Swanky is a tool based on existing tools, such as cargo contract CLI and polkadot.js, but has additional features to build smart contracts on a local testing node (Swanky node). It will be a tool for developers to use existing smart contracts to create an environment to build their projects, saving time at the development stage and making it easier to build new WASM dApps on our networks.

Swanky is able to:

  • Quickstart a local contract development node with instant finality (Swanky Node)
  • Scaffolding a new project with various templates for both smart contracts and front-end dApps (ie. “Truffle” for ink!)
  • Compiling projects with various languages (like ink!, Ask-Lite, …)
  • Setting up RPC tests and integration tests via npm for interacting with smart contracts on the client-side
  • Deploying smart contracts to networks within the Dotsama ecosystem that support pallet-contracts
  • Handling network accounts
  • Making arbitrary calls to the deployed smart contracts

Through the second half of 2022, we will expand the possibilities for development by working closely with Supercolony’s OpenBrush to broaden the library for Polkadot on Rust. Our aim is to create a large library of code and continue connecting to neighboring parachains so that WASM builders can efficiently build dApps that connect to liquidity and assets across the ecosystem.

While a Shiden developer can now use Swanky to build WASM, they still face limitations. Neither EVM nor WASM dApps can directly interact with each other. This means that a Solidity developer is stuck developing only EVM, even though the network supports a booming growth of cross-chain integration (with Turing, Karura, and Moonriver XC20s). It also means that assets and dApps are built twice on both layers of the same network, without ever being able to interact with each other, creating a clunky user experience that will deter, rather than attract, new users to Shiden and Astar.

What xvm_pallet?

XVM is a powerful tool for experimental development, allowing the interaction between WASM and EVM smart contracts. The challenge of building an XVM module is two-fold. First, a WASM smart contract (using Substrate contracts_pallet) expects to only receive and send Native calls (that is, only interactions from another pallet or the runtime). So, our xvm_pallet must wrap any EVM contract call in order to successfully interact with WASM. We call this the EVM adapter, and it is complete. Akru, a lead developer at Astar, successfully demonstrated an EVM to WASM interaction via our XVM pallet. Meaning an event in our EVM environment can now make a call to a separate WASM contract, all within Substrate runtime.

The reverse, that is interacting WASM-to-EVM, also requires XVM translation, but through a chain extension. The XVM adapter is what we are completing and testing now. We expect to complete this and enable a bidirectional XVM on Shiden by Q2 of 2023.

The second challenge is integrating XVM within Substrate runtime; important because it keeps building simple for developers while ensuring that they have the full benefits of ink! contracts. Substrate uses frame macros that are yet to be fully used, where a single line of code in ink! grants the developer access to multiple preloaded functions and automatically writes hundreds of lines of coding. Our XVM solution must easily integrate with the untapped technology already found on Dotsama; including Substrate SDK, our EVM chains (i.e. Astar and Moonbeam), and other parachains through cross-chain integration.

The solution is to build an xvm_pallet standard and integrate it with Polkadot native tooling: Swanky Suite and OpenBrush library. Additionally, we will write basic WASM smart contracts, support the development of front-end UI, and provide documentation to encourage developers who want to experiment with WASM and XVM. Eventually, we will expand on the XVM and consider adding support for Gear, Solana contracts, and networks depending on their value propositions and ecosystem. But building within Substrate is how we take a step forward with Dotsama, whereas developing on other platforms, like CosmWasm, in our opinion, is a step backward.

A Multichain Solution for Developers and Users

The end goal of XVM is to remove the limits for developers on Polkadot and Kusama. Creating the space to build with the code you are familiar with, EVM or WASM, while experimenting with a growing number of tools and integrating with any project built on Astar and Shiden networks. We already have projects, such as ArthSwap, beginning to look to Shiden as a space to launch a WASM DEX. While SiO2 Finance promises to be the first multi-VM lending platform on Astar, and potentially Polkadot. Such projects can implement XVM into their smart contracts, and benefit from:

  • Interaction with code and contracts already found in Substrate framework and other parachain technologies
  • Work with any project currently deployed as an EVM dApp
  • Efficiently build projects with Swanky in either EVM or WASM, via xvm_pallet integration
  • Integrate with assets from across the Polkadot ecosystem
  • Create a multichain experience for users who want to interact with dApps and assets found outside of Dotsama through Astar

We look forward to completing our XVM pallet to enable projects to build across EVM and WASM, uniting assets and dApps on our networks. Users will interact with a single UI, yet benefit from the complex multichain smart contracts written by Astar developers. With XVM, Astar is the network to create groundbreaking smart contracts that can interact with the technologies found on Polkadot and build new chain-agnostic dApps for your users.

About Astar

Astar Network — The Future of Smart Contracts for Multichain.

Astar Network supports the building of dApps with EVM and WASM smart contracts and offers developers true interoperability, with cross-consensus messaging (XCM). 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’s vibrant ecosystem has become Polkadot’s leading Parachain globally, supported by all major exchanges and tier 1 VCs. Astar offers the flexibility of all Ethereum and WASM toolings for developers to start building their dApps. To accelerate growth on Polkadot and Kusama Networks, Astar SpaceLabs offers an Incubation Hub for top TVL dApps.

Website | Twitter | Discord | Telegram | GitHub | Reddit

--

--