Remix Gas limit exceeded regardless of how high I set it
Remix Gas limit exceeded regardless of how high I set it
Loading saved threads...
darknightsy · External communityPost link
External question — Ethereum Stack Exchange
Author: darknightsy
Original post: https://ethereum.stackexchange.com/questions/38055
License: CC BY-SA 3.0 — https://creativecommons.org/licenses/by-sa/3.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I am deploying a crowdsale contract in Remix but no matter how high I set the gas limit (set it to 40000000 once) or even how much I change the value field I can't get this contract to not exceed the gas limit. The other contract I deployed was much larger and it deployed fine so I am thinking there is something wrong with my code. Here it is
pragma solidity ^0.4.19;
/**
* @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 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;
/**
* @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 {
require(newOwner != address(0));
owner = newOwner;
}
}
/**
* @title Token
* @dev API interface for interacting with the BQPOT Token contract
*/
interface Token {
function transfer(address _to, uint256 _value) returns (bool);
function balanceOf(address _owner) constant returns (uint256 balance);
}
contract Crowdsale is Ownable {
using SafeMath for uint256;
Token token;
uint256 public constant RATE = 1000; //Tokens per Ether
uint256 public constant CAP = 73; //Cap in Ether
uint256 public constant START = 1517383764; //Must change for timestamp
uint256 public DAYS = 1; //Preorder lasts for 14 DAYS
bool public initialized = false;
uint256 public raisedAmount = 0;
// Who bought tokens and how many?
event BoughtTokens(address indexed to, uint256 value);
//Is the sale active?
modifier whenSaleIsActive() {
assert(isActive());
_;
}
//Pass in token contract address
function Crowdsale(address _tokenAddr){
require(_tokenAddr !=0);
token = Token(_tokenAddr);
}
//Makes sure there is correct amount of tokens sent to address
function initialize(uint256 numTokens) onlyOwner {
require(initialized == false);
require(tokensAvailable() ==numTokens); //Make sure tokens are available
initialized = true; //If they check out set initialize to true
}
function isActive() constant returns (bool) {
return (
initialized == true && //Is contract initialized?
now >= START && //To be active it must be after the start date
now <= START.add(DAYS * 1 days) && //Before end date
goalReached() == false //Also Goal is not yet reached
);
}
function goalReached() constant returns (bool) {
return (raisedAmount >= CAP * 1 ether);
}
function () payable {
buyTokens();
}
function buyTokens() payable whenSaleIsActive{
uint256 weiAmount = msg.value;
uint256 tokens = weiAmount.mul(RATE);
BoughtTokens(msg.sender, tokens);
//Add to amount raised
raisedAmount = raisedAmount.add(msg.value);
//Send buyer tokens
token.transfer(msg.sender, tokens);
//Send ether to owner
owner.transfer(msg.value);
}
//Return number of tokens allocated to contract
function tokensAvailable() constant returns (uint256) {
return token.balanceOf(this);
}
//Stop contract and refund the owner
function destroy() onlyOwner {
//Send rest of tokens to the owner
uint256 balance = token.balanceOf(this);
assert(balance > 0);
token.transfer(owner, balance);
//Incase ether is left in contract
selfdestruct(owner);
}
}
Quote
Report
Asone · External communityPost link
External answer — Ethereum Stack Exchange
Author: Asone
Original post: https://ethereum.stackexchange.com/a/38069
License: CC BY-SA 3.0 — https://creativecommons.org/licenses/by-sa/3.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I'm not sure but could be this :
When deploying you instance the following instruction :
token = Token(_tokenAddr);
However Token is defined as the following :
interface Token {
function transfer(address _to, uint256 _value) returns (bool);
function balanceOf(address _owner) constant returns (uint256 balance);
}
I'd see two points here :
This is an interface, not a contract and so shouldn't be used as instanciable directly ( it should be used to base another contract ).
Even if it wasn't an Interface there is not constructor in it, and event with constructor, you should have to specify an argument in the signature call of the constructor as you pass an argument on deployment.
Quote
Report
Chan-Ho Suh · External communityPost link
External answer — Ethereum Stack Exchange
Author: Chan-Ho Suh
Original post: https://ethereum.stackexchange.com/a/78910
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I deployed your
CrowdSale
contract in Remix IDE using the Javascript VM with no issues.
creation of Crowdsale pending...
[vm]from:0xca3...a733cto:Crowdsale.(constructor)value:0 wei data:0x608...77b3alogs:0hash:0x650...40b38
status 0x1 Transaction mined and execution succeed
transaction hash 0x65017f107f3c5309590ff765861ad0dd0f6bb2b6bee5c60bf99c5bdbe0340b38
contract address 0xbbf289d846208c16edc8474705c748aff07732db
from 0xca35b7d915458ef540ade6068dfe2f44e8fa733c
to Crowdsale.(constructor)
gas 3000000 gas
transaction cost 941985 gas
execution cost 677381 gas
hash 0x65017f107f3c5309590ff765861ad0dd0f6bb2b6bee5c60bf99c5bdbe0340b38
input 0x608...77b3a
decoded input {
"address _tokenAddr": "0x692a70D2e424a56D2C6C27aA97D1a86395877b3A"
}
decoded output -
logs []
value 0 wei
I think without further details of how you're deploying, e.g. environment, other contract deployment, there's no way to troubleshoot this further.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Ethereum Stack Exchange Author: Asone Source score (net votes, not local likes): 0 Original post: https://ethereum.stackexchange.com/a/38069 License: CC BY-SA 3.0 — https://creativecommons.org/licenses/by-sa/3.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I'm not sure but could be this : When deploying you instance the following instruction : token = Token(_tokenAddr); However Token is defined as the following : interface Token { function transfer(address _to, uint256 _value) returns (bool); function balanceOf(address _owner) constant returns (uint256 balance); } I'd see two points here : This is an interface, not a contract and so shouldn't be used as instanciable directly ( it should be used to base another contract ). Even if it wasn't an Interface there is not constructor in it, and event with constructor, you should have to specify an argument in the signature call of the constructor as you pass an argument on deployment.
Checking account access…