1

I am trying to store a unit from my smart contract in a variable. My code currently looks like this:

var variable = this.contractInstance.methods.myMethod().call({from: account, gas: 5000000});

^myMethod returns a uint

But instead of saving the uint, I save a promise. How can I save the uint instead?

  • Search how to resolve a promise. This is a general issue (not specific to Ethereum). – goodvibration Jun 12 at 14:03
0

You need to use await JavaScript keyword:

var variable = await this.contractInstance.methods.myMethod().call({from: account, gas: 5000000});

web3.js was changed to use Promises at some point of the past. Some of old tutorials might be outdated.

| improve this answer | |
0

You can use a callback function with .then() Try:

var variable;
this.contractInstance.methods.myMethod()
    .call({
        from: account, 
        gas: 5000000
    }).then(function(val){
            variable = ret;
    });
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.