EVM (Ethereum Virtual Machine): A computation engine that handles smart contract deployment and execution in Ethereum-compatible blockchains.
Commune is EVM compatible, we are currently in the process of testing this feature on our testnet
EVM Tutorials
Installation
First, install the required Python packages:
Environment Setup
Create a .env file in your project root and initialize it with the following:
Replace your_private_key_here and your_sub_seed_here with your actual keys.
Getting Funds to EVM
To interact with smart contracts and use EVM features on Commune, you need to have funds in your EVM-compatible address. This section explains how to transfer funds from your native Commune address to your EVM address.
The EVM in Commune uses the secp256k1 key type, which differs from the native mainnet keys of type sr25519. To deploy your funds on the EVM, you'll need to use address mapping, converting your ss58 address to the corresponding h160 address.
Using MetaMask
Install MetaMask browser extension if you haven't already.
Click on the network dropdown in MetaMask and select "Add Network".
Enter the following details:
Network Name: Commune Testnet
New RPC URL: https://testnet.api.communeai.net
Chain ID: 9461
Currency Symbol: COMAI
Explorer: https://communeai.tryethernal.com/
Click "Save" to add the network.
Your MetaMask address is now your h160 address on the Commune EVM.
Now that you have some funds in your EVM account, you can deploy a smart contract.
Getting to Know Remix
When you visit Remix, you'll notice it is divided into four main sections:
Plugin panel: This area displays icons for each preloaded plugin, the plugin manager, and settings menu. You'll see icons for File explorer, Search in files, Solidity compiler, and Deploy and run transactions. As you activate more plugins, their icons will appear here too.
Side panel: This shows the content of the currently active plugin. By default, you'll see the File explorer, which displays your workspace and files. Clicking other icons in the plugin panel will switch the content here.
Main panel: This is where you'll do most of your work. It opens with a "Home" tab full of helpful resources. You can always reopen this by clicking the blue Remix icon in the top left. As you open files, they'll appear as tabs here.
Terminal: This works like a standard terminal. You can run scripts, view logs, and even interact with Ethers and Web3 JavaScript libraries directly.
Creating Your Smart Contract
Let's create a simple ERC-20 token contract:
In the File explorer, click the new file icon.
Name your new file MyToken.sol.
In the main panel, paste this code:
This contract creates a token called "MyToken" with the symbol "MYTOK". It mints the initial supply to the contract creator.
Compiling Your Contract
Before compiling, make sure you've selected the right file in the File explorer. Then:
Click the Solidity Compiler icon in the plugin panel.
Check that the compiler version matches your contract requirements. For this example, you need 0.8.20 or newer to be compatible with OpenZeppelin's ERC20.sol.
If you want, you can check "Auto compile" for automatic recompilation when you make changes.
Click "Compile MyToken.sol".
A green checkmark will appear next to the Solidity compiler icon if compilation is successful.
Deploying to Commune
Now, let's deploy your contract to Commune:
Select the Deploy and run transactions plugin.
From the "ENVIRONMENT" dropdown, choose your wallet (e.g., "Injected Provider - MetaMask").
Connect your wallet to Remix when prompted.
Ensure you're connected to the Commune network in your wallet.
Keep the default gas limit of 3,000,000.
For "VALUE", leave it as 0.
Make sure MyToken.sol is selected in the "CONTRACT" dropdown.
For initial supply, let's use 8 million tokens: 8000000000000000000000000 (remember, ERC-20 tokens typically use 18 decimal places).
Click "Deploy" and confirm the transaction in your wallet.
Once deployed, you'll see transaction details in the Remix terminal and your contract will appear under "Deployed Contracts".
Interacting with Your Contract
Under "Deployed Contracts", you'll see all the functions you can interact with:
Orange buttons are for non-payable functions that write to the blockchain.
Red buttons are for payable functions that write to the blockchain.
Blue buttons are for functions that only read data.
To use a function:
Click on its name to expand it.
Fill in any required parameters.
Click the function button to execute it.
For example, to use the approve function:
Enter the spender's address (e.g., 0x3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0).
Enter the amount to approve (e.g., 10000000000000000000 for 10 tokens).
Click "transact" and confirm in your wallet.
To view your balance or transfer tokens, you'll need to add the token to your wallet. Check your wallet's documentation for instructions on adding custom tokens.
Remember, every interaction that changes the blockchain state will require a transaction, so keep an eye on your wallet for confirmation prompts.
Deploy with Hardhat
To deploy Tokens on commune EVM, follow the guide here
Precompiles
Precompiles: Built-in contracts that can directly access and modify the blockchain's runtime storage, enabling powerful core-level operations.
We are actively working on completing the documentation for precompiles. In the meantime, you can refer to our Subspace Precompiles Section for preliminary information.