I am trying to write an Ethereum contract and I am able to migrate the contract without any problem, but I am facing a problem that I don’t understand. I am not able to buy tokens because gas price is high. I don’t understand what is wrong. Please help.
2_deploy_contracts.js
const TestTokenCrowdsale = artifacts.require('./TestTokenCrowdsale.sol');
var walletAddress =
require('fs').readFileSync('../keystore/address').toString();
const duration = {
seconds: function(val) { return val},
minutes: function(val) { return val * this.seconds(60) },
hours: function(val) { return val * this.minutes(60) },
days: function(val) { return val * this.hours(24) },
weeks: function(val) { return val * this.days(7) },
years: function(val) { return val * this.days(365)}
};
module.exports = function(deployer) {
const startTime = 1515896330 + duration.minutes(5);
const endTime = startTime + duration.minutes(20);
const rate = new web3.BigNumber(2);
const cap = new web3.BigNumber(1000000000000000000);
const tokenAddress = '****';
deployer.deploy(TestTokenCrowdsale, startTime, endTime, rate, cap, walletAddress, tokenAddress);
}
TestTokenCrowdsale.sol
pragma solidity ^0.4.18;
import 'zeppelin-solidity/contracts/crowdsale/CappedCrowdsale.sol';
import './TestToken.sol';
contract TestTokenCrowdsale is CappedCrowdsale {
address public tokenAddress;
FrontierToken public testToken;
/**
* @dev Crowdsale initializer.
* @param _startTime -> Crowdsale start time in UNIX seconds.
* @param _endTime -> Crowdsale end time in UNIX seconds.
* @param _rate -> TST/ETH exchange rate.
* @param _cap -> Fund cap in Wei.
* @param _wallet -> Wallet to collect Ether.
* @param _tokenAddress -> Deployed TestToken address.
*/
function TestTokenCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, uint256 _cap, address _wallet, address _tokenAddress)
CappedCrowdsale(_cap)
Crowdsale(_startTime, _endTime, _rate, _wallet) public {
tokenAddress = _tokenAddress;
token = createTokenContract();
}
function createTokenContract() internal returns (MintableToken) {
testToken = TestToken(tokenAddress);
return TestToken(tokenAddress);
}
}
TestToken.sol
pragma solidity ^0.4.18;
import 'zeppelin-solidity/contracts/token/MintableToken.sol';
import 'zeppelin-solidity/contracts/token/BurnableToken.sol';
contract FrontierToken is MintableToken, BurnableToken {
string public name = "Test Token";
string public symbol = "TST";
uint8 public decimals = 18;
}
The error I am getting is as follows:
truffle(develop)> c.buyTokens("0x627306090abab3a6e1400e9345bc60c78a8bef57", {value: 0.00000000000001})
Error: Error: sender doesn't have enough funds to send tx. The upfront cost is: 1188468318377797839569896498995073345436650825553660099636 and the sender's account only has: 99249141200000000000
at runCall (/usr/local/lib/node_modules/truffle/build/chain.bundled.js:67228:10)
at /usr/local/lib/node_modules/truffle/build/chain.bundled.js:14393:24
at replenish (/usr/local/lib/node_modules/truffle/build/chain.bundled.js:11525:17)
at iterateeCallback (/usr/local/lib/node_modules/truffle/build/chain.bundled.js:11510:17)
at /usr/local/lib/node_modules/truffle/build/chain.bundled.js:11485:16
at /usr/local/lib/node_modules/truffle/build/chain.bundled.js:14398:13
at /usr/local/lib/node_modules/truffle/build/chain.bundled.js:63440:16
at replenish (/usr/local/lib/node_modules/truffle/build/chain.bundled.js:63387:25)
at /usr/local/lib/node_modules/truffle/build/chain.bundled.js:63396:9
at eachLimit (/usr/local/lib/node_modules/truffle/build/chain.bundled.js:63320:36)
at Object.InvalidResponse (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:41484:16)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:329530:36
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:325200:9
at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:328229:7)
at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:176415:18)
at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:176705:12)
at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:176860:12)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:176820:24)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)