Transfer Between Two H160 Accounts
The complete code for this example is located in file examples/transfer-h160-to-h160.js
.
Prerequisite
You must run either EVM Localnet with Metamask Wallet tutorial or EVM Testnet with Metamask Wallet tutorial before you can run this tutorial.
Steps
-
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
) -
Paste the address in
destinationEthereumAddress
:// Enter your destination address here:
const destinationEthereumAddress = '0x2B5AD5c4795c026514f8317c7a215E218DcCD6cF'; -
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 EVMWhile 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",
};
Before you proceed, make sure you finished the Install step.
-
Navigate to the
examples
directory of the EVM-Bittensor repo:cd examples
-
Run:
node transfer-h160-to-h160.js
-
Observe the transaction receipt and the change of the recipient balance in logs. You can also look how the recipient balance changed in Metamask.