Smart Contract Design: Escrow/Controller contract

2018-05-16 17:23:18

How would I go about creating follow: Escrow/Controller contract A which is capable of accepting ERC20tokens from contract B, and ETH from party C and do a swap when certain conditions are met.

This same contract A should also be able to receive ERC20tokens from contract D and ETH from contract E and do a swap when certain conditions are met.

The catch/relevancy of the question is, how to design contract A to be able to handle ERC20token inputs of different kinds e.g. Walton(WTC) & FUSION(FSN) ERC20 tokens?

This is where interfaces come in. That's great, because ERC-20 is actually an interface! I'll give you an example below. As you can see, the TokenSwapper doesn't even need to know about TokenA and TokenB, just that they implement the ERC20 interface.

Oh and before you start developing, you should first make yourself familiar with the basics of the ERC20 interface. Read this wiki

pragma solidity ^0.4.23;

/* Declaring the ERC20 interface. This tells

othe

  • This is where interfaces come in. That's great, because ERC-20 is actually an interface! I'll give you an example below. As you can see, the TokenSwapper doesn't even need to know about TokenA and TokenB, just that they implement the ERC20 interface.

    Oh and before you start developing, you should first make yourself familiar with the basics of the ERC20 interface. Read this wiki

    pragma solidity ^0.4.23;

    /* Declaring the ERC20 interface. This tells

    other contracts how to handle ERC-20 tokens */

    interface ERC20 {

    function allowance(address owner, address spender)

    external view returns (uint256);

    function transferFrom(address from, address to, uint256 value)

    external returns (bool);

    function approve(address spender, uint256 value) external returns (bool);

    function totalSupply() external view returns (uint256);

    function balanceOf(address who) external view returns (uint256);

    function transfer(address to, uint256 value) external returns (bool);

    }

    2018-05-16 18:13:58