0

Hi I'm having this error when I try to set a variable in remix.

inpage.js:1 Uncaught Error: The MetaMask Web3 object does not support synchronous methods like eth_sendTransaction without a callback parameter. See https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#dizzy-all-async---think-of-metamask-as-a-light-client for details.
at MetamaskInpageProvider.send (inpage.js:1)
at s.send (inpage.js:1)
at n.e [as sendTransaction] (inpage.js:1)
at u.sendTransaction (inpage.js:1)
at u.execute (inpage.js:1)
at HTMLButtonElement.<anonymous> (index.html:93)
at HTMLButtonElement.dispatch (jquery-3.2.1.slim.min.js:3)
at HTMLButtonElement.q.handle (jquery-3.2.1.slim.min.js:3)

This is my code in script

  <script>
    if (typeof web3 !== 'undefined') {
        web3 = new Web3(web3.currentProvider);
    } else {
        // set the provider you want from Web3.providers
        web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
    }
    web3.eth.defaultAccount = web3.eth.accounts[0];

    var CoursetroContract = web3.eth.contract([
{
    "constant": false,
    "inputs": [
        {
            "name": "_fName",
            "type": "string"
        },
        {
            "name": "_age",
            "type": "uint256"
        }
    ],
    "name": "setInstructor",
    "outputs": [],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
},
{
    "constant": true,
    "inputs": [],
    "name": "getInstructor",
    "outputs": [
        {
            "name": "",
            "type": "string"
        },
        {
            "name": "",
            "type": "uint256"
        }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
}]);
    var Coursetro = CoursetroContract.at('0xdfae0c09d27d0614cc337b821be4370d9ec2d7c6');
    console.log(Coursetro);

      Coursetro.getInstructor(function(error, result){
        if(!error)
            {
                $("#instructor").html(result[0]+' ('+result[1]+' years old)');
                console.log(result);
            }
    });

    $("#button").click(function() {
        Coursetro.setInstructor($("#name").val(), $("#age").val());
    });
</script>

This is the first time I encounter this problem because I'm new in making dapps. Any answer will be accepted and appreciated. Thank you and sorry about my english. :)

1

You need to pass a callback function, e.g.:

Coursetro.setInstructor($("#name").val(), $("#age").val(), function (err, result) {
  console.log(err, result);
});
  • Thank you sir this answer my problem. :) Last question sir can I run metamask with free balance? Just for testing dapps? And if yes how? – JeffNUCode Jul 27 '18 at 1:34

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.