The variable tomlLink is undefined outside the function. I would like to know please how to get it defined. Thank you.

var StellarSdk = require('stellar-sdk');
var server = new StellarSdk.Server('https://horizon.stellar.org');

var tomlLink;

.then(function (result) {

    tomlLink = result.records[0]._links.toml.href;                                                        
    console.log(tomlLink); // https://www.anchorusd.com/.well-known/stellar.toml                        
.catch(function (err) {

console.log(tomlLink); // undefined
  • 2
    My JS is a bit rusty but it is likely because console.log() is getting called before the TOML search finishes above. For example if you set var tomlLink = "hello" and run your code as is you will see "hello" logged first. You may need to do some digging in to asynchronous JS and JS Promises. – kolten Sep 3 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.