Data Storage
Some read (non-transaction) methods are
static
and 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,
developerPublicKey : identityDeveloper.publicKey,
network : "https://node-us-west.datum.org/api",
storage: "https://node-eu-west.datum.org/storage",
useFuelingServer: true
});
Initialize the datum instance with given configurations
Parameters
Object
- Configuration object with at least akeystore
set
other options:
defaultPublicKeys
- public keys, if set it will be added to access control list for every item stored
network
- the Datum Blockchain HTTP endpoint that is used, if not specified, it will be auto-selected
storage
- the preferred storage endpoint that should be used to store the data. If not set, it will be auto-selected.
useFuelingServer
- to use fueling server
Returns
None
set
set('ANY DATA', "MY_DATA", "UNKNOWN_CATEGORY", "ANY METADATA", 1, 1, 30, false);
Store data with or without key name
Parameters
Object|String
- Object or String of the data. If the data is an object, it will be stringified.String
- The key name that's used for this data, default emptyString
- The category this data belongs to , default emptyString
- The metadata about this data, default emptyNumber
- The requested replicationMode/Count for this Data, default = 1 (hold at least 1 replication)Number
- The requested privacy level for this data , default = 1 (all nodes can store this data)Number
- Amount of days the data should be stored at least, default = 30Number
- Amount to deposit in DAT, default = 0
Returns
Promise with additional events to capture
Example
set('ANY DATA', "MY_DATA", "UNKNOWN_CATEGORY", "ANY METADATA", 1, 1, 30 );
get
get('0xb57f5f92f8931e044f59d54f7f2a445e5dd274e16599f104a61a8dd4cfa5b0fa');
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
getWithKey('User_Profiles');
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');
static
getIds //static
Datum.getIds("0x6e585cc6047a55a793d1E922afE28BaefaBcd73C");
Get all data id's/hashes for given addess
Parameters
String
- wallet address
Returns
Promise with an array of data id's
Example
getIds("0x6e585cc6047a55a793d1E922afE28BaefaBcd73C");
static
getIdsForKey //static
Datum.getIdsForKey('0x6e585cc6047a55a793d1E922afE28BaefaBcd73C', 'PROFILE_DATA');
Get all data id's/hashes behind the given keyname of the wallet address.
Parameters
String
- wallet addressString
- name of the key
Returns
Promise with an array of data id's
Example
getIdsForKey('PROFILE_DATA');
static
getItem //static
Datum.getItem("0x90ff892e2a2eb89a072cdee59e475dee18f3c1407b4d7bfcfe31dbda84fcabaa");
Get item struct stored in blockchain
Parameters
String
- id/hash
Returns
Promise with an object of data
Example
getItem("0x90ff892e2a2eb89a072cdee59e475dee18f3c1407b4d7bfcfe31dbda84fcabaa");
static
getLastIdForKey //static
Datum.getLastIdForKey("0x6e585cc6047a55a793d1E922afE28BaefaBcd73C", "Profiles");
Get last version for data id's/hashes
Parameters
String
- wallet addressString
- key name
Returns
Promise with an array of data id's
Example
getLastIdForKey("0x6e585cc6047a55a793d1E922afE28BaefaBcd73C","Profiles");
static
getLockedBalance //statis
Datum.getLockedBalance();
Returns the locked balance in storage contract items
Parameters
none
Returns
Promise with amount of DAT's in wei
Example
getLockedBalance();
static
getLockedBalanceForId //statis
Datum.getLockedBalanceForId('0x48104eb1eb10ddf99670aff8d2e702104773fce00d9cb67ac41169541df4884a');
Returns the locked balance in storage contract for given id/hash
Parameters
none
Returns
Promise with amount of DAT's in wei
Example
getLockedBalanceForId('0x48104eb1eb10ddf99670aff8d2e702104773fce00d9cb67ac41169541df4884a');
static
getStorageCosts //static
Datum.getStorageCosts(100000, 30);
Returns the calculated storage costs for given size and duration
Parameters
Number
- amount of bytes that you wanna storeNumber
- amount of days that you wanna store the data
Returns
Promise with costs amount of DAT's in wei
Example
getStorageCosts(100000, 30);
static
getTrafficCostsGB //static
Datum.getTrafficCostsGB(10);
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
getTrafficCostsGB(10);
remove
remove('0xb57f5f92f8931e044f59d54f7f2a445e5dd274e16599f104a61a8dd4cfa5b0fa');
// return { "status": "ok" } by promise
Removes the id/hash from storage space
Parameters
String
- id/hash of the data
Returns
Promise with transaction result
Example
remove('0xb57f5f92f8931e044f59d54f7f2a445e5dd274e16599f104a61a8dd4cfa5b0fa');
removeByKey
removeByKey('USER_PROFILES');
// return { "status": "ok" } by promise
Removes the key from storage space
Parameters
String
- key name
Returns
Promise with transaction result
Example
removeByKey('USER_PROFILES');
static
canAccess //static
Datum.canAccess("0xb6e0a22171b5ce8d1031a81f33e521222038db3da6123a6ab0ff19252dde97e4","0x6e585cc6047a55a793d1E922afE28BaefaBcd73C");
Validates if given wallet has access to id/hash
Returns
Promise with true|false
Example
canAccess("0xb6e0a22171b5ce8d1031a81f33e521222038db3da6123a6ab0ff19252dde97e4","0x6e585cc6047a55a793d1E922afE28BaefaBcd73C");
addPublicKeyForData
addPublicKeyForData('0xb57f5f92f8931e044f59d54f7f2a445e5dd274e16599f104a61a8dd4cfa5b0fa', 'f8cea1b3b439b00215e01e8bfae70c1b2ab09e8b339b9e824f2689df650dda52db7b51afe944b37cb068b1d32de36253275f6f94ba5e11a1ceb501674beafc75');
Add third-party public key to the access list for this data
Parameters
String
- Id/hash of the dataString
- Public key (not wallet) of the 3rd party you wanna add
Returns
Promise with transaction result
Example
addPublicKeyForData('0xb57f5f92f8931e044f59d54f7f2a445e5dd274e16599f104a61a8dd4cfa5b0fa', 'f8cea1b3b439b00215e01e8bfae70c1b2ab09e8b339b9e824f2689df650dda52db7b51afe944b37cb068b1d32de36253275f6f94ba5e11a1ceb501674beafc75');
addPublicKeyForDataByKey
addPublicKeyForDataByKey('PROFILE_DATA', 'f8cea1b3b439b00215e01e8bfae70c1b2ab09e8b339b9e824f2689df650dda52db7b51afe944b37cb068b1d32de36253275f6f94ba5e11a1ceb501674beafc75');
Add third-party public key to the access list for this keyname
Parameters
String
- Keyname of the dataString
- Public key of the 3rd party you wanna add
Returns
Promise with transaction result
Example
addPublicKeyForDataByKey('PROFILE_DATA', 'f8cea1b3b439b00215e01e8bfae70c1b2ab09e8b339b9e824f2689df650dda52db7b51afe944b37cb068b1d32de36253275f6f94ba5e11a1ceb501674beafc75');
removePublicKeyForData
removePublicKeyForData('0xb57f5f92f8931e044f59d54f7f2a445e5dd274e16599f104a61a8dd4cfa5b0fa', '0x6e585cc6047a55a793d1E922afE28BaefaBcd73C');
Removes third-party wallet from the access list for this data
Parameters
String
- Id/hash of the dataString
- Wallet address
Returns
Promise with transaction result
Example
removePublicKeyForData('0xb57f5f92f8931e044f59d54f7f2a445e5dd274e16599f104a61a8dd4cfa5b0fa', '0x6e585cc6047a55a793d1E922afE28BaefaBcd73C');