Generating IOTA addresses from a seed: API call Get_new_addresses()
// The snippet is a part of the IOTA Developer Essentials project. You can reach it at https://hribek25.github.io/IOTA101/ | |
// Complete description and story behind the snippet is available at: https://hribek25.github.io/IOTA101/Allchapters_javascript.ipynb.html#0FF479CB6C0A | |
// Requirement: A core module of IOTA Javascript Library (!npm install @iota/core) | |
var iotalib = require('@iota/core'); | |
var NodeURL = "https://nodes.thetangle.org:443"; | |
var MySeed = "WKQDUZTGFKSSLACUCHHLZRKZBHSDSCEBHKUPDLKFBQALEBKDMFRPUQGZRXAADPG9TSRTZGGBZOFRJCFMM"; | |
var iota = iotalib.composeAPI({ | |
'provider': NodeURL | |
}); | |
//Let's generate 3 addresses using default security level=2. | |
//It is a deterministic function - it always generates same addresses as long as the Seed, Security Level and Index are the same | |
//In case of iota.js library, it additionally checks generated addresses against the Tangle whether the address was spent from | |
//So the following snippet leverages also API calls against a node | |
//Please also note that generating addresses can take quite long | |
var promise = iota.getNewAddress(MySeed, { index: 0, total: 3, returnAll: true } ) | |
.then(address => { | |
console.log(); | |
console.log(address); //returned addresses are printed out | |
}) | |
.catch(error => { | |
console.log("Error occured: %s", error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment