-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd2e181
commit b50221d
Showing
18 changed files
with
327 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
212 changes: 212 additions & 0 deletions
212
apps/commune-page/src/app/docs/[...slug]/tutorials/evm.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
# EVM | ||
|
||
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: | ||
|
||
```bash | ||
pip install substrate-interface eth-account web3 python-dotenv communex | ||
``` | ||
|
||
### Environment Setup | ||
|
||
Create a `.env` file in your project root and initialize it with the following: | ||
|
||
```env | ||
ETH_PRIVATE_KEY=your_private_key_here | ||
SUBSTRATE_PRIVATE_KEY=your_sub_seed_here | ||
RPC_URL=https://testnet.api.communeai.net | ||
WS_URL=wss://testnet.api.communeai.net | ||
``` | ||
|
||
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 | ||
|
||
1. Install [MetaMask](https://metamask.io/) browser extension if you haven't already. | ||
2. Click on the network dropdown in MetaMask and select "Add Network". | ||
3. 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/ | ||
4. Click "Save" to add the network. | ||
5. Your MetaMask address is now your h160 address on the Commune EVM. | ||
|
||
#### Transfer Using Python | ||
|
||
```py | ||
import os | ||
import asyncio | ||
from dotenv import load_dotenv | ||
from substrateinterface import SubstrateInterface, Keypair | ||
from eth_account import Account | ||
from web3 import Web3 | ||
from eth_utils import to_bytes | ||
from scalecodec.utils.ss58 import ss58_encode | ||
import hashlib | ||
from communex.client import CommuneClient | ||
|
||
# Load environment variables from .env file | ||
load_dotenv() | ||
|
||
# Access environment variables | ||
ETH_PRIVATE_KEY = os.getenv('ETH_PRIVATE_KEY') | ||
SUBSTRATE_PRIVATE_KEY = os.getenv('SUBSTRATE_PRIVATE_KEY') | ||
RPC_URL = os.getenv('RPC_URL') | ||
WS_URL = os.getenv('WS_URL') | ||
def convert_h160_to_ss58(eth_address): | ||
# Ensure the eth_address starts with '0x' | ||
if not eth_address.startswith('0x'): | ||
eth_address = '0x' + eth_address | ||
|
||
# Convert the prefix to bytes | ||
prefix = b'evm:' | ||
|
||
# Convert the Ethereum address to bytes | ||
address_bytes = to_bytes(hexstr=eth_address) | ||
|
||
# Combine prefix and address | ||
combined = prefix + address_bytes | ||
|
||
# Hash the combined data using Blake2 256-bit | ||
blake2_hash = hashlib.blake2b(combined, digest_size=32).digest() | ||
|
||
# Convert the public key to SS58 format | ||
ss58_address = ss58_encode(blake2_hash, ss58_format=42) # Using 42 as the network ID, adjust as needed | ||
|
||
return ss58_address | ||
|
||
|
||
async def perform_transfer(): | ||
keypair = Keypair.create_from_uri(SUBSTRATE_PRIVATE_KEY) | ||
|
||
eth_account = Account.from_key(ETH_PRIVATE_KEY) | ||
recipient_ethereum_address = eth_account.address | ||
|
||
ss58_address = convert_h160_to_ss58(recipient_ethereum_address) | ||
print(f"Mirror: {ss58_address}") | ||
|
||
amount = 10_000_000_000 # 10 tokens | ||
|
||
client = CommuneClient(WS_URL) | ||
|
||
print(client.transfer(key=keypair, dest=ss58_address, amount=amount)) | ||
print(f"Transfer sent to {recipient_ethereum_address} (its ss58 mirror address is: {ss58_address})") | ||
|
||
if __name__ == "__main__": | ||
asyncio.run(perform_transfer()) | ||
|
||
``` | ||
|
||
You should now have funds in your EVM account. | ||
|
||
### Deploying A Smartcontract | ||
|
||
*Adapation of: Moonbeam article at [https://docs.moonbeam.network/builders/ethereum/dev-env/remix/](https://docs.moonbeam.network/builders/ethereum/dev-env/remix/)* | ||
|
||
Now that you have some funds in your EVM account, you can deploy a smart contract. | ||
|
||
#### Getting to Know Remix | ||
|
||
When you visit [Remix](https://remix.ethereum.org/), you'll notice it is divided into four main sections: | ||
|
||
1. 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. | ||
|
||
2. 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. | ||
|
||
3. 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. | ||
|
||
4. 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: | ||
|
||
1. In the File explorer, click the new file icon. | ||
2. Name your new file `MyToken.sol`. | ||
3. In the main panel, paste this code: | ||
|
||
```solidity | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
contract MyToken is ERC20 { | ||
constructor(uint256 initialSupply) ERC20("MyToken", "MYTOK") { | ||
_mint(msg.sender, initialSupply); | ||
} | ||
} | ||
``` | ||
|
||
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: | ||
|
||
1. Click the Solidity Compiler icon in the plugin panel. | ||
2. 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`. | ||
3. If you want, you can check "Auto compile" for automatic recompilation when you make changes. | ||
4. 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: | ||
|
||
1. Select the Deploy and run transactions plugin. | ||
2. From the "ENVIRONMENT" dropdown, choose your wallet (e.g., "Injected Provider - MetaMask"). | ||
3. Connect your wallet to Remix when prompted. | ||
4. Ensure you're connected to the Commune network in your wallet. | ||
5. Keep the default gas limit of 3,000,000. | ||
6. For "VALUE", leave it as 0. | ||
7. Make sure `MyToken.sol` is selected in the "CONTRACT" dropdown. | ||
8. For initial supply, let's use 8 million tokens: 8000000000000000000000000 (remember, ERC-20 tokens typically use 18 decimal places). | ||
9. 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: | ||
1. Click on its name to expand it. | ||
2. Fill in any required parameters. | ||
3. Click the function button to execute it. | ||
|
||
For example, to use the `approve` function: | ||
1. Enter the spender's address (e.g., 0x3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0). | ||
2. Enter the amount to approve (e.g., 10000000000000000000 for 10 tokens). | ||
3. 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. | ||
|
||
|
||
#### 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](https://github.com/renlabs-dev/subspace-network/tree/feat/merged-weight-copying/runtime/src/precompiles) for preliminary information. |
65 changes: 49 additions & 16 deletions
65
apps/commune-page/src/app/docs/[...slug]/tutorials/general-subnet-dao.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,61 @@ | ||
# Subnet 0 Module Curation DAO | ||
# General Subnet Module Curation DAO | ||
|
||
The general subnet (netuid 0) has no consensus to protect against dishonest actors and hence needs an alternative solution. The Module Curation DAO is perpetually curating a onchain whitelist of module key addresses that have a clear value proposition to Commune based on their collective 2/3 majority-based evaluation. The whitelist acts as a condition to be registered on subnet 0. | ||
The general subnet (s2) operates without a limiting consensus mechanism, allowing flexible weight allocation but requiring protection against abuse. The Module Curation DAO serves this purpose by maintaining an on-chain whitelist of validated module key addresses through a 2/3 majority voting system. | ||
|
||
New modules have to submit an application to the DAO, which will be reviewed, discussed and voted on by its members. Members can start votes to remove existing modules from the whitelist. | ||
## Purpose and Function | ||
|
||
note: since the whitelist stores the ss58 addresses, modules will not have to reapply to the DAO after getting deregistered | ||
The DAO protects against dishonest weights on junk modules by: | ||
- Evaluating module applications based on clear value propositions | ||
- Maintaining a curated whitelist of approved modules | ||
- Enabling removal of modules that no longer meet standards | ||
- Ensuring only quality modules receive stake-weight allocations | ||
|
||
Capacities of the S2 DAO: | ||
> **Note:** Since the whitelist stores ss58 addresses, modules don't need to reapply after deregistration. | ||
- approve modules to join the whitelist | ||
- remove modules from the whitelist | ||
- add DAO members | ||
- remove DAO members | ||
## Module Requirements and Economics | ||
|
||
The DAO starts at initially 12 members and is capped at 21 members. | ||
### Whitelist Conditions | ||
- Only whitelisted modules can receive stake-weight allocations | ||
- Whitelisting is required for reward eligibility | ||
- Modules must demonstrate clear value to the Commune ecosystem | ||
|
||
# DAO Interface | ||
### Economic Model | ||
- Modules define stake-weight requirements for access | ||
- Access bandwidth scales with allocated stake | ||
- Rewards increase with stakeholder demand | ||
- Flexible pricing models based on stake-weight | ||
|
||
For high daily participation rate the DAO is native to discord, ran through a discord bot with a dedicated channel on the official Commune AI discord. Applicants and members run bot commands, which can be done easily from the phone. The discord bot is a centrally managed multisignature address. | ||
## Application and Registration Process | ||
|
||
# DAO Decentralization | ||
Modules can join through two pathways in the [Governance Portal][governance]: | ||
|
||
This compromise in decentralization for UX is mitigated by storing the public address of the multisignature key as a global chain parameter. This means if the entity running the bot becomes unavailable, corrupted or is otherwise unable to continue running the bot, the decentralized onchain governance process can vote to change the global parameter to a new multisignature address. This effectively allows the community to replace the bot with a new instance on the fly, as the bot is fully open source and can be operated by anyone. | ||
1. **S2 Application** | ||
- `Propose Change → Create new S2 Application` | ||
- Full DAO review and voting process | ||
|
||
# DAO Participation Reward | ||
2. **Direct Registration** | ||
- `Propose Change → Register a Module → S2` | ||
- Must meet pre-established criteria | ||
|
||
All Module Curation DAO activity is tracked and tied to the members. This allows to retrospectively or actively distribute rewards to members for participation. At launch, there will be no reward, but it can be expected that after the implementation of the DAO treasury rewards are distributed retrospectively to members. | ||
## Governance Structure | ||
|
||
### Decision Making | ||
- 2/3 majority required for all decisions | ||
- Members can initiate removal votes | ||
- Applications undergo collective review and discussion | ||
|
||
### Platform Integration | ||
- Primary interface: [Governance Portal][governance] | ||
- Validator interface: [Community Validator Platform][validator] | ||
- Integrated weight management and stakeholder participation tracking | ||
|
||
## Future Developments | ||
|
||
The system will expand to include: | ||
- API for modules to check stake-weight allocations | ||
- Module idea suggestion platform | ||
- Integration with new human-centric subnets | ||
- Enhanced delegation capabilities for existing validators | ||
|
||
[governance]: https://governance.communeai.org | ||
[validator]: https://validator.communeai.org |
2 changes: 1 addition & 1 deletion
2
apps/commune-page/src/app/docs/[...slug]/tutorials/general-subnet.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.