Second State
  • What is Second State
  • BUIDL developer tool
    • Why BUIDL
    • Getting started
      • Develop for Ethereum Classic
      • Develop for CyberMiles
      • Develop for Ethereum
      • MetaMask notes
    • Data-driven DApps
      • Create and index contracts
    • Rule-based smart contract
    • Sharing your DApp
    • Working with BaaS
    • DEMO: A voting dapp
      • DevChain
      • Ethereum Classic
      • CyberMiles
  • Oasis Ethereum ParaTime
    • Getting started
    • Tutorial: publish a decentralized social media post
    • Tutorial: mint and trade your own ERC-20 tokens
    • Tutorial: mint and transfer your own ERC-721(NFT) tokens
    • Ethereum flavored WebAssembly (Ewasm)
  • DevChain
    • Getting started
      • Run an ewasm smart contract
      • CyberMiles ewasm testnet
    • Build
    • Run
    • BaaS
  • Data services for contracts
    • Getting started
    • Start a search engine (Docker)
      • Notes on SSL with Docker
    • Start a search engine (Ubuntu)
    • Demos
  • White Papers
    • Enterprise middleware for blockchain smart contracts
    • Google for smart contracts
    • FairPlay: a new type of DApp
Powered by GitBook
On this page
  • Step 1 Compile your smart contract to WebAssembly bytecode
  • Step 2 Deploy the contract via web3
  • Step 3 Make an ERC20 coin transfer

Was this helpful?

  1. Oasis Ethereum ParaTime

Ethereum flavored WebAssembly (Ewasm)

Ewasm is the next generation Ethereum virtual machine.

PreviousTutorial: mint and transfer your own ERC-721(NFT) tokensNextGetting started

Last updated 4 years ago

Was this helpful?

The Ewasm is the future of Ethereum smart contracts and applications. It is highly-efficient, supported by the mainstream tech communities, and could support more programming languages on the frontend.

Step 1 Compile your smart contract to WebAssembly bytecode

Here is a written in Solidity. Compiling it with the , you will get a file. Then, convert it to so that we can deploy via web3 JavaScript.

    • This file is an ERC20 contract written in Solidity.

    • This file is a wasm file generate from erc20.sol by

    • Command to generate wasm file: soll -deploy=Normal erc20.sol

    • To deploy wasm file to our node, we need to convert erc20.wasm to hex.

    • Command to generate hex file: xxd -p erc20.wasm | tr -d $'\n' > erc20.hex

Step 2 Deploy the contract via web3

The Node.js application deploys the ERC20 smart contract to the mainnet node. It uses the HEX bytecode from SOLL, as well as the private key from a known address to pay for "gas", and then initiate a coin transfer transaction.

$ node deploy_contract.js

Web3 is connected.
accounts: ["0x1BbE5edc5Caabf4517e40b766D64c3DEd86822Df"]
Contract created at 0x984718904f853A004F145d133dEAb0c1dE50466B
contract.balanceOf(0x1BbE5edc5Caabf4517e40b766D64c3DEd86822Df) = 1000

Step 3 Make an ERC20 coin transfer

$ node transfer_erc20.js 0x984718904f853A004F145d133dEAb0c1dE50466B 0x987652e1C2B3B953354A43171063499DCE16dC8f 10

Web3 is connected.
accounts: ["0x1BbE5edc5Caabf4517e40b766D64c3DEd86822Df"]
Contract instaniated at 0x984718904f853A004F145d133dEAb0c1dE50466B

Initial balances
0x1BbE5edc5Caabf4517e40b766D64c3DEd86822Df = 1000
0x987652e1C2B3B953354A43171063499DCE16dC8f = 0
Transfer 10 token from address(0x1BbE5edc5Caabf4517e40b766D64c3DEd86822Df) to address(0x987652e1C2B3B953354A43171063499DCE16dC8f)

End balances
0x1BbE5edc5Caabf4517e40b766D64c3DEd86822Df = 990
0x987652e1C2B3B953354A43171063499DCE16dC8f = 10

This is just a taste of the future. As Ewasm evolves, we will see many more smart contracts and dapps written in WebAssembly in the future.

The Node.js application makes a transfer from the ERC20 contract we just created. It transfers from the contract creator's address, which we know the private key of, to another address, and then prints the balance. The first argument is the ERC20 contract address, the second argument is the TO address that receives the ERC20 tokens, and the third argument is the amount of ERC20 tokens to transfer.

simple ERC20 smart contract
Second State SOLL compiler
WebAssembly bytecode
HEX text
erc20.sol
erc20.wasm
SOLL
erc20.hex
deploy_contract.js
transfer_erc20.js