Indefinite Variable / Callback in javascript Accountaddress

Asked

Viewed 51 times

0

I am facing a problem in my project: Ultimately it is as follows: My local variable is not being set even if it is set. is Callback problem, how can I solve?

I’ll explain the situation further below.

in my database it looks like this: Email Address | Member ID;

I need to search the member ID by the email address it provides to me.

Within the getCont function there are two local variables, one obeject and one function, and two log;

The Member ID is a local variable of the getCont function and takes indefinite. address is a local variable representing the email provided by the user.

Accountaddress is the object with the name given to my structure in the database, the variable address looks for an ID value;

ex: email address search [email protected] and returns the Member ID and sets the Idmember variable that in the example should be 1; 1st member registration. and Idmember is now set; So far everything works.

Now comes the problem: when I take the Idmember that is in the local scope and do console.log outside the Accountaddress object, it automatically comes back undefined.

I understood that it has the sicronia and callback... blz, how can I callback the Accountaddress object since, it has a function and a return? follows the code below:

Thank you very much

HelloWorld.prototype.getCont = function(cb) { 

    var IDMember; 
    var endereco = window.web3.eth.accounts[0];

    document.getElementById("Address").innerHTML =  endereco;

    this.instance.AccountAddress(endereco, function (error, result) {      
        IDMember = result;   
       document.getElementById("IDAccount").innerHTML =  IDMember;   
       console.log(IDMember);
    }) 

    console.log(AccontAddress()); 
}
  • You’ll have to call a Promise and use the await. Edit the question and enter the code AccontAddress() and take it back var of var IDMember = result;

  • console.log(AccontAddress()); Returns this Referenceerror: Accontaddress is not defined even using the return IDMember; }); I’ll see how use Promisses and Wait thank you so much for the tip

  • trial log(this.instance.AccountAddress), must come something.

  • Yes, this is it;ƒ (){return!this._constant?this.sendTransaction.apply(this,Array.prototype.slice.call(arguments)):this.call.apply(this,Array.prototype.slice.call(arguments))}

  • So it’s a function defined by you in your source code then put the code you used to define this function in the question. In order to understand what is happening.

  • One detail: in the console it is array.no console comes like this e {s: 1, e: 0, c: Array(1)} and IDMember = result; is 1. without having to do even a type of array treatment.

  • Screwed! I’m using Builder :( as I don’t know how to use WEB3 js. and would have to create a node and install N programs. I found a site that does this. the only thing I did was the database, and the javascript front end codes and not all

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.