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.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.transferAxie = transferAxie;
exports.batchTransferAxies = batchTransferAxies;
const contracts_1 = require("./contracts");
async function transferAxie(signer, addressTo, axieId) {
const addressFrom = await signer.getAddress();
console.log(`Transferring axie ${axieId} from ${addressFrom} to ${addressTo}`);
const writeAxieContract = (0, contracts_1.getAxieContract)(signer);
const formattedAxieId = typeof axieId === 'string' ? axieId : axieId.toString();
const tx = await writeAxieContract['safeTransferFrom(address,address,uint256)'](addressFrom, addressTo.replace('ronin:', '0x').toLowerCase(), formattedAxieId);
const receipt = await tx.wait();
return receipt;
}
async function batchTransferAxies(signer, addressTo, axieIds) {
const addressFrom = await signer.getAddress();
console.log(`Transferring ${axieIds.length} axies from ${addressFrom} to ${addressTo}`);
// convert axieIds to an array of strings
const axies = axieIds.map((axieId) => {
return typeof axieId === 'string' ? axieId : axieId.toString();
});
// check if the batch contract is approved to transfer the axies from addressFrom
const writeBatchTransferContract = (0, contracts_1.getBatchTransferContract)(signer);
const writeAxieContract = (0, contracts_1.getAxieContract)(signer);
// batch Transfer, call the function this way since it's overloaded
const tx = await writeBatchTransferContract.functions['safeBatchTransfer(address,uint256[],address)'](writeAxieContract.address, axies, addressTo.replace('ronin:', '0x').toLowerCase());
// wait for tx to be mined and get receipt
const receipt = await tx.wait();
return receipt;
}