Skip to content

MyCrowdsale

BokkyPooBah edited this page Oct 3, 2017 · 1 revision

My Crowdsale

Following is a simple crowdsale contract, deployed to the Ropsten network.

Contract address: 0xa858cc5abf91a7dfcff20ee80859e42d9959df08

I contributed 0.5 ETH to the crowdsale contract in the transaction 0x1c51c1c3 to receive 500 MYT tokens.

Note that I had to specify 150,000 gas as the contribution consumes more than the standard 90,000 gas provided for transactions to contracts. The actual gas used in the contribution transaction was 94,418.

I also had to specify a 105 gwei gasPrice in the deployment and contribution transactions - a leftover from the recent Ropsten network attack.



Source Code

From MyCrowdsale.sol:

pragma solidity ^0.4.16;

// ----------------------------------------------------------------------------
// MYT 'MyToken' crowdsale/token contract sample contract.
//
// NOTE: Use at your own risk as this contract has not been audited
//
// Deployed to : 
// Symbol      : MYT
// Name        : MyToken
// Total supply: Unlimited
// Decimals    : 18
//
// Enjoy.
//
// (c) BokkyPooBah / Bok Consulting Pty Ltd 2017. The MIT Licence.
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
    uint public totalSupply;
    function balanceOf(address account) public constant returns (uint balance);
    function transfer(address to, uint value) public returns (bool success);
    function transferFrom(address from, address to, uint value)
        public returns (bool success);
    function approve(address spender, uint value) public returns (bool success);
    function allowance(address owner, address spender) public constant
        returns (uint remaining);
    event Transfer(address indexed from, address indexed to, uint value);
    event Approval(address indexed owner, address indexed spender, uint value);
}


// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {

    // ------------------------------------------------------------------------
    // Current owner, and proposed new owner
    // ------------------------------------------------------------------------
    address public owner;
    address public newOwner;

    // ------------------------------------------------------------------------
    // Constructor - assign creator as the owner
    // ------------------------------------------------------------------------
    function Owned() public {
        owner = msg.sender;
    }


    // ------------------------------------------------------------------------
    // Modifier to mark that a function can only be executed by the owner
    // ------------------------------------------------------------------------
    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }


    // ------------------------------------------------------------------------
    // Owner can initiate transfer of contract to a new owner
    // ------------------------------------------------------------------------
    function transferOwnership(address _newOwner) public onlyOwner {
        newOwner = _newOwner;
    }


    // ------------------------------------------------------------------------
    // New owner has to accept transfer of contract
    // ------------------------------------------------------------------------
    function acceptOwnership() public {
        require(msg.sender == newOwner);
        OwnershipTransferred(owner, newOwner);
        owner = newOwner;
        newOwner = 0x0;
    }
    event OwnershipTransferred(address indexed from, address indexed to);
}


// ----------------------------------------------------------------------------
// Safe maths, borrowed from OpenZeppelin
// ----------------------------------------------------------------------------
library SafeMath {

    // ------------------------------------------------------------------------
    // Add a number to another number, checking for overflows
    // ------------------------------------------------------------------------
    function add(uint a, uint b) pure internal returns (uint) {
        uint c = a + b;
        assert(c >= a && c >= b);
        return c;
    }

    // ------------------------------------------------------------------------
    // Subtract a number from another number, checking for underflows
    // ------------------------------------------------------------------------
    function sub(uint a, uint b) pure internal returns (uint) {
        assert(b <= a);
        return a - b;
    }

    // ------------------------------------------------------------------------
    // Multiply two numbers
    // ------------------------------------------------------------------------
    function mul(uint a, uint b) pure internal returns (uint) {
        uint c = a * b;
        assert(a == 0 || c / a == b);
        return c;
    }

    // ------------------------------------------------------------------------
    // Multiply one number by another number
    // ------------------------------------------------------------------------
    function div(uint a, uint b) pure internal returns (uint) {
        // assert(b > 0); // Solidity automatically throws when dividing by 0
        uint c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold
        return c;
    }
}


// ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals
// ----------------------------------------------------------------------------
contract MyToken is ERC20Interface, Owned {
    using SafeMath for uint;

    // ------------------------------------------------------------------------
    // Token parameters
    // ------------------------------------------------------------------------
    string public constant symbol = "MYT";
    string public constant name = "MyToken";
    uint8 public constant decimals = 18;
    uint public totalSupply = 0;

    // ------------------------------------------------------------------------
    // Balances for each account
    // ------------------------------------------------------------------------
    mapping(address => uint) balances;

    // ------------------------------------------------------------------------
    // Owner of account approves the transfer tokens to another account
    // ------------------------------------------------------------------------
    mapping(address => mapping (address => uint)) allowed;


    // ------------------------------------------------------------------------
    // Constructor
    // ------------------------------------------------------------------------
    function MyToken() public Owned() {
    }


    // ------------------------------------------------------------------------
    // Get the account balance of another account with address account
    // ------------------------------------------------------------------------
    function balanceOf(address account) public constant returns (uint balance) {
        return balances[account];
    }


    // ------------------------------------------------------------------------
    // Transfer the balance from owner's account to another account
    // ------------------------------------------------------------------------
    function transfer(address to, uint tokens) public returns (bool success) {
        balances[msg.sender] = balances[msg.sender].sub(tokens);
        balances[to] = balances[to].add(tokens);
        Transfer(msg.sender, to, tokens);
        return true;
    }


    // ------------------------------------------------------------------------
    // Allow spender to withdraw from your account, multiple times, up to the
    // value tokens. If this function is called again it overwrites the
    // current allowance with value.
    // ------------------------------------------------------------------------
    function approve(address spender, uint tokens) public returns (bool success) {
        allowed[msg.sender][spender] = tokens;
        Approval(msg.sender, spender, tokens);
        return true;
    }


    // ------------------------------------------------------------------------
    // Spender of tokens transfer an tokens of tokens from the token owner's
    // balance to another account. The owner of the tokens must already
    // have approve(...)-d this transfer
    // ------------------------------------------------------------------------
    function transferFrom(address from, address to, uint tokens) public
        returns (bool success)
    {
        balances[from] = balances[from].sub(tokens);
        allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
        balances[to] = balances[to].add(tokens);
        Transfer(from, to, tokens);
        return true;
    }


    // ------------------------------------------------------------------------
    // Returns the number of tokens approved by the owner that can be
    // transferred to the spender's account
    // ------------------------------------------------------------------------
    function allowance(address owner, address spender ) public 
        constant returns (uint remaining)
    {
        return allowed[owner][spender];
    }


    // ------------------------------------------------------------------------
    // Mint coins for a single account
    // ------------------------------------------------------------------------
    function mint(address to, uint tokens) internal {
        require(to != 0x0 && tokens != 0);
        balances[to] = balances[to].add(tokens);
        totalSupply = totalSupply.add(tokens);
        Transfer(0x0, to, tokens);
    }


    // ------------------------------------------------------------------------
    // Owner can transfer out any accidentally sent ERC20 tokens
    // ------------------------------------------------------------------------
    function transferAnyERC20Token(address tokenAddress, uint tokens)
      public onlyOwner returns (bool success)
    {
        return ERC20Interface(tokenAddress).transfer(owner, tokens);
    }
}


contract MyCrowdsale is MyToken {

    // ------------------------------------------------------------------------
    // Start Date
    //   > new Date('2017-10-03T08:00:00+11:00').getTime()/1000
    //   1506978000
    //   > new Date(1506978000 * 1000).toString()
    //   "Tue, 03 Oct 2017 08:00:00 AEDT"
    // End Date
    //   Start Date + 2 weeks
    // ------------------------------------------------------------------------
    uint public constant START_DATE = 1506978000;
    uint public constant END_DATE = START_DATE + 2 weeks;

    // Hard cap
    uint public constant ETH_HARD_CAP = 5 ether;

    // Tokens per 1,000 ETH
    uint public constant tokensPerKEther = 1000000; 

    // Keep track of ETH raised
    uint public ethersRaised;

    // Crowdsale finalised?
    bool public finalised;

    // Tokens transferable?
    bool public transferable;

    // My coffer
    address public wallet; 


    // ------------------------------------------------------------------------
    // Constructor
    // ------------------------------------------------------------------------
    function MyCrowdsale() public MyToken() {
        wallet = msg.sender;
    }


    // ------------------------------------------------------------------------
    // Add precommitment funding token balance and ether cost before the
    // crowdsale commences
    // ------------------------------------------------------------------------
    function addPrecommitment(address participant, uint tokens, uint ethers) public onlyOwner {
        // Can only add precommitments before the crowdsale starts
        require(block.timestamp < START_DATE);

        // Check tokens > 0
        require(tokens > 0);

        // Mint tokens
        mint(participant, tokens);

        // Keep track of ethers raised
        ethersRaised = ethersRaised.add(ethers);

        // Log event
        PrecommitmentAdded(participant, tokens, ethers);
    }
    event PrecommitmentAdded(address indexed participant, uint tokens, uint ethers);


    // ------------------------------------------------------------------------
    // Fallback function to receive ETH contributions send directly to the
    // contract address
    // ------------------------------------------------------------------------
    function() public payable {
        proxyPayment(msg.sender);
    }


    // ------------------------------------------------------------------------
    // Receive ETH contributions. Can use this to send tokens to another
    // account
    // ------------------------------------------------------------------------
    function proxyPayment(address contributor) public payable {
        // Check we are still in the crowdsale period
        require(block.timestamp >= START_DATE && block.timestamp <= END_DATE);

        // Check for invalid address
        require(contributor != 0x0);

        // Check that contributor has sent ETH
        require(msg.value > 0);

        // Keep track of ETH raised
        ethersRaised = ethersRaised.add(msg.value);

        // Check we have not exceeded the hard cap
        require(ethersRaised <= ETH_HARD_CAP);

        // Calculate tokens for contributed ETH
        uint tokens = msg.value.mul(tokensPerKEther).div(1000);

        // Mint tokens for contributor
        mint(contributor, tokens);

        // Log ETH contributed and tokens generated
        TokensBought(contributor, msg.value, tokens);

        // Transfer ETH to coffer 
        wallet.transfer(msg.value);
    }
    event TokensBought(address indexed contributor, uint ethers, uint tokens);


    // ------------------------------------------------------------------------
    // Finalise crowdsale, 20% of tokens for myself
    // ------------------------------------------------------------------------
    function finalise() public onlyOwner {
        // Can only finalise once
        require(!finalised);

        // Can only finalise if we are past end date, or hard cap reached
        require(block.timestamp > END_DATE || ethersRaised == ETH_HARD_CAP);

        // Mark as finalised 
        finalised = true;

        // Allow tokens to be transferable
        transferable = true;

        // Mint tokens for my coffer, being 20% of crowdsold tokens
        uint myTokens = totalSupply.mul(20).div(80);
        mint(owner, myTokens);
    }


    // ------------------------------------------------------------------------
    // transfer tokens, only transferable after the crowdsale is finalised
    // ------------------------------------------------------------------------
    function transfer(address to, uint tokens) public returns (bool success) {
        // Can only transfer after crowdsale completed
        require(transferable);
        return super.transfer(to, tokens);
    }


    // ------------------------------------------------------------------------
    // transferFrom tokens, only transferable after the crowdsale is finalised
    // ------------------------------------------------------------------------
    function transferFrom(address from, address to, uint tokens) public
        returns (bool success)
    {
        // Can only transfer after crowdsale completed
        require(transferable);
        return super.transferFrom(from, to, tokens);
    }
}


Deployment Using Remix And geth

I compiled the code in Remix and copied the deployment script below, set the from account, and added gasPrice: web3.toWei(105, "gwei") as the Ropsten network is still recovering from the recent attack.

var browser_testi_sol_mycrowdsaleContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"tokens","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"finalised","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"tokens","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"START_DATE","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"wallet","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"END_DATE","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ETH_HARD_CAP","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"DECIMALSFACTOR","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"transferable","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"participant","type":"address"},{"name":"tokens","type":"uint256"},{"name":"ethers","type":"uint256"}],"name":"addPrecommitment","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"finalise","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"tokensPerKEther","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"tokens","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ethersRaised","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"tokenAddress","type":"address"},{"name":"tokens","type":"uint256"}],"name":"transferAnyERC20Token","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"contributor","type":"address"}],"name":"proxyPayment","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"participant","type":"address"},{"indexed":false,"name":"tokens","type":"uint256"},{"indexed":false,"name":"ethers","type":"uint256"}],"name":"PrecommitmentAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"contributor","type":"address"},{"indexed":false,"name":"ethers","type":"uint256"},{"indexed":false,"name":"tokens","type":"uint256"}],"name":"TokensBought","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}]);
var browser_testi_sol_mycrowdsale = browser_testi_sol_mycrowdsaleContract.new(
   {
     from: "0x74ed6eb23c21403d7a00bf388a2ec691b98ba8ed",
     data: '0x60606040526000600355341561001457600080fd5b60018054600160a060020a03191633600160a060020a0316908117909155600780546201000060b060020a03191662010000909202919091179055610db58061005e6000396000f300606060405236156101515763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde03811461015c578063095ea7b3146101e657806318160ddd1461021c578063214bb60f1461024157806323b872dd14610254578063313ce5671461027c578063372c6533146102a5578063521eb273146102b8578063545599ff146102e757806365d967b0146102fa57806370a082311461030d57806379ba50971461032c5780638bc04eb71461033f5780638da5cb5b1461035257806392ff0d311461036557806393e4bf4f1461037857806395d89b411461039d578063a4399263146103b0578063a5bc770c146103c3578063a9059cbb146103d6578063d4ee1d90146103f8578063d70fe8a41461040b578063dc39d06d1461041e578063dd62ed3e14610440578063f2fde38b14610465578063f48c305414610484575b61015a33610494565b005b341561016757600080fd5b61016f6105bc565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156101ab578082015183820152602001610193565b50505050905090810190601f1680156101d85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156101f157600080fd5b610208600160a060020a03600435166024356105f3565b604051901515815260200160405180910390f35b341561022757600080fd5b61022f61065f565b60405190815260200160405180910390f35b341561024c57600080fd5b610208610665565b341561025f57600080fd5b610208600160a060020a036004358116906024351660443561066e565b341561028757600080fd5b61028f61069a565b60405160ff909116815260200160405180910390f35b34156102b057600080fd5b61022f61069f565b34156102c357600080fd5b6102cb6106a7565b604051600160a060020a03909116815260200160405180910390f35b34156102f257600080fd5b61022f6106bc565b341561030557600080fd5b61022f6106c4565b341561031857600080fd5b61022f600160a060020a03600435166106d0565b341561033757600080fd5b61015a6106eb565b341561034a57600080fd5b61022f610779565b341561035d57600080fd5b6102cb610785565b341561037057600080fd5b610208610794565b341561038357600080fd5b61015a600160a060020a03600435166024356044356107a2565b34156103a857600080fd5b61016f610843565b34156103bb57600080fd5b61015a61087a565b34156103ce57600080fd5b61022f61091d565b34156103e157600080fd5b610208600160a060020a0360043516602435610924565b341561040357600080fd5b6102cb61094e565b341561041657600080fd5b61022f61095d565b341561042957600080fd5b610208600160a060020a0360043516602435610963565b341561044b57600080fd5b61022f600160a060020a0360043581169060243516610a1e565b341561047057600080fd5b61015a600160a060020a0360043516610a49565b61015a600160a060020a03600435165b60006359d2a8d042101580156104ae57506359e51dd04211155b15156104b957600080fd5b600160a060020a03821615156104ce57600080fd5b600034116104db57600080fd5b6006546104ee903463ffffffff610a9316565b6006819055674563918244f4000090111561050857600080fd5b61052d6103e861052134620f424063ffffffff610ab016565b9063ffffffff610ad116565b90506105398282610ae8565b81600160a060020a03167f8442948036198f1146d3a63c3db355d7e0295c2cc5676c755990445da4fdc1c9348360405191825260208201526040908101905180910390a2600754600160a060020a0362010000909104163480156108fc0290604051600060405180830381858888f1935050505015156105b857600080fd5b5050565b60408051908101604052600781527f4d79546f6b656e00000000000000000000000000000000000000000000000000602082015281565b600160a060020a03338116600081815260056020908152604080832094871680845294909152808220859055909291907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259085905190815260200160405180910390a350600192915050565b60035481565b60075460ff1681565b600754600090610100900460ff16151561068757600080fd5b610692848484610ba5565b949350505050565b601281565b6359d2a8d081565b600754620100009004600160a060020a031681565b6359e51dd081565b674563918244f4000081565b600160a060020a031660009081526004602052604090205490565b60025433600160a060020a0390811691161461070657600080fd5b600254600154600160a060020a0391821691167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3600280546001805473ffffffffffffffffffffffffffffffffffffffff19908116600160a060020a03841617909155169055565b670de0b6b3a764000081565b600154600160a060020a031681565b600754610100900460ff1681565b60015433600160a060020a039081169116146107bd57600080fd5b6359d2a8d042106107cd57600080fd5b600082116107da57600080fd5b6107e48383610ae8565b6006546107f7908263ffffffff610a9316565b600655600160a060020a0383167fda61c0dd6097bf0b966bc5731cb5a1327a747d654195c0d7dc75ae40f7118c1e838360405191825260208201526040908101905180910390a2505050565b60408051908101604052600381527f4d59540000000000000000000000000000000000000000000000000000000000602082015281565b60015460009033600160a060020a0390811691161461089857600080fd5b60075460ff16156108a857600080fd5b6359e51dd04211806108c35750674563918244f40000600654145b15156108ce57600080fd5b6007805461ff001960ff19909116600117166101001790556003546109019060509061052190601463ffffffff610ab016565b60015490915061091a90600160a060020a031682610ae8565b50565b620f424081565b600754600090610100900460ff16151561093d57600080fd5b6109478383610cb8565b9392505050565b600254600160a060020a031681565b60065481565b60015460009033600160a060020a0390811691161461098157600080fd5b600154600160a060020a038085169163a9059cbb9116846000604051602001526040517c010000000000000000000000000000000000000000000000000000000063ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b15156109fd57600080fd5b6102c65a03f11515610a0e57600080fd5b5050506040518051949350505050565b600160a060020a03918216600090815260056020908152604080832093909416825291909152205490565b60015433600160a060020a03908116911614610a6457600080fd5b6002805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b6000828201838110801590610aa85750828110155b151561094757fe5b6000828202831580610aa85750828482811515610ac957fe5b041461094757fe5b6000808284811515610adf57fe5b04949350505050565b600160a060020a03821615801590610aff57508015155b1515610b0a57600080fd5b600160a060020a038216600090815260046020526040902054610b33908263ffffffff610a9316565b600160a060020a038316600090815260046020526040902055600354610b5f908263ffffffff610a9316565b600355600160a060020a03821660007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405190815260200160405180910390a35050565b600160a060020a038316600090815260046020526040812054610bce908363ffffffff610d7716565b600160a060020a0380861660009081526004602090815260408083209490945560058152838220339093168252919091522054610c11908363ffffffff610d7716565b600160a060020a0380861660009081526005602090815260408083203385168452825280832094909455918616815260049091522054610c57908363ffffffff610a9316565b600160a060020a03808516600081815260046020526040908190209390935591908616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a35060019392505050565b600160a060020a033316600090815260046020526040812054610ce1908363ffffffff610d7716565b600160a060020a033381166000908152600460205260408082209390935590851681522054610d16908363ffffffff610a9316565b600160a060020a0380851660008181526004602052604090819020939093559133909116907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9085905190815260200160405180910390a350600192915050565b600082821115610d8357fe5b509003905600a165627a7a72305820a2c8b629ccca05f31b85a3d1d87be7840389b167f5b363b36a025f4e377e64ac0029',
     gas: '4700000',
     gasPrice: web3.toWei(105, "gwei")
   }, function (e, contract){
    console.log(e, contract);
    if (typeof contract.address !== 'undefined') {
         console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
 })

The transaction 0xb34d1c4f created the contract at 0xa858cc5abf91a7dfcff20ee80859e42d9959df08.

I added the address in the source code and verified the source code at the contract address.



Deployment Using Remix And MyEtherWallet

Remix

I compiled the code in Remix:

  • In Remix, select the Compile tab
  • Select browser/name.sol/MyCrowdsale in the dropdown on the top right
  • Click on Details
  • You will see the BYTECODE section
  • Click on the clipboard icon to copy the bytecode to your clipboard. This is the bytecode that you can deploy using MyEtherWallet

MyEtherWallet

Open https://www.myetherwallet.com/ in your browser:

  • In the top right of the MEW screen, select the Network: Ropsten (MyEtherWallet)
  • In the top right of the MEW screen, select the maximum Gas Price
  • Select the Contracts tab
  • Click on Deploy Contract
  • Paste the bytecode from the previous instructions in the Byte Code text box
  • Set your Gas Limit to 2000000 (2 million)
  • Select Keystore File (UTC / JSON) or Private Key and unlock your account
  • Deploy the transaction and search for the contract by viewing the transactions for your account in https://ropsten.etherscan.io/

Verify the source code

  • View the code for your contract in https://ropsten.etherscan.io/
  • Cick on Verify Source and paste in your source code
  • Type MyCrowdsale in the contract name field
  • Select the same compiler version as you used in Remix above
  • Select optimisation On or Off, the same setting as in the Remix Settings tab, in the Enable Optimisation field
  • Confirm with EtherScan that you want the source code verified

Contribute to your crowdsale

  • Send some ETH to your crowdsale contract address
  • View the transaction in EtherScan and verify that tokens were transferred to your account