1

This is my coding below. When funds are sent to this contract they are supposed to be forwarded to the creator of the smart contract, however it is not working. All funds are being sent to 0x000000000000000000 ethereum address.

contract address is https://etherscan.io/address/0x6f3c294288c62ff70d6274c73741e16d3113f37d

pragma solidity ^0.4.23;

contract Forward {

  address public destinationAddress;
  event LogForwarded(address indexed sender, uint amount);
  event LogFlushed(address indexed sender, uint amount);

  function constuctor() public {
    destinationAddress = msg.sender;
  }

  function() payable public {
    emit LogForwarded(msg.sender, msg.value);
    destinationAddress.transfer(msg.value);
  }

  function flush() public {
    emit LogFlushed(msg.sender, address(this).balance);
    destinationAddress.transfer(address(this).balance);
  }

}
1

Your constructor was never invoked. The constructor should be written without the keyword function. Moreover, spelling of constructor is also wrong.

The correct smart contract would be

pragma solidity ^0.4.23;

contract Forward {

  address public destinationAddress;
  event LogForwarded(address indexed sender, uint amount);
  event LogFlushed(address indexed sender, uint amount);

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

  function() payable public {
    emit LogForwarded(msg.sender, msg.value);
    destinationAddress.transfer(msg.value);
  }

  function flush() public {
    emit LogFlushed(msg.sender, address(this).balance);
    destinationAddress.transfer(address(this).balance);
  }

}

Update:

And even this might fail to fulfill your purpose. Because you have written flush function, using which I assume you want the contract to store balance and later flush it to destination. But in the fallback function, you are instantly giving away the collected balance to destinationAddress. So contract will never store balance. If this is the case, you may want your fallback to look like this:

  function() payable public {
    emit LogForwarded(msg.sender, msg.value);
    // destinationAddress.transfer(msg.value);
  }

Or I may be wrong in assuming the use case you want.

Note: Most developers like to do testing on test networks. Just in case if you didn't know about them.

  • @DavidD If you think that my answer resolves your doubt/query, then you can mark this as accepted answer. Where the answer starts, on left side there would be a tick mark for it. – Ayushya Apr 24 '18 at 3:59

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.