0

I'm creating a web app that is using Blockstack and I have some problems with the Javascript and understanding how to use Blockstack in the browser.

Whenever I try to get the Blockstack user's ID or username:

var bsId = blockstack.loadUserData(profile).username;
console.log(bsId);

I get this error:

Uncaught ReferenceError: profile is not defined

But when I run the code directly in the developer console it works fine and returns the username. I'm curious what I'm doing wrong and also this is my first time dealing with Blockstack.

This is a application using Blockstack, Express, and Heroku. I've looked up this error and have not found much and have read over the documentation for Blockstack.

var bsId = blockstack.loadUserData(profile).username;
console.log(bsId);

To return the Blockstack username or selected information.

1 Answers1

0

I think that your problem is that you access the profile property by:

var bsId = blockstack.loadUserData(profile).username;

According to the documentation, loadUserData() returns a userData() object, with params like profile && username (among others). Instead you should use:

var profile = blockstack.loadUserData().profile;  //Get the profile
var username = blockstack.loadUserData().username; //Get the username directly

You could also check that you set correctly the CORS by adding:

config.headers = {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Methods": "GET,PUT,POST,DELETE",
    "Access-Control-Allow-Headers": "Content-Type"
}

Here you have more examples: https://github.com/blockstack/blockstack-browser/blob/master/docs/multi-player-storage.md

Hope it helps!

JP. Aulet
  • 4,375
  • 4
  • 26
  • 39