Please use the datumHelper.js to help you get sense of how to generate, recover, and transfer DAT to your accounts.
Please note the following:
- All balances are returned in Wei not DAT.
- You can't perform concurrent set/remove, this is related to Blockchain not Datum since you have to manage transaction nonce.
- ask all your questions @ our gitter_lobby
- check out our official example folder our SDK repo
- Check our getting Started
To Create Datum Identity you need to perform two steps:
- Create new datum Object
const tmpDatObj = new Datum();
- Create Identity
const id = await Datum.createIdentity("password", accounts);
password is used to encrypt your keystore, accounts is the number of accounts you need to generate. Usually the value is 0 unless you want to generate number of accounts under the same seed.
- initialize your datum object with Identity KeyStore
tmpDatObj.initialize({ identity: id.keystore });
Note that keystore must be stringified.
async function createDatumIdentity(password, accounts = 0) {
const tmpDatObj = new Datum();
const id = await Datum.createIdentity(password, accounts);
//Save Identity is a function that save seed into a file to later recovery
saveIdentity(id.seed);
tmpDatObj.initialize({ identity: id.keystore });
tmpDatObj.identity.storePassword(password);
return tmpDatObj;
}
storePassword function allow you to perform operations without providing password every time
To recover datum object from seed keyword
- Create empty Identity object.
const tmpId = new Datum().Identity();
- Recover Identity from seed keyword
await tmpId.recover(seed, password);
password is used to encrypt the keystore information in datum object
- Create empty Datum object
const tmpDatum = new Datum();
- initialize datum object with recovered Identity
tmpDatum.initialize({
identity: JSON.stringify(tmpId.keystore),
});
Notice that keystore is stringified
async function recoverDatumObj(seed, password) {
const tmpId = new Datum().Identity();
await tmpId.recover(seed, password);
const tmpDatum = new Datum();
tmpDatum.initialize({
identity: JSON.stringify(tmpId.keystore),
});
tmpDatum.identity.storePassword(password);
return tmpDatum;
}