List SkyID on Marketplace

To list your SkyID on the marketplace, run this code:

const contractService = skynet.contractService;

const listing = {
        assetContract: contractService.AppNFT.address,
        tokenId: nftID,
        quantity: 1,
        currency: saleCurrency,
        pricePerToken: etherToWei(marketplacePrice, getTokenDecimal(saleCurrency)).toString(),
        startTimestamp: Math.floor(new Date().getTime() / 1000), // Convert to UNIX timestamp
        endTimestamp: Math.floor((new Date().getTime() + saleDuration * 1000) / 1000), // Convert to UNIX timestamp
        reserved: false
};
        
let approveTx;

const isApproved = await contractService.callContractRead(contractService.AppNFT.getApproved(nftID), (res: any) => res);

if (isApproved.success) {
    if (isApproved.data !== contractService.Marketplace.address) {
         approveTx = await contractService.callContractWrite(contractService.AppNFT.approve(contractService.Marketplace.address, nftID));
     } else {
        approveTx = {success: true}
     }
    } else {
            approveTx = await contractService.callContractWrite(contractService.AppNFT.approve(contractService.Marketplace.address, nftID));
    }

    if (approveTx && !approveTx.success) {
        setIsLoading(false);
        toast.error("Failed to approve transaction", { position: "top-right" });
        return;
    } else {
        toast.success("Transaction approved successfully...", { position: "top-right" });
    }

    const tx = await contractService.callContractWrite(contractService.Marketplace.createListing(listing));
           
    if (tx.success) {
        const _listingId: any = await getListingId(tx.data);
        if (!_listingId) {
                setIsLoading(false);
                return {
                    success: false,
                    data: new Error("Failed to get listing ID")
        }
        return {
            success: true,
            data: _listingId
        
    }else{
        return {
           success:false,
           data:new Error("Transaction failed");
    }
            

To get the listing ID for your SkyID, implement this code:

const getListingId = async (txId: string) => {
        const provider:any = skynet.contractService.provider;
        await provider.waitForTransaction(txId);
        const receipt = await provider.getTransactionReceipt(txId);
        if (!receipt) {
            return {
                success: false,
                data: new Error("Transaction not found or not yet mined")
            }
        }
        const logs = receipt.logs;
        return decodeUint256(logs[0].topics[2]);
    }

Last updated