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 (18 loc) • 980 B
text/typescript
import { ethers } from "ethers";
import { MARKETPLACE_GATEWAY_V2 } from "@roninbuilders/contracts";
import { getAxieContract } from "../contracts";
// check and approve the axie contract to transfer axies from address to the marketplace contract
export default async function approveMarketplaceContract(address: string, signer: ethers.Signer) {
const axieContract = getAxieContract(signer)
let isApproved = await axieContract.isApprovedForAll(address, MARKETPLACE_GATEWAY_V2.address)
if (!isApproved) {
console.log('Approving marketplace contract')
const tx = await axieContract.setApprovalForAll(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, MARKETPLACE_GATEWAY_V2.address)
}
return isApproved
}