Skip to main content
SUBMIT A PRSUBMIT AN ISSUElast edit: Nov 27, 2024

Transfer Between Two H160 Accounts

The complete code for this example is located in file examples/transfer-h160-to-h160.js.

Prerequisite

stop, did you set up your Metamask wallet for EVM?

You must run either EVM Localnet with Metamask Wallet tutorial or EVM Testnet with Metamask Wallet tutorial before you can run this tutorial.

Steps

  1. Create additional address in Metamask

    You can just create a new account or add exising one using a private key. Copy the address (for example: 0x2B5AD5c4795c026514f8317c7a215E218DcCD6cF)

  2. Paste the address in destinationEthereumAddress:

    // Enter your destination address here:
    const destinationEthereumAddress = '0x2B5AD5c4795c026514f8317c7a215E218DcCD6cF';
  3. Configure the amount to be sent. In this example we are using large numbers so that the result is visible in Metamask: Because Metamask doesn't respect decimals of 9 and always defaults to 18 decimals. In production environment 0.1 TAO will match to "100000000000" (10^8), while for this demonstration we have to use "100000000000000000" (10^17), which will appear as "0.1 TAO" in Metamask, but will actually be equal to 100000000 TAO (10^8 TAO).

    1 TAO = 1e18 on subtensor EVM

    While working with the subtensor EVM, 1 TAO should be written as 1 followed by 18 zeroes, i.e., 1e18. Also see this code example: https://github.com/opentensor/evm-bittensor/blob/main/examples/withdraw.js#L58.

        // Create a transfer transaction to send 0.1 TAO
    const tx = {
    to: destinationEthereumAddress,
    value: "100000000000000000",
    };
Stop. Did you install the dependencies?

Before you proceed, make sure you finished the Install step.

  1. Navigate to the examples directory of the EVM-Bittensor repo:

    cd examples
  2. Run:

    node transfer-h160-to-h160.js
  3. Observe the transaction receipt and the change of the recipient balance in logs. You can also look how the recipient balance changed in Metamask.