Skip to content

Instantly share code, notes, and snippets.

@JGcarv
Created October 17, 2018 18:33
Show Gist options
  • Save JGcarv/8b0f3a229c4310a2a6c5c30642733e30 to your computer and use it in GitHub Desktop.
Save JGcarv/8b0f3a229c4310a2a6c5c30642733e30 to your computer and use it in GitHub Desktop.
ERC20 Token Exchange
pragma solidity 0.4.24;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
contract ERC20Exchange {
address myToken;
address yourToken;
constructor(address _myToken) public {
myToken = _myToken;
}
function tradeToken(address _yourToken) public {
yourToken = _yourToken;
require(IERC20(yourToken).totalSupply() == 10, "Your token needs to have a total supply of 10");
//Transfer mytoken to you
require(IERC20(myToken).transfer(msg.sender, 10));
require(IERC20(yourToken).transferFrom(msg.sender, address(this), 10));
}
function check(address player) public view returns (bool, uint) {
require(IERC20(yourToken).totalSupply() == 10, "Your token needs to have a total supply of 10");
require(IERC20(myToken).balanceOf(player) == 10);
require(IERC20(yourToken).balanceOf(player) == 10);
return (true, 400);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment