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.
22 lines (21 loc) • 804 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAxieIdsFromAccount = getAxieIdsFromAccount;
const ethers_1 = require("ethers");
const contracts_1 = require("./contracts");
async function getAxieIdsFromAccount(address, provider) {
// get axie contract
const axieContract = (0, contracts_1.getAxieContract)(provider);
// get axies balance for the address
const axiesBalance = await axieContract.balanceOf(address);
// get axie ids
let axieIds = [];
for (let i = 0; i < axiesBalance; i++) {
const axieId = await axieContract.tokenOfOwnerByIndex(address, i);
// convert to number
if (ethers_1.ethers.BigNumber.isBigNumber(axieId)) {
axieIds.push(axieId.toNumber());
}
}
return axieIds;
}