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.
21 lines (20 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = approveMarketplaceContract;
const contracts_1 = require("@roninbuilders/contracts");
const contracts_2 = require("../contracts");
// check and approve the axie contract to transfer axies from address to the marketplace contract
async function approveMarketplaceContract(address, signer) {
const axieContract = (0, contracts_2.getAxieContract)(signer);
let isApproved = await axieContract.isApprovedForAll(address, contracts_1.MARKETPLACE_GATEWAY_V2.address);
if (!isApproved) {
console.log('Approving marketplace contract');
const tx = await axieContract.setApprovalForAll(contracts_1.MARKETPLACE_GATEWAY_V2.address, true);
// wait for tx to be mined and get receipt
const receipt = await tx.wait();
console.log('Receipt:', receipt.transactionHash);
// check if marketplace contract is approved for the axie contract
isApproved = await axieContract.isApprovedForAll(address, contracts_1.MARKETPLACE_GATEWAY_V2.address);
}
return isApproved;
}