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 codeAccontAddress()
and take it backvar
ofvar IDMember = result;
– Augusto Vasques
console.log(AccontAddress());
Returns this Referenceerror: Accontaddress is not defined even using thereturn IDMember; });
I’ll see how use Promisses and Wait thank you so much for the tip– Marcio Livramento
trial
log(this.instance.AccountAddress)
, must come something.– Augusto Vasques
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))}
– Marcio Livramento
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.
– Augusto Vasques
One detail: in the console it is array.no console comes like this
e {s: 1, e: 0, c: Array(1)}
andIDMember = result;
is 1. without having to do even a type of array treatment.– Marcio Livramento
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
– Marcio Livramento