0

I have a webapp that calls a smart contract via web3js/Metamask and I want to reload certain elements once the user has submitted the tx.

How can I set up the callbacks for those reload actions?

0

All metamask calls suppose to have callback function where you can do whatever you want. Below is the sample snippet for your reference.

myContractInstance.method(parameter,{ from:result[0],
                            to:recipient,
                            value:  0, 
                        }, function(err, transactionHash) {
                            if (!err)
                            {
                                $('#btnSample').css('display','none');
                                $('#info').html("Transaction succeeded. Track <a href='https://rinkeby.etherscan.io/tx/"+transactionHash +"'>"+here+"</a>");
                                console.log(transactionHash); 
                            }
                            else
                            {
                                console.log('Error in the method');
                                console.log(error);
                            };
                        });

You can even have ajax call within if(!err) to save or record any other action.

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.