Solidity Address Transfer – Fix address.transfer(this.balance) Not Working in Solidity

mistsolidity

In my contract I have a function that's supposed to move the balance of the contract to its owner.
The function is:
function moveFunds(){
owner.transfer(this.balance);
}

owner is set to be: address owner = msg.sender; in the constructor of the contract.

but it doesn't work. The transaction is completed, but the balance doesn't change in the contract or in the owners wallet.
Does anyone have any idea how to solve this? Is there another way to do this?
I've tried both in private network and in Rinkeby multiple times.
There's also a donate function in the contract that works well, the value input is added to the contracts balance and the same value is subtracted from the sender. (I do this before I try to transfer anything to owner)

Thanks in advance.

Edit: Whole contract below: (formatting in here didn't work out..)

   pragma solidity ^0.4.2;

contract donation {
    address owner;
    modifier onlyowner {
        if (msg.sender == owner) _;
        }
    address[] _giver;

function Donation() public {
        owner = msg.sender;
    }


function donate() public payable {
        if (msg.value == 0) {
        revert();
        }
      addGiver(msg.sender);
    }

   /*
   * TODO: 
   */
function moveFund() public onlyowner{
      owner.transfer(this.balance);
    }


function addGiver(address _a) internal {
        _giver.push(_a);
    }
}

Best Answer

There's a typo, a very critical one indeed.

The contract is named donation (d not capitalized)

The constructor is named Donation (D IS capitalized)

Since the contract and constructor are not named the same, the constructor is never called, so owner is never set.

Related Topic