Skip to content

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

ts

const { 
txHash
} = await
dataProtectorSharing
.
addToCollection
({
protectedData
: '0x123abc...',
collectionId
: 12,
addOnlyAppWhitelist
: '0x541abc...',
});

Parameters

ts
import { type 
AddToCollectionParams
} from '@iexec/dataprotector';

collectionId

number

Collection ID to which you'd like to add the protected data.

ts

const { 
txHash
} = await
dataProtectorSharing
.
addToCollection
({
collectionId
: 12,
protectedData
: '0x123abc...',
addOnlyAppWhitelist
: '0x541abc...',
});

protectedData

AddressOrENS

Address of the protected data you'd like to add to your collection.

ts

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

AddressOrENS

Address of the whitelist smart contract that contains applications allowed to consume the protected data.

ts

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

OnStatusUpdateFn<AddToCollectionStatuses> | undefined

Callback function to be notified at intermediate steps.

ts

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:

ts
'APPROVE_COLLECTION_CONTRACT';
'ADD_PROTECTED_DATA_TO_COLLECTION';

Once with isDone: false, and then with isDone: true

Return value

ts
import { type 
SuccessWithTransactionHash
} from '@iexec/dataprotector';

See SuccessWithTransactionHash