UNPKG

gray-market-js

Version:

Utility library for the Gray Market rental marketplace

24 lines (21 loc) 1.02 kB
const { ethers } = require("ethers"); const erc721ABI = require("./abi/ERC721.json"); const MessageHelper = require("./signer/MessageHelper"); class RentalListingCreator { constructor() {} async createListing(signerOrProvider, chainId, verifyingContract, listing, proxyContractAddress) { const signable = MessageHelper.getSignable(chainId, verifyingContract, listing); const contract = new ethers.Contract(listing.collectionAddress, erc721ABI, signerOrProvider); const isApproved = await contract.isApprovedForAll(await signerOrProvider.getAddress(), proxyContractAddress); if(!isApproved) { alert("NFT is not approved here, a TX should be asked from the user for that"); //await contract.setApprovalForAll(proxyContractAddress, true); } const signature = await signerOrProvider._signTypedData(signable.domain, signable.types, listing); return { signable: signable, signed: signature } } } module.exports = RentalListingCreator;