0

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;

server.assets()
.forCode('USD')
.forIssuer('GDUKMGUGDZQK6YHYA5Z6AY2G4XDSZPSZ3SW5UN3ARVMO6QSRDWP5YLEX')
.call()
.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(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.