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.
33 lines (32 loc) • 1.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = batchTransferAxies;
const contracts_1 = require("./contracts");
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 = await (0, contracts_1.getBatchTransferContract)(signer);
const writeAxieContract = await (0, contracts_1.getAxieContract)(signer);
const isApproved = await writeAxieContract.isApprovedForAll(addressFrom, writeBatchTransferContract.address);
// requirements: msg.sender has to call setApprovalForAll on _tokenContract to authorize this contract.
if (!isApproved) {
console.log('Approving Batch Transfer contract');
const tx = await writeAxieContract.setApprovalForAll(writeBatchTransferContract.address, true);
// wait for tx to be mined and get receipt
const receipt = await tx.wait();
console.log('Receipt:', receipt.transactionHash);
}
else {
console.log('Batch Transfer contract already approved');
}
// 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;
}