Contract Development – How to Send ERC20 Tokens from Contract

contract-debuggingcontract-designcontract-developmenttokens

I've created an escrow contract, and I want the 'deposit' to be in my own ERC20 token so I've sent the ERC20 tokens to the contract address. The contract can be seen below:

 pragma solidity ^0.4.4;
 contract Escrow {

 address public challenger;
 address public participant;
 address public arbiter;

 function Escrow(address _participant, address _arbiter) {
   challenger = msg.sender;
   participant = _participant;
   arbiter = _arbiter;
 }

 function payoutToParticipant() {
   if(msg.sender == challenger || msg.sender == arbiter) {
     participant.send(this.balance);
   }
 }

 function refundToChallenger() {
   if(msg.sender == challenger || msg.sender == arbiter) {
     challenger.send(this.balance);
   }
 }

 function getBalance() constant returns (uint) {
   return this.balance;
 }

}

After sending the tokens to the address, do I now just call payoutToParticipant() from the challenger or the arbiter to send the tokens? Or will it just send the 0 ETH? Additionally, why does the contract not have to sign the transaction as a user would?

Thanks

Best Answer

.send() function sends Ethereum from contract balance, not tokens. So you need to call token transfer function.

Also I advise you to always you send() function within require() because send() doesn't throw exception and your debug process could be harder.

Additionally, why does the contract not have to sign the transaction as a user would?

Because contract can't execute it's own functions by itself. All functions can be triggered only when real user send signed transaction with correct data field (contains information about calling function and arguments) to Ethereum network.