I am sending ETH on Rinkeby network from my wallet in Metamask to a contract that has been deployed on Rinkeby. This is a crowdsale contract based on Open Zeppelin.
However when I check the transaction details on Etherscan, I get the following error:
TxReceipt Status: Fail
How do I find out the problem?
Update
Metamask's suggested gas amount is always unusually high when the transaction is to fail...
ETH was sent to the TestTokenSale.sol
contract.
Rinkeby transaction: 0xbbcff212c72e201412a3c4f4304d13e517212b793f04ae597399d2f375052b36
geth debug.traceTransaction: [Gist]
The TestToken.sol
is first deployed, followed by TestTokenSale.sol
TestToken.sol
Constructor Arguments: 'qwe', 'qwe, 'qwe', 123
pragma solidity ^0.4.15;
import "./libs/zeppelin/token/MintableToken.sol";
contract TestToken is MintableToken {
string public name;
string public symbol;
uint8 public constant decimals = 18;
string public constant version = "1.0";
string public location;
uint8 public power;
uint256 public constant tokenUnit = 10 ** 18;
function TestToken(string _name, string _symbol, string _location, uint8 _power) {
name = _name;
symbol = _symbol;
location = _location;
power = _power;
}
}
TestTokenSale.sol
Constructor arguments: 1520889758, 1530889758, 500, 10000000, 0xcede48d8ac162d1b08ed9419010de3c99f2cfdd6, 0x37b925b6c72cc313bea41b95629b74478d9d442b
pragma solidity ^0.4.15;
import "./libs/zeppelin/crowdsale/CappedCrowdsale.sol";
import "./libs/zeppelin/crowdsale/FinalizableCrowdsale.sol";
import './TestToken.sol';
contract TestTokenSale is CappedCrowdsale, FinalizableCrowdsale {
address public tokenContractAddress;
function TestTokenSale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _cap, address _wallet, address _tokenContractAddress)
CappedCrowdsale(_cap)
FinalizableCrowdsale()
Crowdsale(_startTime, _endTime, _rate, _wallet)
{
tokenContractAddress = _tokenContractAddress;
}
function createTokenContract(address tokenContractAddress) internal returns (MintableToken) {
return TestToken(tokenContractAddress);
}
function finalization() internal {
}
}
Update 2
ETH send to TestTokenSale.sol
still fails...
Tx: 0x640771750ded31c0ef817d1e0df3a1ec16c186fd353a6034dd1799af26e486ed
TestTokenSale.sol
Constructor arguments: 1511235849, 1530889758, 500, 10000000, 0xcede48d8ac162d1b08ed9419010de3c99f2cfdd6, 0x47a27fb4722f293b7ab499ef910d1f2ca78b94b6
pragma solidity ^0.4.15;
import "./libs/zeppelin/crowdsale/CappedCrowdsale.sol";
import "./libs/zeppelin/crowdsale/FinalizableCrowdsale.sol";
import './TestToken.sol';
contract TestTokenSale is CappedCrowdsale, FinalizableCrowdsale {
address public tokenContractAddress;
function TestTokenSale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _cap, address _wallet, address _tokenContractAddress)
CappedCrowdsale(_cap)
FinalizableCrowdsale()
Crowdsale(_startTime, _endTime, _rate, _wallet)
{
token = TestToken(_tokenContractAddress);
}
function finalization() internal {
}
}
Update 3
Tx: 0x561f9cb4630905c2bb1391db3d3d1afd3b29cc454b238b25dbc3372f19c4a274
ETH sends successfully to TestTokenSale.sol
contract only if Crowdsale.sol
was edited to comment out require(validPurchase())
:
Code works
function buyTokens(address beneficiary) public payable {
require(beneficiary != address(0));
// require(validPurchase());
...
Code fails
ETH send will fail if I dont comment out that line, but instead set validPurchase()
to return true
:
function buyTokens(address beneficiary) public payable {
require(beneficiary != address(0));
require(validPurchase());
...
function validPurchase() internal constant returns (bool) {
return true;
// bool withinPeriod = now >= startTime && now <= endTime;
// bool nonZeroPurchase = msg.value != 0;
// return withinPeriod && nonZeroPurchase;
}
Code works!!!
// low level token purchase function
function buyTokens(address beneficiary) public payable {
require(beneficiary != address(0));
require(now >= startTime);
require(now <= endTime);
require(msg.value != 0);
// require(validPurchase());
Shouldnt require(validPurchase())
not throw any errors if validPurchase()
returns true
?
Why does it work if the 3 conditions are moved from validPurchase()
out to buyTokens
, but dont work when they are inside `validPurchase()~?
What's happening here?
0xbbcff212c72e201412a3c4f4304d13e517212b793f04ae597399d2f375052b36
. Do you see anything wrong with the contract code?Crowdsale()
which in turn will callcreateTokenContract()
which will returnTestToken(tokenContractAddress)
, but it will return 0x0, becausetokenContractAddress
is not yet initialzed. Drop variabletokenContractAddress
and assign directly in your constructortoken = MintableToken(_tokenContractAddress);
createTokenContract
?