EVM on Local Chain
This page covers getting set up to use EVM on a locally deployed Bittensor blockchain.
Consider first trying EVM with Bittensor testnet. This allows you to try EVM without having to deploy a blockchain locally, but you will have to obtain testnet TAO by inquiring in discord. Alternatively, you can run a local Bittensor blockchain instance.
Key values:
- EVM Subtensor Mainnet Chain ID:
964(UTF-8 encoded TAO symbol) - EVM Subtensor Testnet Chain ID:
945(UTF-8 encoded alpha character) - Opentensor EVM-Bittensor GitHub repo with code examples: https://github.com/opentensor/evm-bittensor/tree/main
Step 1. Run EVM-enabled localnet
Before setting up EVM on a local chain, ensure that you have a local Subtensor instance running.
To do this, follow the steps to start a local Subtensor instance. You can run it using Docker or a local source build.
Step 2. Set Chain ID
A local Subtensor network does not have a Chain ID configured by default. You must set it using an admin extrinsic. Use the sudo section of Polkadot Apps UI to call the appropriate extrinsic and set the Chain ID:
On the call: Call(RuntimeCall) input:
- Select the
adminUtilspallet - Then select the
sudoSetEvmChainIdextrinsic from list of pallet extrinsics - Finally, set the chain ID to either
964for mainnet or945for testnet
Step 3. Create a Metamask wallet
- If you don't already have it, install Metamask wallet browser extension.
- Create a new account.
Step 4. Add EVM localnet to Metamask
Follow the below steps:
- Open Metamask Wallet extension on your browser. Click on the drop-down Select a network menu at the top left.
- Click on + Add a Custom Network button.
- Enter the following details:
- Network name: "Subtensor Local"
- Default RPC URL: http://localhost:9944/
- Chain ID:
964or945, depending on your setting in Step 2 - Currency symbol: TAO
- Click Save.
- Click on Select a network again and switch to the Subtensor Local network.
With the above steps, you have successfully configured your Metamask wallet with the EVM localnet.
Step 5. Configure private key and RPC endpoint
Before you proceed, make sure you finished the Install step.
In this step you will copy the private key from your Metamask wallet account and paste it into the configuration file in the repo. This step will ensure that you are not prompted with password each and every step as you run these tutorials.
-
Navigate to the
examplesdirectory of the EVM-Bittensor repo:cd examples -
Create
config.jsfile by copying theconfig-example.jsfile:cp config-example.js config.js -
On Metamask wallet extension, your wallet account will have a H160 account address, starting with the
0xprefix (for example:0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf), and also your wallet account name. -
Click on your wallet account name, which will open the drop-down menu.
-
Click on the ⋮ (three vertical dots, i.e., vertical ellipsis) next to the wallet account and select Account details. It will open a view with a QR code, your wallet account H160 address and a Show private key button.
-
Click on the Show private key button, enter the password. You will then see the private key for your wallet account. Copy this private key.
-
Paste this private key into
ethPrivateKeystring in yourconfig.jsfile as shown below (mangled for security):const ethPrivateKey =
"02c1c4112233snipsnipsnipgh933aca491e090e0b7xxyy1b124b86d9382b01a8"; -
Finally, edit the
module.exportssection of theconfig.jsfile to use the localnet URLs, as shown below:module.exports = {
ethPrivateKey,
subSeed,
rpcUrl: rpcUrlLocal,
wsUrl: wsUrlLocal,
};
Save the config.js file. Now your setup is ready to run the tutorials with EVM localnet.
Step 6 (Optional). Disable white list for contract deployment
If you are planning to deploy contracts locally, you need to disable the premission control. This can be done with the following extrinsic in sudo section of Polkadot AppsUI:
evm >> disableWhitelist
Select Yes and then click Submit Sudo.