Mint a SkyID

After you have created a collection to mint a SkyID, implement this code:

export const mintCollection = async (collectionId: string, nftCount: number, mintAddress: string, skynet: SkyMainBrowser) => {
    try {
        const mintPriceResp = await skynet.contractService.callContractRead(skynet.contractService.OrderPayment.collections(stringToHex(collectionId)), (res) => res);
        let mintPrice: number = 1;
        if (mintPriceResp.success) {
            mintPrice = mintPrice + parseInt(mintPriceResp.data[1].toString())
        }

        mintPrice = mintPrice * nftCount;

        const etherContractService: any = skynet.contractService;
        const balance = await etherContractService.signer.getBalance();

        const userBalance = ethers.utils.formatEther(balance);
        if (parseFloat(userBalance) < mintPrice) {
            return {
                success: false,
                data: collectionId
            }
        }
        const payvalue = ethers.utils.parseEther(mintPrice.toString())

        const patmentMade = await skynet.contractService.callContractWrite(skynet.contractService.OrderPayment.receivePayment(
            stringToHex(collectionId), nftCount, mintAddress,
            {
                value: payvalue
            }
        ))
        if (patmentMade?.success) {
            return {
                success: true,
                data: collectionId
            }
        } else {
            return {
                success: false,
                data: collectionId
            }
        }
    } catch (e) {
        return {
            success: false,
            data: collectionId
        }
    }
}

This function creates a contract that is used to pay a fee to mint the SkyID, and the collection creator sets the fee.

Last updated