0

Im stuck with a crowdsale that needs to be deployed tomorrow! Already created token and now just want to crowdsale. So tried several examples- ethereum.org,zeppelin, github and all but they dont seem to give actual help where needed on address syntax of 3 address types Token address, contract address and receiver address of eth donations. Specifically I just want to know WHERE in the code (or compiler) to plug my token address and WHERE to place the contract address using solidity Compiler and where for reciever address.

Secondly, I think Im confused by the latter two addresses. Are these addresses generated or do I manually have to input them? Here's a link to the coin I want to fork. I want to keep it as simple as possible.

Thanks in advance

pragma solidity ^0.4.13;

contract ECToken {
    function balanceOf(address _owner) constant returns (uint256);
    function transfer(address _to, uint256 _value) returns (bool);
}

library SafeMath {
  function mul(uint256 a, uint256 b) internal constant returns (uint256) {
    uint256 c = a * b;
    assert(a == 0 || c / a == b);
    return c;
  }

  function div(uint256 a, uint256 b) internal constant returns (uint256) {
    uint256 c = a / b;
    return c;
  }

  function sub(uint256 a, uint256 b) internal constant returns (uint256) {
    assert(b <= a);
    return a - b;
  }

  function add(uint256 a, uint256 b) internal constant returns (uint256) {
    uint256 c = a + b;
    assert(c >= a);
    return c;
  }
}

interface Token { 
    function transfer(address _to, uint256 _value) returns (bool);
    function totalSupply() constant returns (uint256 supply);
    function balanceOf(address _owner) constant returns (uint256 balance);
}

contract TokenCrowdsale {

    using SafeMath for uint256;

    // Crowdsale details
    address public beneficiary;      //<---? Do I place a key string here 0x..... ?             
    address public creator;          //<---? Do I place a key string here 0x..... ?        
    address public confirmedBy;      //<---? Do I place a key string here 0x..... ?          
    uint256 public maxSupply = 15000;    
    bool public purchasingAllowed = false;
    uint256 public totalSupplied = 0;

    // Eth to token rate
    uint256 public rate = 1200;

    enum Stages {
        PreSale, //0
        InProgress, //1
        Ended, //2 
        Withdrawn //3
    }

    Stages public stage = Stages.PreSale;

    // deployed token
    Token public deplToken;

    // Invested balances
    mapping (address => uint256) balances;

    /**
    * Throw if at stage other than current stage
    * 
    * @param _stage expected stage to test for
    */
    modifier atStage(Stages _stage) {
        require(stage == _stage);
        _;
    }

    /**
    * Throw if sender is not beneficiary
    */
    modifier onlyBeneficiary() {
        require(beneficiary == msg.sender);
        _;
    }

    /** 
    * Get balance of `_investor` 
    * 
    * @param _investor The address from which the balance will be retrieved
    * @return The balance
    */
    function balanceOf(address _investor) constant returns (uint256 balance) {
        return balances[_investor];
    }


    function enablePurchasing() onlyBeneficiary atStage(Stages.PreSale) {
        purchasingAllowed = true;
        stage = Stages.InProgress;
    }

    function disablePurchasing() onlyBeneficiary atStage(Stages.InProgress) {
        purchasingAllowed = false;
        stage = Stages.Ended;
    }

    function enableNewPurchasing() onlyBeneficiary atStage(Stages.Withdrawn) {
        purchasingAllowed = true;
        stage = Stages.InProgress;
    }

    /**
    * Constructor
    *
    * @param _tokenAddress The address of the token contact
    * @param _beneficiary  The address of the wallet for the beneficiary  
    * @param _creator      The address of the wallet for the creator 
    */
    // Do I uncomment and define these parameters above in constructor area???

    function TokenCrowdsale(address _tokenAddress, address _beneficiary, address _creator) {
        deplToken = Token(_tokenAddress);
        beneficiary = _beneficiary;
        creator = _creator;
    }

    /**
    * For testing purposes
    *
    * @return The beneficiary address
    */
    function confirmBeneficiary() onlyBeneficiary {
        confirmedBy = msg.sender;
    }


    event sendTokens(address indexed to, uint256 value);


    /**
    * Transfer raised amount to the beneficiary address
    */
    function withdraw() onlyBeneficiary atStage(Stages.Ended) {
        uint256 ethBalance = this.balance;
        beneficiary.transfer(ethBalance);
        stage = Stages.Withdrawn;
    }

    /**
    * Receives Eth and issue tokens to the sender
    */
    function () payable atStage(Stages.InProgress) {

        require(purchasingAllowed);
        if (msg.value == 0) { return; }
        uint256 weiAmount = msg.value;
        address investor = msg.sender;
        uint256 received = weiAmount.div(10e7);
        uint256 tokens = (received).mul(rate);
        }

        sendTokens(msg.sender, tokens);
        deplToken.transfer(investor, tokens);
        totalSupplied = (totalSupplied).add(tokens);

        if (totalSupplied >= maxSupply) {
            purchasingAllowed = false;
            stage = Stages.Ended;
        }

    }


    function tokensAvailable() constant returns (uint256) {
        return deplToken.balanceOf(this);
    }


    function withdrawForeignTokens(address _tokenContract) onlyBeneficiary public returns (bool) {
        ECToken token = ECToken(_tokenContract);
        uint256 amount = token.balanceOf(address(this));
        return token.transfer(beneficiary, amount);
    }
}

1 Answer 1

2

NOTE: I've mad an attempt to answer your questions below, but it sounds like you're new to reading and writing Solidity code. I would strongly caution against trying to do a token sale without understanding the contract you're deploying.


In this contract, three addresses are passed as constructor parameters, so you will supply these at the time you deploy the contract. (How you supply the constructor parameters depends on what tool you're using.)

The tokenAddress is the address of the token you're selling (the token contract you deployed).

The beneficiary is the address of the account that will receive the ether.

The creator address seems to be unused, so it doesn't matter what you put there. You added a comment around confirmedBy also. That, too, appears to be unused in any meaningful way.

4
  • Thanks, I am using Solidity compiler and yes relatively new but deployed a token few months ago and thought the crowdsale code would also be a breeze but its 11th hour and sweating bullets. Its a community group anyway..nothing critical. So just to be clear the tokenAddress is not the same as the _tokenAddress within the constructor area. Notice I also have a comment in the constructor area asking if these set of variables are manipulated. How does that get passed into the constructor?
    – oncebitten
    Jan 30, 2018 at 19:33
  • Sorry, should be _tokenAddress.
    – user19510
    Jan 30, 2018 at 19:34
  • Im still clueless here. I get the definitions of the variables, but still unsure WHERE to place the actual addresses. I'm using solidity online compiler if anyone is familiar with that guy. Its a 2 min copy/paste of the above to figure out for those familiar with solidity compiler.
    – oncebitten
    Feb 1, 2018 at 14:28
  • They're parameters you pass to the constructor. You would provide them at the time you deployed the contract, not during compilation.
    – user19510
    Feb 1, 2018 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.