UNPKG

@iexec/dataprotector

Version:

This product enables users to confidentially store data–such as mail address, documents, personal information ...

31 lines 1.39 kB
import { WorkflowError } from '../../utils/errors.js'; import { getEventFromLogs } from '../../utils/getEventFromLogs.js'; import { throwIfMissing } from '../../utils/validators.js'; import { getSharingContract } from './smartContract/getSharingContract.js'; export const createCollection = async ({ iexec = throwIfMissing(), sharingContractAddress = throwIfMissing(), }) => { const sharingContract = await getSharingContract(iexec, sharingContractAddress); try { let userAddress = await iexec.wallet.getAddress(); userAddress = userAddress.toLowerCase(); const { txOptions } = await iexec.config.resolveContractsClient(); const tx = await sharingContract.createCollection(userAddress, txOptions); const transactionReceipt = await tx.wait(); const specificEventForPreviousTx = getEventFromLogs({ contract: sharingContract, eventName: 'Transfer', logs: transactionReceipt.logs, }); const mintedTokenId = specificEventForPreviousTx.args?.tokenId; return { collectionId: Number(mintedTokenId), txHash: tx.hash, }; } catch (e) { throw new WorkflowError({ message: 'Failed to create collection into collection smart contract', errorCause: e, }); } }; //# sourceMappingURL=createCollection.js.map