So I have deployed a smart contract and can interact with it via a web UI using web3.eth.contract(abi).at(address)
and Metamask - so far so good.
However, between a transaction being submitted and it being mined I would like to display one message and once it has been mined another one.
I understand that web3.eth.getTransactionReceipt(txhash).blockNumber == ""
until the tx has been mined. But how do I check this until it has in fact been mined using javascript and the injected web3 from Metamask?
EDIT: I am trying to make it work with promises but just can't wrap my head around how to implement it. This is my code that should handle a transaction receipt via a promise:
function approveFactoryContract(factory) {
factoryAdress = $("#factory").val();
RegistratContractInstance.approveFactoryContract(factoryAdress, false, {from: web3.eth.accounts[0]}, function(error, result){
if(!error)
console.log(result),
$("#message").html("Approval request has been submitted - please wait a moment for it to be mined. You can check your transaction <a href=\"https://ropsten.etherscan.io/tx/"+result+"\" target=\"_blank\">here</a>");
else
console.error(error);
});
}
How do I make this work?
Display text while pending: Please wait for your transaction to be mined. Display text when resolved: Your transaction has been mined.