Last active
July 18, 2022 08:02
-
-
Save sargonas/86366991d20cf833b8e60ce136572ac0 to your computer and use it in GitHub Desktop.
Solidium script for a smart contract for a brokerage wallet exchanging eth back for a custom token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.8; | |
contract Token { | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
function transfer(address _to, uint256 _value); | |
function balanceOf(address) returns (uint256); | |
} | |
contract owned { | |
address public owner; | |
function owned() { | |
owner = msg.sender; | |
} | |
modifier onlyOwner { | |
if (msg.sender != owner) throw; | |
_; | |
} | |
function transferOwnership(address newOwner) onlyOwner { | |
owner = newOwner; | |
} | |
} | |
contract TokenSale is owned { | |
address public asset; | |
uint256 public price; | |
function TokenSale() | |
{ | |
asset = 0x8eA88DDefA3B470B51c108475ed2073845a3944C; // RP contract | |
price = 0.000000001 ether; // equals Roughly $1 USD eth for 1,000 RP @ 100$ eth | |
} | |
function transfer_token(address _token, address _to, uint256 _value) | |
onlyOwner() | |
{ | |
Token(_token).transfer(_to,_value); | |
} | |
function transfer_eth(address _to, uint256 _value) | |
onlyOwner() | |
{ | |
if(this.balance >= _value) { | |
_to.transfer(_value); | |
} | |
} | |
function () payable { | |
uint order = msg.value / price; | |
if(order == 0) throw; | |
uint256 balance = Token(asset).balanceOf(address(this)); | |
if(balance == 0) throw; | |
if(order > balance ) | |
{ | |
order = balance; | |
uint256 change = msg.value - order * price; | |
msg.sender.transfer(change); | |
} | |
Token(asset).transfer(msg.sender,order); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment