3

I'm trying to invoke a constant function test from a webpage. I've injected web3 object through MetaMask.

contract A {
     function test(uint8 x) constant returns(uint8) {
        return x + 10;
    }
}

My JS code:

var contractA = web3.eth.contract(abiDefinition).at(address);
var retVal = contractA.test(10);

I get an error:

The MetaMask Web3 object does not support synchronous methods

Is there an async version of this api method?

8

If you want to make an asynchronous request, you can pass an optional callback as the last parameter to most functions. All callbacks are using an error first callback style:

 var contractA = web3.eth.contract(abiDefinition).at(address);
 contractA.test(10, function(error, result){
     if(!error)
         console.log(result)
     else
         console.error(error);
 });

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.