0
function tipPoolOwner() public payable{
    require(msg.value > 0);
    require(msg.sender != owner());
    address payable poolOwner = address(uint160(owner()));
    poolOwner.transfer(msg.value);
    emit TipSent(msg.sender, msg.value);
}

I have this tipping function running on the remix IDE. the contract will deploy but when trying to run the function and tip the owner of the contract, I get 0x0 Transaction mined but execution failed.

I tested it and it specifically fails at the transfer function. I checked gas price of the mined transaction and it's at 30926, well within the acceptable range.

Edit:
Here is the owner method:

address private _owner;
constructor () internal {
    _owner = msg.sender;
    emit OwnershipTransferred(address(0), _owner);
}

function owner() public view returns (address) {
   return _owner;
}

Here is the Transaction:
enter image description here

1

As long as your transaction was mined, your gas cost is OK.

Invocation of transfer may basically fail for three reasons:

  1. Calling contract does not have enough ether to transfer. This is probably not your case, because your smart contract is transferring exactly the amount of ether it just received, i.e. msg.value.
  2. The address the ether is being transferred to belongs to a smart contract, and execution of its code does not fit into 2300 gas.
  3. The address the ether is being transferred to belongs to a smart contract, and this smart contract reverted transaction.

Could you show the transaction?

I just tried the following contract in Remix and it works fine:

pragma solidity ^0.5.7;

contract Foo {
    event TipSent (address indexed who, uint256 amount);
    event OwnershipTransferred (address indexed oldOwner, address newOwner);

    function tipPoolOwner() public payable{
        require(msg.value > 0);
        require(msg.sender != owner());
        address payable poolOwner = address(uint160(owner()));
        poolOwner.transfer(msg.value);
        emit TipSent(msg.sender, msg.value);
    }

    address private _owner;

    constructor () public {
        _owner = msg.sender;
    }

    function owner() public view returns (address) {
        return _owner;
    }
}

Note, that I changed constructor access modifier from internal to public. Also make sure, that you deploy your contract from one account and call tipPoolOwner from another. Otherwise require(msg.sender != owner()) will revert the transaction.

  • Sure thing I'll post it tomorrow since it's late. It's just between two addressed on my ganache testnet. The only smart contract in use is the one making the transfer – YoungKidWarrior Apr 10 at 8:13
  • updated my post – YoungKidWarrior Apr 11 at 4:50
  • In your transaction 30926 is gas limit, not gas price, and transaction used it all. So, probably, your transaction just ran out of gas. Try executing with higher gas limit, say 100,000. – Mikhail Vladimirov Apr 11 at 5:42
  • My remix says gas limit is 3000000 – YoungKidWarrior Apr 11 at 8:12
  • Answer updated. – Mikhail Vladimirov Apr 11 at 9:09

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.