Data Storage
Some read (non-transaction) methods are
staticand can be accessed without creating an instance of Datum. All blockchain write actions require a Datum instance initialized with a private key. Learn more about initializing the Datum instance here
initialize
With minimal configuration
datum.initialize({
    identity : identity.keystore
});
With all configuration options set
datum.initialize({
    identity : identity.keystore,
    defaultPublicKeys : [identityDeveloper.publicKey],
    network : "https://node-5.megatron.datum.org/api",
    useFuelingServer: true
});
Initialize the datum instance with given configurations
Parameters
Object - Configuration object with at leastidentity set
| key | Type | Required | Description | 
|---|---|---|---|
| identity | String | true | stringified key store | 
| defaultPublicKeys | Array | false | Array of public keys that have access to the stored data | 
| network | String | false | RPC endpoint | 
| useFuelingServer | Boolean | false | Enable use of fuelling server | 
Returns
None
set
Store data with or without key name
Parameters
| Parameter | Type | Required | Default | Description | 
|---|---|---|---|---|
| data | String/Object | true | N/A | Data you want to store | 
| key | String | false | N/A | Key used to store data | 
| category | String | false | N/A | data category | 
| metadata | String | false | N/A | metadata about the data | 
| replicationMode | Number | false | 1 | How many replica of the data set | 
| privacyLevel | Number | false | 1 | Desired privacy level, currently it is set to 1 | 
| duration | Number | false | 30 | How long data need to be stored in Days | 
| owner | String | false | N/A | Set owner of the data | 
| publicKeysToAdd | Array | false | N/A | List of public keys that will have access to data | 
Returns
Promise with additional events to capture
Example
datum.set(data,key,category,metadata,replicationMode,privacyLevel,duration,deposit,owner,publicKeysToAdd)
.then(itemId=>{
  console.log(itemId);
});
get
Downloads the data with given id/hash
Parameters
- String- Id/hash of the data
Returns
Promise with decrypted content of the data
Example
get('0xb57f5f92f8931e044f59d54f7f2a445e5dd274e16599f104a61a8dd4cfa5b0fa');
getWithKey
Downloads the latest version data with given keyname
Parameters
- String- keyname of the data
Returns
Promise with decrypted content of the data
Example
getWithKey('User_Profiles');
getIds static
Get all data id's/hashes for given addess
Parameters
- String- wallet address
Returns
Promise with an array of data id's
Example
//static
Datum.getIds("0x6e585cc6047a55a793d1E922afE28BaefaBcd73C");
getIdsForKey static
Get all data id's/hashes behind the given keyname of the wallet address.
Parameters
- String- wallet address
- String- name of the key
Returns
Promise with an array of data id's
Example
//static
Datum.getIdsForKey('0x6e585cc6047a55a793d1E922afE28BaefaBcd73C', 'PROFILE_DATA');
getItem static
Get item struct stored in blockchain
Parameters
- String- id/hash
Returns
Promise with an object of data
Example
//static
Datum.getItem("0x90ff892e2a2eb89a072cdee59e475dee18f3c1407b4d7bfcfe31dbda84fcabaa");
getLastIdForKey static
Get last version for data id's/hashes
Parameters
- String- wallet address
- String- key name
Returns
Promise with an array of data id's
Example
//static
Datum.getLastIdForKey("0x6e585cc6047a55a793d1E922afE28BaefaBcd73C", "Profiles");
getLockedBalance static
Returns the locked balance in storage contract items
Parameters
none
Returns
Promise with amount of DAT's in wei
Example
//statis
Datum.getLockedBalance();
getLockedBalanceForId static
Returns the locked balance in storage contract for given id/hash
Parameters
none
Returns
Promise with amount of DAT's in wei
Example
//statis
Datum.getLockedBalanceForId('0x48104eb1eb10ddf99670aff8d2e702104773fce00d9cb67ac41169541df4884a');
getStorageCosts static
Returns the calculated storage costs for given size and duration
Parameters
- Number- amount of bytes that you wanna store
- Number- amount of days that you wanna store the data
Returns
Promise with costs amount of DAT's in wei
Example
//static
Datum.getStorageCosts(100000, 30);
getTrafficCostsGB static
Returns the calculated traffic costs for given volumen
Parameters
- Number- amount of GB expected
Returns
Promise with costs amount of DAT's in wei
Example
//static
Datum.getTrafficCostsGB(10);
remove
Removes the id/hash from storage space
Parameters
- String- id/hash of the data
Returns
Promise with transaction result
Example
remove('0xb57f5f92f8931e044f59d54f7f2a445e5dd274e16599f104a61a8dd4cfa5b0fa');
// return { "status": "ok" } by promise
removeByKey
Removes the key from storage space
Parameters
- String- key name
Returns
Promise with transaction result
Example
removeByKey('USER_PROFILES');
// return { "status": "ok" } by promise
canAccess static
Validates if given wallet has access to id/hash
Returns
Promise with true|false
Example
//static
Datum.canAccess("0xb6e0a22171b5ce8d1031a81f33e521222038db3da6123a6ab0ff19252dde97e4","0x6e585cc6047a55a793d1E922afE28BaefaBcd73C");
addPublicKeyForData
Add third-party public key to the access list for this data
Parameters
- String- Id/hash of the data
- String- Public key (not wallet) of the 3rd party you wanna add
Returns
Promise with transaction result
Example
addPublicKeyForData('0xb57f5f92f8931e044f59d54f7f2a445e5dd274e16599f104a61a8dd4cfa5b0fa', 'f8cea1b3b439b00215e01e8bfae70c1b2ab09e8b339b9e824f2689df650dda52db7b51afe944b37cb068b1d32de36253275f6f94ba5e11a1ceb501674beafc75');
addPublicKeyForDataByKey
Add third-party public key to the access list for this keyname
Parameters
- String- Keyname of the data
- String- Public key of the 3rd party you wanna add
Returns
Promise with transaction result
Example
addPublicKeyForDataByKey('PROFILE_DATA', 'f8cea1b3b439b00215e01e8bfae70c1b2ab09e8b339b9e824f2689df650dda52db7b51afe944b37cb068b1d32de36253275f6f94ba5e11a1ceb501674beafc75');
removePublicKeyForData
Removes third-party wallet from the access list for this data
Parameters
- String- Id/hash of the data
- String- Wallet address
Returns
Promise with transaction result
Example
removePublicKeyForData('0xb57f5f92f8931e044f59d54f7f2a445e5dd274e16599f104a61a8dd4cfa5b0fa', '0x6e585cc6047a55a793d1E922afE28BaefaBcd73C');
