addToCollection
Method to transfer one of your protected data to a collection of yours in the Data Sharing smart contract.
Under the hood, this method performs two actions:
- Approve the Data Sharing smart contract to manage your protected data.
- Add the protected data to your collection.
Usage
const { txHash } = await dataProtectorSharing.addToCollection({
protectedData: '0x123abc...',
collectionId: 12,
addOnlyAppWhitelist: '0x541abc...',
});
Parameters
import { type AddToCollectionParams } from '@iexec/dataprotector';
collectionId Required *
Type: number
Collection ID to which you'd like to add the protected data.
const { txHash } = await dataProtectorSharing.addToCollection({
collectionId: 12,
protectedData: '0x123abc...',
addOnlyAppWhitelist: '0x541abc...',
});
protectedData Required *
Type: AddressOrENS
Address of the protected data you'd like to add to your collection.
const { txHash } = await dataProtectorSharing.addToCollection({
collectionId: 12,
protectedData: '0x123abc...',
addOnlyAppWhitelist: '0x541abc...',
});
Before any smart contract interaction, the existence of the protected data will be checked, as well as the ownership: it should be the wallet address you used to instantiate DataProtector SDK.
addOnlyAppWhitelist Required *
Type: AddressOrENS
Address of the whitelist smart contract that contains applications allowed to consume the protected data.
const { txHash } = await dataProtectorSharing.addToCollection({
collectionId: 12,
protectedData: '0x123abc...',
addOnlyAppWhitelist: '0xba46d6...',
});
TIP
For this addOnlyAppWhitelist
, you are free to use 0x256bcd881c33bdf9df952f2a0148f27d439f2e64
.
For more details on how to create and manage appsWhitelist, see Apps whitelist.
onStatusUpdate Optional
Type: OnStatusUpdateFn<AddToCollectionStatuses>
Callback function to be notified at intermediate steps.
const { txHash } = await dataProtectorSharing.addToCollection({
protectedData: '0x123abc...',
collectionId: 12,
addOnlyAppWhitelist: '0xba46d6...',
onStatusUpdate: ({ title, isDone }) => {
console.log(title, isDone);
},
});
You can expect this callback function to be called with the following titles:
'APPROVE_COLLECTION_CONTRACT';
'ADD_PROTECTED_DATA_TO_COLLECTION';
Once with isDone: false
, and then with isDone: true
Return value
import { type SuccessWithTransactionHash } from '@iexec/dataprotector';