Last active
September 24, 2019 10:30
-
-
Save Hribek25/182dcb33c03b2c38cd3f2c24f456eaf4 to your computer and use it in GitHub Desktop.
Generating IOTA addresses from a seed: API call Get_new_addresses()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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