1

I'm making a simple time-lock contract in Solidity. In my funds withdraw function I have:

function withdraw_funds() public returns (bool) {
        if (getAccounts[msg.sender].amount > 0) {

            if(getAccounts[msg.sender].releasetime < now){
            msg.sender.transfer(getAccounts[msg.sender].amount);
            return (true);
        }}
        else {
            return(false);
        }
     }

On the front end I'm using:

SimpleContract.withdraw_funds(function(err,result){
                if(!err){
                    console.log(result);
                }
                else {
                    console.log("Failure");
                }
            });

With the above function I get the transaction hash regardless of whether the funds were actually transferred or not.

Could someone please tell me the correct way to check the Boolean return value and display the transaction hash if the transfer was successful ?

2

Instead of return(false) you can use revert() or maybe use events so on frontend you can have listeners to be triggered by each event.

I suggest read these:

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