通过现有代币合同的稳定性进行众筹

时间:2018-09-11 08:09:42

标签: ethereum solidity contract

我正在开始使用以太坊智能合约,并试图为我持有在钱包中的现有代币订立众包合约。

有人可以看看我的合同并在这里向我解释我做错了什么吗?

警告!合同执行期间遇到错误[还原]

问候, 托马斯

pragma solidity ^0.4.24;

library SafeMath{

function add(uint a, uint b) internal pure returns (uint c) {
    c = a + b;
    require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
    require(b <= a);
    c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
    c = a * b;
    require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal pure returns (uint c) {
    require(b > 0);
    c = a / b;
}
}

contract ERC20Interface {
function totalSupply() public constant returns (uint);
function balanceOf(address tokenOwner) public constant returns (uint 
balance);
function allowance(address tokenOwner, address spender) public constant 
returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns 
(bool success);

event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint 
tokens);
}

contract Owned {
address public owner;
address public newOwner;

event OwnershipTransferred(address indexed _from, address indexed _to);

constructor() public {
    owner = msg.sender;
}

modifier onlyOwner {
    require(msg.sender == owner);
    _;
}

function transferOwnership(address _newOwner) public onlyOwner {
    newOwner = _newOwner;
}
function acceptOwnership() public {
    require(msg.sender == newOwner);
    emit OwnershipTransferred(owner, newOwner);
    owner = newOwner;
    newOwner = address(0);
}
}

contract Crowdsale is Owned{

using SafeMath for uint256;

ERC20Interface public token;

// Amount Raised
uint256 public weiRaised;

// Wallet where funds will be transfered
address public wallet;

// Is the crowdsale paused?
bool isCrowdsalePaused = false;

// the exchange rate
uint256 public rate;

// total ETH for sale
uint256 public cap;

uint8 public decimals;

event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);

constructor() public {
    require(wallet != address(0));
    require(token != address(0));

    require(cap > 0);
    require(rate > 0);

    wallet = 0x000000000000000000000000000000000;
    token = ERC20Interface(0x0000000000000000000000000000000);

    decimals = 18;

    // 100.000 ETH
    cap = 100000 * 10**uint(decimals);

    // get the rate based on current amount raised
    if (weiRaised < 20000 * 10 ** uint(decimals)){
      rate = 1000;  
    }else if (weiRaised >= 20000 * 10 ** uint(decimals)){
        rate = 900;
    }else if (weiRaised >= 50000 * 10 ** uint(decimals)){
        rate = 800;
    }
}

function () external payable {
    buyTokens(msg.sender);
}

function buyTokens(address beneficiary) public payable {

    require(beneficiary != 0x0);

    uint256 amount = msg.value;

    require(isCrowdsalePaused == false);

    require(weiRaised.add(amount) <= cap);

    uint256 tokens = getTokenAmount(amount);

    weiRaised = weiRaised.add(amount);

    processPurchase(beneficiary, tokens);

    emit TokenPurchase(msg.sender, beneficiary, amount, tokens);

    forwardFunds();

}

function deliverTokens(address beneficiary,uint256 tokenAmount) internal{
    token.transferFrom(wallet, beneficiary, tokenAmount);
}

function processPurchase(address beneficiary,uint256 tokenAmount) internal{
    deliverTokens(beneficiary, tokenAmount);
}

function getTokenAmount(uint256 amount) internal view returns (uint256){
    return rate.mul(amount);
}

function forwardFunds() internal {
    wallet.transfer(msg.value);
}

function remainingTokens() public view returns (uint256) {
    return token.allowance(wallet, this);
}

function capReached() public view returns (bool) {
    return weiRaised >= cap;
}

function pauseCrowdsale() public onlyOwner {
    isCrowdsalePaused = true;
}

function resumeCrowdsale() public onlyOwner {
    isCrowdsalePaused = false;
}

function takeTokensBack() public onlyOwner
 {
     uint remainingTokensInTheContract = token.balanceOf(address(this));
     token.transfer(owner,remainingTokensInTheContract);
 }
}

0 个答案:

没有答案