Dapp Deployment

Section Brief:

This document is intended to help developers deploy both Ink! and EVM smart contracts to the CESS network.

Deploying Ink! Contracts to CESS Network

There are few requirements need to be meet:

To provides a command-line interface for working with smart contracts using the ink! language, install the WebAssembly optimizer binaryen:

sudo apt install binaryen

To warn you about issues that might lead to security vulnerabilities, install cargo-dylint to check ink! contracts:

cargo install cargo-dylint dylint-link

Install cargo-contract:

cargo install cargo-contract --force

Verify the installation and explore the commands:

cargo contract --help

Create a new smart contract project

We will create new smart contract project using the cargo-contract package downloaded in the previous steps. Run the following command:

cargo contract new flipper
cd flipper
code .

Open the Cargo.toml file and have version 3.3 for all ink crates.

ink_primitives = { version = "3.3", default-features = false }
ink_metadata = { version = "3.3", default-features = false, features = ["derive"], optional = true }
ink_env = { version = "3.3", default-features = false }
ink_storage = { version = "3.3", default-features = false }
ink_lang = { version = "3.3", default-features = false }

Run the test for the flipper contract:

cargo test

You should see the following output:

running 2 tests

test flipper::tests::it_works ... ok

test flipper::tests::default_works ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

To build and generate the WebAssembly binary for the contract project:

cargo +nightly contract build

After the build is complete, you can find the "flipper.contract" file under the "target/ink/ "folder. This file will be used to deploy the contracts on the CESS network.

Deploying the contract

Open CESS Explorer and navigate to "Developers => Contracts" page.

Click on "Upload & deploy code" button to open "Upload & deploy code dialog box".

On the dialog box, select the account which will be used as the deployment account and upload the "flipper.contract" file.

Give a discriptive name to the contract and click the next button to advance to the next dialog box.

Depending on the Deployment Constructor, review and update the values if needed or accept the default values and click "deploy".

Authorize and submit signed transaction and wait for the transaction to be included into the block.

Once the contract is diployed, you can view the contract in the "contracts" page as shown in the following.

To access the contract, you can open the contracts page and in contracts list, you can find the list of all the contracts diployed.

As shown in the above, you can access smart contract functions using the CESS Explorer.

Deploying EVM Contracts to CESS Network

Preparation

  • MetaMask: Required to get Ethereum address and to connect to the CESS Chain.

  • Remix IDE: IDE to develop, compile, and deploy smart contracts to the chain.

  • CESS node: Have access to the CESS node. (Make sure the node allows access to MetaMask)

For the current guide, we will be deploying the contract to the CESS test chain. The following steps will guide you to deploy EVM-based contracts on CESS Chain:

Adding CESS Network to MataMask

Open the MetaMask setting tab, click on the “Networks” tab, click on “Add a network” and then “Add a network manually”

On “Add a network manually” page, enter the following details:

Note: In case MetaMask is not able to connect your RPC URL, make sure the CORS is allowed for MetaMask in the CESS node.

Convert the Account address to the CESS-supported address

Copy the account address from MetaMask.

Open the following link Substrate Address Converter.

Fund the address using polkadot.js.org/apps

Using CESS Explorer “Accounts” -> "Transfer" to transfer amount to the contract address.

Validate the fund in MetaMask

To validate the funds are in the Ethereum account, open MetaMask and check that account has the funds transferred. Check the fig-6

Deploy contract to address using Remix IDE

Open Remix Ethereum and go to “File explorer”.

In File explorer, open the smart contract you wish to compile and then deploy.

Once the file is selected, go to tab “Solidity Compiler”, you should see the selected file, press the "Compile" button to compile the contract. Once compiled, you’ll see the "green tick" mark and compiled (*.sol) file.

Go to “Deploy and run Transactions”, once the compilation is successful, you should see the compiled *.sol file selected, ready to be deployed. In the “Environments” drop-down, select “Injected Provider - MetaMask” and click "deploy".

Note: When you click "deploy", you may need to click confirm in MetaMask to allow Remix to access the account and submit the transaction.

Click "Confirm" to submit the transaction to deploy the smart contract.

After the transaction is deployed and mined on the chain, you’ll see the following message.

In the “Deployed Contracts” section in the Remix, you can call the function of the smart contract.

Transfer token from Ethereum account to CESS address

Convert the Substrate address to Ethereum account address using the link Substrate Address Converter.

Copy the Ethereum equivalent address of the substrate address and use MetaMask to transfer fund.

Confirm the balance in the CESS Exployer: Developer RPC calls. Use the Ethereum address in previous step.

Withdraw the balance from Ethereum account to CESS account

To withdraw the balance from Ethereum account to CESS account, follow the route "Developer => Extrinsics => evm => withdraw".

Validate the balances in "Accounts" tab of CESS Explorer.

Further reading

Develop smart contracts