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.
31 lines (30 loc) • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = transferAxie;
const contracts_1 = require("../lib/contracts");
async function transferAxie(taskArgs, hre) {
try {
const accounts = await hre.ethers.getSigners();
const signer = accounts[0];
const address = signer.address.toLowerCase();
const addressTo = taskArgs.address.replace('ronin:', '0x').toLowerCase();
const axieId = parseInt(taskArgs.axie.replace(/\s/g, '').replace('#', ''), 10);
if (isNaN(axieId) || axieId <= 0) {
console.log('Invalid Axie ID provided');
throw new Error('Invalid Axie ID provided');
}
console.log(`Transferring Axie #${axieId} from ${address} to ${addressTo}`);
// get axie contract
const axieContract = await (0, contracts_1.getAxieContract)(signer);
// Transfer
const tx = await axieContract.transferFrom(address, addressTo, axieId, { gasPrice: 20000000000 });
// wait for tx to be mined and get receipt
const receipt = await tx.wait();
console.log('Receipt:', receipt.transactionHash);
return receipt.transactionHash;
}
catch (error) {
console.error(error);
}
return false;
}