Skip to main content

EVM Smart Contract

Develop and deploy your first Solidity smart contract on Mandala EVM, bridging Ethereum development with the Polkadot ecosystem.

Overview​

Mandala Testnet provides full Ethereum Virtual Machine (EVM) compatibility, allowing you to deploy existing Ethereum smart contracts and use familiar tools like Remix, Hardhat, and MetaMask.

EVM Environment Setup​

Network Configuration​

Mandala EVM Details:

  • Network Name: Mandala Testnet EVM
  • RPC URL: https://rpc1.paseo.mandalachain.io
  • Chain ID: 4818
  • Currency: KPGT

MetaMask Configuration​

metamask-add-to-chrome.png

metamask-add-extension.png

metamask-create-a-new-wallet.png

improve-metamask-agree.png

metamask-create-password.png

metamask-secure-your-wallet.png

metamask-secret-recovery-phrase.png

metamask-secret-recovery-phrase-confirm.png

metamask-done.png

Add Mandala to MetaMask:

  1. Open MetaMask → Click network dropdown

  2. Select "Add Network" → "Add a custom network"

    metamask-select-network.png

  3. Enter network details:

    FieldValue
    Network NameMetamask Testnet EVM
    New RPC URLhttps://rpc1.paseo.mandalachain.io
    Chain ID4818
    Currency SymbolKPGT

    network-details.png

  4. Click "Save" and switch to Mandala network

    network-save-button.png

    mandala-testnet-successfully.png

    mandala-testnet.png

Development Environment​

Tool Options​

Choose your preferred development environment:

Option 1: Remix IDE (Recommended for beginners)

  • Browser-based, no installation required
  • Built-in compiler and debugger
  • Direct deployment to networks

Remix IDE Setup​

Accessing Remix:

  1. Visit: https://remix.ethereum.org
  2. Accept privacy policy and close welcome screen
  3. Open file in contracts folder: Storage.sol

remix-visit.png

contract-file.png

Building Your First Contract​

Storage Contract​

Create a basic contract that stores and retrieves a number:

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.8.2 <0.9.0;

/**
* @title Storage
* @dev Store & retrieve value in a variable
* @custom:dev-run-script ./scripts/deploy_with_ethers.ts
*/
contract Storage {

uint256 number;

/**
* @dev Store value in variable
* @param num value to store
*/
function store(uint256 num) public {
number = num;
}

/**
* @dev Return value
* @return value of 'number'
*/
function retrieve() public view returns (uint256){
return number;
}
}

Contract Features​

Key Components:

State Variables:

uint256 number;  // Public storage variable for storing a number

Functions:

  • store(uint256 num) - Store a value in the number variable
  • retrieve() - Read and return the stored number value

Function Details:

Store Function:

function store(uint256 num) public {
number = num;
}
  • Visibility: Public (can be called by anyone)
  • Purpose: Updates the stored number with a new value
  • Parameter: num - the new value to store

Retrieve Function:

function retrieve() public view returns (uint256){
return number;
}
  • Visibility: Public view (read-only, doesn't modify state)
  • Purpose: Returns the currently stored number
  • Returns: The value stored in the number variable

Compiling the Contract​

Using Remix​

  1. Select Solidity Compiler tab (left sidebar)

  2. Choose compiler version: 0.8.19 or later

  3. Enable optimization (optional)

  4. Click "Compile Storage.sol"

    solidity-compiler.png

Compilation artifacts:

  • Bytecode: Contract's compiled code
  • ABI: Application Binary Interface
  • Metadata: Contract information

Deploying to Mandala​

Remix Deployment​

  1. Go to "Deploy & Run Transactions" tab

  2. Set environment to "Injected Provider - MetaMask"

  3. Verify network shows "Mandala Testnet EVM (4818)"

  4. Select Storage contract

  5. Click "Deploy"

    remix-deployment.jpg

MetaMask Transaction​

  1. MetaMask popup will show transaction details

  2. Review gas fee and contract creation

  3. Click "Confirm" to deploy

  4. Wait for confirmation (usually 12-24 seconds)

    deploy-confirm.png

Deployment Success​

After successful deployment:

  • Contract address is generated (0x...)

  • Contract appears in Remix deployed contracts

  • Transaction hash is provided

  • Gas used is displayed

    deply-confirm-remix.jpg

  • On metamask Activity section will show the Contract deployment as well

    deploy-confirm-metamask-97592f50178840ca98968f135358f32b.png

Interacting with Your Contract​

Using the Deployed Contract​

Once deployed, you can interact with your Storage contract:

Storing a Value:

  1. In the deployed contracts section, find your Storage contract
  2. Expand the contract to see available functions
  3. Enter a number in the store function input field
  4. Click the store button
  5. Confirm the transaction in MetaMask

Retrieving the Value:

  1. Click the retrieve button (no input needed)
  2. The stored number will be displayed immediately
  3. This is a view function, so no gas is required

Security Best Practices​

Common Vulnerabilities​

Reentrancy protection:

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

contract SecureContract is ReentrancyGuard {
function withdraw() public nonReentrant {
// Safe withdrawal logic
}
}

Integer overflow protection:

// Use SafeMath or Solidity ^0.8.0 built-in checks
function safeAdd(uint256 a, uint256 b) public pure returns (uint256) {
return a + b; // Automatically checks for overflow
}

Access control:

import "@openzeppelin/contracts/access/Ownable.sol";

contract ControlledContract is Ownable {
function sensitiveFunction() public onlyOwner {
// Only owner can call
}
}

Additional Resources:

Congratulations! You've successfully deployed your first EVM smart contract on Mandala Testnet, demonstrating the power of Polkadot's multi-virtual machine architecture!