As the Substrate (and Polkadot) gains popularity, there is increasing demand for running Ethereum smart contracts and Dapps on Substrate-based blockchains. Ethereum developers benefit by having a faster, more stable, and more versatile infrastructure to deploy their applications. Substrate blockchains benefit from a rich decentralized application ecosystem.
The ParaState (and Second State) team develops software that enables Ethereum smart contracts on Substrate blockchains. It supports smart contracts written in Solidity and other WebAssembly-compatible languages and supports both polkadot.js and web3.js based web application front-ends.
Use the BUIDL online IDE
The ParaState Frontier project demonstrates how to create a Substrate blockchain with
- A traditional EVM to run Solidity smart contracts compiled by the solc compiler.
- A next-gen SSVM-based Ewasm VM to run Ethereum flavored WebAssembly smart contracts compiled from Solidity (via the SOLL compiler) or Rust or other languages.
- A web3 gateway that allows users to submit transactions for deploying contracts, and calling contract functions.
The ParaState Frontier software can tell whether a transaction is for EVM or Ewasm based on the content payload, and route to EVM or SSVM Ewasm on the fly.
We have started a blockchain testnet with the ParaState Frontier software, and the web3 RPC endpoint is
With the web3 RPC, we can use the BUIDL online IDE, created by Second State, to create, deploy, and test Solidity smart contracts. Load BUIDL for ParaState in your browser.
The video below shows how to create, compile, and deploy a simple Hello World smart contract to the ParaState testnet. It also demonstrates how to call functions on the deployed smart contract.
Next, let’s try a more complex smart contract — an ERC20 contract to issue tokens. The video below shows how to send transactions to the deployed contract to mint and transfer tokens, and hence to change the internal state of the contract.
Finally, let’s look into an advanced smart contract — an ERC721 contract for Non-fungible tokens (NFTs). The video shows how to deploy the contract, mint an NFT to yourself, and transfer the NFT to another address.
More examples on how to deploy and use SSVM Ewasm smart contracts via the web3 RPC service can be found here.
You have probably noticed that the web3 RPC and BUIDL IDE make the ParaState testnet very much like an Ethereum blockchain. The users use Ethereum addresses and wallets to sign and send transactions. Substrate is completely behind the scene to manage and store information on the blockchain. The BUIDL user does not need to have a Substrate account address. Indeed, the user does not even need to know the underlying blockchain is based on Substrate.
In many cases, however, the user might want to deploy and run Solidity smart contracts as a Substrate user. That is to use his Substrate address and wallet to sign and send the transaction for deploying and calling the smart contract. It is needed when the user operates in a Substrate ecosystem system, such as Polkadot. To support that use case, ParaState software allows users to submit Ewasm contract transactions from the polkadot.js portal and wallet.
Use polkadot.js to run smart contracts
The substrate-ssvm-node project demonstrates how to create a blockchain with an Ethereum flavored WebAssembly (Ewasm) runtime for smart contracts. It uses the pallet-ssvm component to verify and execute smart contracts. The smart contracts can be written in Solidity or Rust, compiled into WebAssembly bytecode, and submitted to the blockchain for execution via polkadot.js.
Since polkadot.js can only submit Substrate transactions, we need a way to map the Substrate from address to a unique Ethereum address. The pallet-ssvm uses a hash algorithm to convert the Substrate address to Ethereum address. When a user submits a Substrate transaction from polkadot.js, the transaction is signed by the user’s Substrate address. The substrate-ssvm-node verifies the transaction signature, and then executes the content in the SSVM Ewasm runtime with the corresponding Ethereum from address.
The video below shows how to figure out the Ethereum address associated with the current Substrate address in polkadot.js. It requires you to use the SOLL compiler to compile and deploy a small Solidity contract. You will then call a function from the contract from polkadot.js, and see the caller’s Ethereum address in the results.
Next, you can use SOLL to compile an ERC-20 contract to WebAssembly.
Now, use the polkadot.js portal to deploy the conytract, and mint tokens to yourself (i.e., to the Ethereum address associated with your Substrate address in polkadot.js).
That’s it for now! You have learned how to deploy and call Ethereum smart contracts from both an Ethereum wallet and from a Substrate wallet. Go create your own smart contracts. Happy coding!