Closed athlona64 closed 7 years ago
Please don't copy paste your entire codebase here, or at least format it so that it's understandable. Can you please explain what your problem is more clearly in a new issue?
@maraoz You are right . Just paste error message or the entire code which you have issue.
as required exceeds limit: 3000000. An important gas estimation might also be the sign of a problem in the contract code. Please check loops and be sure you did not sent value to a non payable function (that's also the reason of strong gas estimation)
`pragma solidity ^0.4.11;
/**
@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; } }
/**
as they arrive. */ contract Crowdsale { using SafeMath for uint256;
// The token being sold MintableToken public token;
// start and end timestamps where investments are allowed (both inclusive) uint256 public startTime; uint256 public endTime;
// address where funds are collected address public wallet;
// how many token units a buyer gets per wei uint256 public rate;
// amount of raised money in wei uint256 public weiRaised;
/**
function Crowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet) { require(_startTime >= now); require(_endTime >= _startTime); require(_rate > 0); require(_wallet != address(0));
token = createTokenContract(); startTime = _startTime; endTime = _endTime; rate = _rate; wallet = _wallet; }
// creates the token to be sold. // override this method to have crowdsale of a specific mintable token. function createTokenContract() internal returns (MintableToken) { return new MintableToken(); }
// fallback function can be used to buy tokens function () payable { buyTokens(msg.sender); }
// low level token purchase function function buyTokens(address beneficiary) public payable { require(beneficiary != address(0)); require(validPurchase());
uint256 weiAmount = msg.value;
// calculate token amount to be created uint256 tokens = weiAmount.mul(rate);
// update state weiRaised = weiRaised.add(weiAmount);
token.mint(beneficiary, tokens); 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); }
// @return true if the transaction can buy tokens function validPurchase() internal constant returns (bool) { bool withinPeriod = now >= startTime && now <= endTime; bool nonZeroPurchase = msg.value != 0; return withinPeriod && nonZeroPurchase; }
// @return true if crowdsale event has ended function hasEnded() public constant returns (bool) { return now > endTime; }
} /**
@dev Extension of Crowdsale with a max amount of funds raised */ contract CappedCrowdsale is Crowdsale { using SafeMath for uint256;
uint256 public cap;
function CappedCrowdsale(uint256 _cap) { require(_cap > 0); cap = _cap; }
// overriding Crowdsale#validPurchase to add extra cap logic // @return true if investors can buy at the moment function validPurchase() internal constant returns (bool) { bool withinCap = weiRaised.add(msg.value) <= cap; return super.validPurchase() && withinCap; }
// overriding Crowdsale#hasEnded to add cap logic // @return true if crowdsale event has ended function hasEnded() public constant returns (bool) { bool capReached = weiRaised >= cap; return super.hasEnded() || capReached; }
}
/**
functions, this simplifies the implementation of "user permissions". */ contract Ownable { address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
owner
of the contract to the sender/**
/**
}
/**
after finishing. */ contract FinalizableCrowdsale is Crowdsale, Ownable { using SafeMath for uint256;
bool public isFinalized = false;
event Finalized();
/**
finalization(); Finalized();
isFinalized = true; }
/**
/**
and forwarding it if crowdsale is successful. */ contract RefundVault is Ownable { using SafeMath for uint256;
enum State { Active, Refunding, Closed }
mapping (address => uint256) public deposited; address public wallet; State public state;
event Closed(); event RefundsEnabled(); event Refunded(address indexed beneficiary, uint256 weiAmount);
function RefundVault(address _wallet) { require(_wallet != 0x0); wallet = _wallet; state = State.Active; }
function deposit(address investor) onlyOwner public payable { require(state == State.Active); deposited[investor] = deposited[investor].add(msg.value); }
function close() onlyOwner public { require(state == State.Active); state = State.Closed; Closed(); wallet.transfer(this.balance); }
function enableRefunds() onlyOwner public { require(state == State.Active); state = State.Refunding; RefundsEnabled(); }
function refund(address investor) public { require(state == State.Refunding); uint256 depositedValue = deposited[investor]; deposited[investor] = 0; investor.transfer(depositedValue); Refunded(investor, depositedValue); } }
/**
Uses a RefundVault as the crowdsale's vault. */ contract RefundableCrowdsale is FinalizableCrowdsale { using SafeMath for uint256;
// minimum amount of funds to be raised in weis uint256 public goal;
// refund vault used to hold funds while crowdsale is running RefundVault public vault;
function RefundableCrowdsale(uint256 _goal) { require(_goal > 0); vault = new RefundVault(wallet); goal = _goal; }
// We're overriding the fund forwarding from Crowdsale. // In addition to sending the funds, we want to call // the RefundVault deposit function function forwardFunds() internal { vault.deposit.value(msg.value)(msg.sender); }
// if crowdsale is unsuccessful, investors can claim refunds here function claimRefund() public { require(isFinalized); require(!goalReached());
vault.refund(msg.sender); }
// vault finalization task, called when owner calls finalize() function finalization() internal { if (goalReached()) { vault.close(); } else { vault.enableRefunds(); }
super.finalization(); }
function goalReached() public constant returns (bool) { return weiRaised >= goal; }
}
/**
/**
@dev Basic version of StandardToken, with no allowances. */ contract BasicToken is ERC20Basic { using SafeMath for uint256;
mapping(address => uint256) balances;
/**
// 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 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)) internal allowed;
/**
balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _to, _value); return true; }
/**
/**
/**
function decreaseApproval (address _spender, uint _subtractedValue) public 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; }
}
/**
contract MintableToken is StandardToken, Ownable { event Mint(address indexed to, uint256 amount); event MintFinished();
bool public mintingFinished = false;
modifier canMint() { require(!mintingFinished); _; }
/**
@return A boolean that indicates if the operation was successful. */ function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { totalSupply = totalSupply.add(_amount); balances[_to] = balances[_to].add(_amount); Mint(_to, _amount); Transfer(address(0), _to, _amount); return true; }
/**
/**
contract SampleCrowdsaleToken is MintableToken {
string public constant name = "Sample Crowdsale Token"; string public constant symbol = "SCTV2"; uint8 public constant decimals = 18;
}
/**
to ensure that subcontracts works together as intended. */ contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale {
function SampleCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _goal, uint256 _cap, address _wallet) CappedCrowdsale(_cap) FinalizableCrowdsale() RefundableCrowdsale(_goal) Crowdsale(_startTime, _endTime, _rate, _wallet) { //As goal needs to be met for a successful crowdsale //the value needs to less or equal than a cap which is limit for accepted funds require(_goal <= _cap); }
function createTokenContract() internal returns (MintableToken) { return new SampleCrowdsaleToken(); }
}`