axie-ronin-ethers-js-tools
Version:
A set of functions that make it easier for developers to interact with their Axies on the Ronin network and the maketplace.
35 lines (34 loc) • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = sendRON;
async function sendRON(taskArgs, hre) {
try {
// check if to is valid
if (!hre.ethers.utils.isAddress(taskArgs.to)) {
throw new Error('Invalid address');
}
const accounts = await hre.ethers.getSigners();
const signer = accounts[0];
const addressFrom = signer.address.toLowerCase();
console.log('AddressFrom:', addressFrom);
console.log('AddressTo:', taskArgs.to);
// get RON balance
const balance = await hre.ethers.provider.getBalance(addressFrom);
const balanceInEther = hre.ethers.utils.formatEther(balance);
console.log('RON:', balanceInEther);
// check if balance is enough
if (hre.ethers.utils.parseEther(taskArgs.amount).gt(balance)) {
throw new Error('Not enough RON');
}
// send RON to address
console.log('Sending RON to:', taskArgs.to);
const tx = await signer.sendTransaction({
to: taskArgs.to,
value: hre.ethers.utils.parseEther(taskArgs.amount)
});
console.log('Tx:', tx.hash);
}
catch (error) {
console.error(error);
}
}