My problem : I want to show transaction details like block hash , block no and input parameters. but it was showing that metamask does not support callback. our function is not waiting till transaction got mined and it enters into else part. how to solve it?

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <link rel="stylesheet" type="text/css" href="../script/main.css">

        <script src="../node_modules/web3/dist/web3.min.js"></script>  
        <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
        <script src="../script/app.js"></script>

    <div class="container">


        <p id="result"></p>

        <label for="address" class="col-lg-2 control-label">Address to be approved </label>
        <input id="address" type="text">

        <label for="amount" class="col-lg-2 control-label"> Maximum Amount</label>
        <input id="amount" type="number">

       <!-- <label for="name" class="col-lg-2 control-label">Instructor Age</label>
        <input id="age" type="text"> -->

        <button id="approve" style="height:50px;width:200px">Approve now</button>
        <input type="button" style="height:50px;width:200px" id="homebutton" value="Home" onClick="location.href='../index.html'" >

     $("#approve").click(function() {
            INCTokenC.approve($("#address").val(),$("#amount").val(),function(error, result){

                        if (tx != null) {
                                var tx = getTx(result);
                        var txResult = "TxHash : " + tx.hash +"\n TxBlockNumber : " + tx.blockNumber;
                        else {
                            $("#result").html(' No Transaction Happen');


1 Answer 1


It is highly recommended to use the Truffle Framework's JavaScript way of calling functions instead of jQuery, although Truffle's PetSShop tutorial shows otherwise.

If you do truffle unbox webpack and check the app/app.js, you will see the advantage in that: The functions use promises, which only resolve, if/when a transaction got mined. As a result of that, you will get a transaction ID you can use to perform web3 functions on to receive the information you desire. But for that it's exactly the other way round: MetaMask forces you to use callbacks, synchronous function calls are not permitted.


    theContract = instance;
    return theContract.yourFunction({from: yourAccount})
// you get here only if the transaction was successful, but you still have to check for it's status - was the function run successfully?
    web3.getTransactionReceipt(theTransactionID, function(error, result){

    [handle error and result here]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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