I am using remix.ethereum.org as my compiler. I have already done some tests with the token contract before, and it worked. but since a few days, on wallet.ethereum.org, when I add the token after creating it it doesn't show the balancec anymore (just 0,0000...). So I tried to use MyEtherWallet, to send the tokens to the crowdsale address. And bam! There it says that my ERC20Token is not valid. Now as I can't find the issue, I would be very grateful if somebody could help me here, and I would send 0.1 ETH as a reward to the guy who finds the issue. Here the contract:
pragma solidity ^0.4.12;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
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) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
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;
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner public {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
uint256 public totalSupply;
function balanceOf(address who) public constant returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public constant returns (uint256 balance) {
return balances[_owner];
}
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public constant returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
uint256 _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue)
returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue)
returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
/**
* @title Burnable Token
* @dev Token that can be irreversibly burned (destroyed).
*/
contract BurnableToken is StandardToken {
event Burn(address indexed burner, uint256 value);
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public {
require(_value > 0);
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
Burn(burner, _value);
}
}
contract ImmortalityIvars is BurnableToken, Ownable {
//this is token customize it after that we will deploy ICO - ok, understood. So just change name symbol etc right?yes ok
string public constant name = "Immortality Ivars";
string public constant symbol = "IMIV";
uint public constant decimals = 6;
uint256 public constant initialSupply = 1000000 * (10 ** uint256(decimals));
// Constructor
function ImmortalityIvars() {
totalSupply = initialSupply;
balances[msg.sender] = initialSupply; // Send all tokens to owner
}
}
Okay, I edited it to the question now - and tried to format it, don't know if it worked.
pragma solidity ^0.4.11;
/** * @title SafeMath * @dev Math operations with safety checks that throw on error */ 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) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold 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; } }
/** * @title Crowdsale * @dev Crowdsale is a base contract for managing a token crowdsale. * Crowdsales have a start and end timestamps, where investors can make * token purchases and the crowdsale will assign them tokens based * on a token per ETH rate. Funds collected are forwarded to a wallet * as they arrive. */ contract token { function transfer(address receiver, uint amount){ } } contract Crowdsale { using SafeMath for uint256;
// uint256 durationInMinutes; // address where funds are collected address public wallet; // token address address public addressOfTokenUsedAsReward;
uint256 public price = 200;//initial price
token tokenReward;
mapping (address => uint) public contributions;
// start and end timestamps where investments are allowed (both inclusive) // uint256 public startTime; // uint256 public endTime; // amount of raised money in wei uint256 public weiRaised; uint256 public tokensSold;
/** * event for token purchase logging * @param purchaser who paid for the tokens * @param beneficiary who got the tokens * @param value weis paid for purchase * @param amount amount of tokens purchased */ event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
function Crowdsale() { //DO NOT FORGET TO CHANGE THIS //This is the wallet where all the ETH will go! wallet = 0x1E84B88b8AB048ff2Bf20284EC95217ce4f87B89;//this should be Filips wallet! // durationInMinutes = _durationInMinutes; //Here will come the checksum address we got addressOfTokenUsedAsReward = 0x39607EAc1EF8e9e931970a1522245779e45c866f; //address of the token contract //web3.toChecksumAddress is needed here in most cases.
tokenReward = token(addressOfTokenUsedAsReward);
}
bool public started = false;
function startSale(){ if (msg.sender != wallet) throw; started = true; }
function stopSale(){ if(msg.sender != wallet) throw; started = false; }
function setPrice(uint256 _price){ if(msg.sender != wallet) throw; price = _price; }
// fallback function can be used to buy tokens function () payable { buyTokens(msg.sender); }
// low level token purchase function function buyTokens(address beneficiary) payable { require(beneficiary != 0x0); require(validPurchase());
uint256 weiAmount = msg.value;
if(tokensSold < 10000*10**6){
price = 300;
}else if(tokensSold < 20000*10**6){
price = 273;
}else if(tokensSold < 30000*10**6){
price = 249;
}else if(tokensSold < 40000*10**6){
price = 228;
}else if(tokensSold < 50000*10**6){
price = 209;
}else if(tokensSold < 60000*10**6){
price = 192;
}else if(tokensSold < 70000*10**6){
price = 177;
}else if(tokensSold < 80000*10**6){
price = 164;
}else if(tokensSold < 90000*10**6){
price = 153;
}else if(tokensSold < 100000*10**6){
price = 143;
}else if(tokensSold < 110000*10**6){
price = 135;
}else if(tokensSold < 120000*10**6){
price = 128;
}else if(tokensSold < 130000*10**6){
price = 122;
}else if(tokensSold < 140000*10**6){
price = 116;
}else if(tokensSold < 150000*10**6){
price = 111;
}else if(tokensSold < 160000*10**6){
price = 106;
}else if(tokensSold < 170000*10**6){
price = 102;
}else if(tokensSold < 180000*10**6){
price = 98;
}else if(tokensSold < 190000*10**6){
price = 94;
}else if(tokensSold < 200000*10**6){
price = 91;
}else if(tokensSold < 210000*10**6){
price = 88;
}else if(tokensSold < 220000*10**6){
price = 86;
}else if(tokensSold < 230000*10**6){
price = 84;
}else if(tokensSold < 240000*10**6){
price = 82;
}else if(tokensSold < 250000*10**6){
price = 80;
}else if(tokensSold < 260000*10**6){
price = 78;
}else if(tokensSold < 270000*10**6){
price = 76;
}else if(tokensSold < 280000*10**6){
price = 74;
}else if(tokensSold < 290000*10**6){
price = 72;
}else if(tokensSold < 300000*10**6){
price = 70;
}else if(tokensSold < 310000*10**6){
price = 68;
}else if(tokensSold < 320000*10**6){
price = 66;
}else if(tokensSold < 330000*10**6){
price = 64;
}else if(tokensSold < 340000*10**6){
price = 62;
}else if(tokensSold < 350000*10**6){
price = 60;
}else if(tokensSold < 360000*10**6){
price = 58;
}else if(tokensSold < 370000*10**6){
price = 56;
}else if(tokensSold < 380000*10**6){
price = 54;
}else if(tokensSold < 390000*10**6){
price = 52;
}else if(tokensSold < 400000*10**6){
price = 50;
}else if(tokensSold < 410000*10**6){
price = 49;
}else if(tokensSold < 420000*10**6){
price = 48;
}else if(tokensSold < 430000*10**6){
price = 47;
}else if(tokensSold < 440000*10**6){
price = 46;
}else if(tokensSold < 450000*10**6){
price = 45;
}else if(tokensSold < 460000*10**6){
price = 44;
}else if(tokensSold < 470000*10**6){
price = 43;
}else if(tokensSold < 480000*10**6){
price = 42;
}else if(tokensSold < 490000*10**6){
price = 41;
}else if(tokensSold < 500000*10**6){
price = 40;
}else if(tokensSold < 510000*10**6){
price = 39;
}else if(tokensSold < 520000*10**6){
price = 38;
}else if(tokensSold < 530000*10**6){
price = 37;
}else if(tokensSold < 540000*10**6){
price = 36;
}else if(tokensSold < 550000*10**6){
price = 35;
}else if(tokensSold < 560000*10**6){
price = 34;
}else if(tokensSold < 570000*10**6){
price = 33;
}else if(tokensSold < 580000*10**6){
price = 32;
}else if(tokensSold < 590000*10**6){
price = 31;
}else if(tokensSold < 600000*10**6){
price = 30;
}else if(tokensSold < 610000*10**6){
price = 29;
}else if(tokensSold < 620000*10**6){
price = 28;
}else if(tokensSold < 630000*10**6){
price = 27;
}else if(tokensSold < 640000*10**6){
price = 26;
}else if(tokensSold < 650000*10**6){
price = 25;
}else if(tokensSold < 660000*10**6){
price = 24;
}else if(tokensSold < 670000*10**6){
price = 23;
}else if(tokensSold < 680000*10**6){
price = 22;
}else if(tokensSold < 690000*10**6){
price = 21;
}else if(tokensSold < 700000*10**6){
price = 20;
}
//the price above is Token per ETH
// calculate token amount to be sent
uint256 tokens = (weiAmount/10**12) * price;//weiamount * price
require(tokens >= 1 * 10 ** 6); //1 token minimum
// update state
weiRaised = weiRaised.add(weiAmount);
tokenReward.transfer(beneficiary, tokens);
tokensSold = tokensSold.add(tokens);//now we can track the number of tokens sold.
TokenPurchase(msg.sender, beneficiary, weiAmount, tokens);
forwardFunds();
}
// send ether to the fund collection wallet // override to create custom fund forwarding mechanisms function forwardFunds() internal { // wallet.transfer(msg.value); if (!wallet.send(msg.value)) { throw; } }
// @return true if the transaction can buy tokens function validPurchase() internal constant returns (bool) { bool withinPeriod = started; bool nonZeroPurchase = msg.value != 0; return withinPeriod && nonZeroPurchase; }
function withdrawTokens(uint256 _amount) { if(msg.sender!=wallet) throw; tokenReward.transfer(wallet,_amount); } }
But I don't think there's a problem with this contract. I have a problem with transferring the tokens to it, because wallet.ethereum.org doesn't show me the tokens at all - the balance is 0 and I can't send them. Also, when trying to do it via MyEtherWallet it says the ERC20 Token is not valid - so there has to be a problem somewhere, but neither you or me seem to see it :/ Also: Sorry, I can't manage to format it