0

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

2

.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.

  • Ok great thanks, so I need to change the code from 'challenger.send(this.balance);' to calling transfer on the contract. Ok that makes some sense! Thanks :) – SwimmingG Jan 18 '18 at 13:01

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.