I try to transfer ethers from one account to another using my smart contract but the contract doesn't allow me with following functions :

function transferFrom(address _from, address _to, uint256 _value) returns (bool success)            /* A contract attempts to get the coins */ 
            if (balanceOf[_from] < _value) 
                throw;                                              // Check if the sender has enough
            if (balanceOf[_to] + _value < balanceOf[_to]) 
                throw;                                              // Check for overflows
            if (_value > allowance[_from][msg.sender]) 
                throw;                                              // Check allowance
            balanceOf[_from] -= _value;                             // Subtract from the sender
            balanceOf[_to] += _value;                               // Add the same to the recipient
            allowance[_from][msg.sender] -= _value;
            Transfer(_from, _to, _value);
            return true;
function sell(uint256 TokensAmount) afterDeadline

            uint256 amount = TokensAmount;
            if (balanceOf[msg.sender] < amount ) 
                throw;                                              // checks if the sender has enough to sell
            uint256 revenue = amount * sellPrice;
            balanceOf[msg.sender] -= amount;                        // subtracts the amount from seller's balance
            balanceOf[Killer] += amount;                            // adds the amount to owner's balance
            KilledTokens[msg.sender] += amount;
            KilledTillNow += amount;
            address _to = msg.sender;
            address _from = owner;
            uint256 _value = revenue;

            if (!msg.sender.send(revenue)) 
            {                                                       // sends ether to the seller: it's important
                throw;                                              // to do this last to prevent recursion attacks
                transferFrom(_from, _to, _value)
                Transfer(msg.sender, Killer, amount);               // executes an event reflecting on the change
                return;                                             // ends function and returns

1 Answer 1


The problem appears to be in the approach.

You're trying to move eth from wallets the contract doesn't control. A contract can do most things a person can but not more. If can't, for example, spend someone else's money.

Think about this way:

  • Sender -> Contract
  • Contract -> Receiver (using money it received).

function pay(address receiver) payable returns(bool success) {
  // uint paid = msg.value
  balance[msg.sender] += paid;
  return true;

function claim() returns(bool success) {
  if(balance[msg.sender]==0) throw;
  uint amount = balance[msg.sender];
  return true;

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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