I have my own token on the Harmony blockchain, I need to transfer some of the tokens from my Metamask to another Metamask wallet using node.js, but I have absolutely no idea how to do this. I only know the contract address of my token.
I was able to put together a small code to transfer Harmony One to another Metamask wallet, however, I need to transfer my own tokens located on the Harmony One blockchain:
const {Web3} = require('web3')
const { ChainID, ChainType } = require('@harmony-js/utils');
const { ContractFactory } = require('@harmony-js/contract');
const { Harmony } = require('@harmony-js/core');
const { fromBech32, toBech32 } = require('@harmony-js/crypto');
const web3 = new Web3(new Web3.providers.HttpProvider('https://api.harmony.one'));
const senderAddress = 'my metamask public token';
const receiverAddress = 'receiver metamask public token';
const senderPrivateKey = 'my metamask private token';
(async()=>{
const hmy = new Harmony('https://api.harmony.one', {
chainType: ChainType.Harmony,
chainId: ChainID.HmyMainnet,
});
const senderAccount = hmy.wallet.addByPrivateKey(senderPrivateKey);
const txn = hmy.transactions.newTx({
from: senderAddress,
to: receiverAddress,
value: '1000000000000000000',
gasLimit: '21000',
gasPrice: '100000000000',
shardID: 0,
toShardID: 0,
chainId: 1,
});
// Подписание транзакции
const signedTxn = await hmy.wallet.signTransaction(txn);
// Отправка транзакции
const [sentTxn, txnHash] = await signedTxn.sendTransaction();
console.log('Transaction Hash: ', txnHash);
})()