1

I'm using this contract code and want to create ico contract. But when I create contract code and try to transfer eth I'm getting error. I can't transfer ethereum to ico contract address.

Warning! Error encountered during contract execution [Bad jump destination]

can you help me ?

pragma solidity ^0.4.6;

import "./ABCToken.sol";
import "./SafeMath.sol";

ABCToken public ABCToken;

// Address of the founder of ABC.
address public founder = 0x3311111111111111111111111111111111111133;

// Address where all tokens created during ICO stage initially allocated
address public allocationAddress = 0x2111111111111111111111111111111111111111;

// Start date of the ICO
uint public startDate = 1524528001;  

// End date of the ICO
uint public endDate = 1535068801;  

// Token price without discount during the ICO stage
uint public baseTokenPrice = 10000000; // 0.001 ETH, considering 8 decimal places

// Number of tokens distributed to investors
uint public tokensDistributed = 0;

/*
 *  Modifiers
 */
modifier onlyFounder() {
    // Only founder is allowed to do this action.
    if (msg.sender != founder) {
        throw;
    }
    _;
}

modifier minInvestment(uint investment) {
    // User has to send at least the ether value of one token.
    if (investment < baseTokenPrice) {
        throw;
    }
    _;
}

/// @dev Returns current bonus
function getCurrentBonus()
    public
    constant
    returns (uint)
{
    return getBonus(now);
}

/// @dev Returns bonus for the specific moment
/// @param timestamp Time of investment (in seconds)
function getBonus(uint timestamp)
    public
    constant
    returns (uint)
{   
    if (timestamp > endDate) {
        throw;
    }

    if (startDate > timestamp) {
        return 1499;  // 49.9%
    }

    uint icoDuration = timestamp - startDate;
    if (icoDuration >= 16 days) {
        return 1000;  // 0%
    } else if (icoDuration >= 9 days) {
        return 1125;  // 12.5%
    } else if (icoDuration >= 2 days) {
        return 1250;  // 25%
    } else {
        return 1499;  // 49.9%
    }
}

function calculateTokens(uint investment, uint timestamp)
    public
    constant
    returns (uint)
{
    // calculate discountedPrice
    uint discountedPrice = div(mul(baseTokenPrice, 1000), getBonus(timestamp));

    // Token count is rounded down. Sent ETH should be multiples of baseTokenPrice.
    return div(investment, discountedPrice);
}


/// @dev Issues tokens for users who made BTC purchases.
/// @param beneficiary Address the tokens will be issued to.
/// @param investment Invested amount in Wei
/// @param timestamp Time of investment (in seconds)
function fixInvestment(address beneficiary, uint investment, uint timestamp)
    external
    onlyFounder
    minInvestment(investment)
    returns (uint)
{   

    // Calculate number of tokens to mint
    uint tokenCount = calculateTokens(investment, timestamp);

    // Update fund's and user's balance and total supply of tokens.
    tokensDistributed = add(tokensDistributed, tokenCount);

    // Distribute tokens.
    if (!ABCToken.transferFrom(allocationAddress, beneficiary, tokenCount)) {
        // Tokens could not be issued.
        throw;
    }

    return tokenCount;
}

/// @dev Contract constructor
function ABCICO(address tokenAddress, address founderAddress) {
    // Set token address
    ABCToken = ABCToken(tokenAddress);

    // Set founder address
    founder = founderAddress;
}

/// @dev Fallback function
function () payable {
    throw;
}

}

2 Answers 2

0

My assumption is that your only function marked as payable, the fallback function, throws, thus rejecting the eth transfer.

Have a look at this Register contract from the official documentation and see a nice example, with a brief explanation of how to use the payable keyword.

0

Ok I changed fallback function and solved problem but now Ico contract can't transfer me token. Contract is taking ethereum bot didn't transfer token.

IcoDuration is working I'm in +2 days period.

Your Answer

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

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