subscribeToCollection
Method to subscribe to a collection.
You subscribe for a certain price and duration. The subscription will not automatically renew.
With an active subscription, you'll have access to current and future protected data.
Usage
const { txHash } = await dataProtectorSharing.subscribeToCollection({
collectionId: 12,
price: 1, // 1 nRLC
duration: 60 * 60 * 24 * 2, // 172,800 sec = 2 days
});
TIP
Technically, price
and duration
parameters could be avoided. It is mainly a protection against front-running "attacks", ie. if the collection owner changes the price at the same time you subscribe to the collection, you would end up paying more than expected. Passing the price
here allows the SDK to ensure you're paying the right price. If prices don't match, the SDK will throw an error.
Pre-conditions
- The collection must be available for subscription, ie. the collection owner must have set a price and a duration.
Parameters
import { type SubscribeToCollectionParams } from '@iexec/dataprotector';
collectionId Required *
Type: number
Collection ID to which you'd like to subscribe.
const { txHash } = await dataProtectorSharing.subscribeToCollection({
collectionId: 12,
price: 1, // 1 nRLC
duration: 60 * 60 * 24 * 2, // 172,800 sec = 2 days
});
price Required *
Type: number
Price of the rental for the protected data that you expect to rent. This parameter ensures that you will not be front-run by the owner of the protected data. The unit is in nano RLC (nRLC).
const { txHash } = await dataProtectorSharing.subscribeToCollection({
collectionId: 12,
price: 1, // 1 nRLC
duration: 60 * 60 * 24 * 2, // 172,800 sec = 2 days
});
duration Required *
Type: number
Duration of the rental for the protected data that you expect to rent. This parameter ensures that you will not be front-run by the owner of the protected data. The unit is in seconds.
const { txHash } = await dataProtectorSharing.subscribeToCollection({
collectionId: 12,
price: 1, // 1 nRLC
duration: 60 * 60 * 24 * 2, // 172,800 sec = 2 days
});
Return value
import { type SuccessWithTransactionHash } from '@iexec/dataprotector';