UNPKG

axie-tools

Version:

TypeScript library and CLI tool for interacting with Axie Infinity marketplace and NFTs on Ronin network. Features marketplace operations (buy/sell/delist), batch transfers, and wallet information.

41 lines (40 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.transferAxie = transferAxie; exports.batchTransferAxies = batchTransferAxies; const ethers_1 = require("ethers"); const contracts_1 = require("./contracts"); const approve_1 = require("./marketplace/approve"); 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, { gasPrice: (0, ethers_1.parseUnits)("20", "gwei") }); const receipt = await tx.wait(); return receipt; } async function batchTransferAxies(signer, addressTo, axieIds) { // 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); const batchTransferAddress = await writeBatchTransferContract.getAddress(); const axieContractAddress = await writeAxieContract.getAddress(); await (0, approve_1.approveBatchTransfer)(signer, batchTransferAddress); 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(); }); if (axies.length === 0) { throw new Error("You must provide at least one axie ID"); } // batch Transfer, call the function this way since it's overloaded const tx = await writeBatchTransferContract["safeBatchTransfer(address,uint256[],address)"](axieContractAddress, axies, addressTo.replace("ronin:", "0x").toLowerCase(), { gasPrice: (0, ethers_1.parseUnits)("20", "gwei"), }); // wait for tx to be mined and get receipt const receipt = await tx.wait(); return receipt; }