Blockchain 开放式齐柏林飞艇+;Truffle Ethereum Crowdsale buyTokens()函数的预付成本

Blockchain 开放式齐柏林飞艇+;Truffle Ethereum Crowdsale buyTokens()函数的预付成本,blockchain,ethereum,smartcontracts,truffle,Blockchain,Ethereum,Smartcontracts,Truffle,我正试图写一份以太坊众售合同,我正试图绑定到之前迁移到Ropsten testnet的现有令牌,但我遇到了一个我无法解决的问题。我可以迁移这两个合同没有问题,但我不能购买代币,因为汽油价格高得离谱。下面是我的代码,以及我在尝试调用buyTokens()函数时遇到的错误: truffle控制台中出现错误: truffle(develop)> c.buyTokens("0x627306090abab3a6e1400e9345bc60c78a8bef57", {value: 0.00000000

我正试图写一份以太坊众售合同,我正试图绑定到之前迁移到Ropsten testnet的现有令牌,但我遇到了一个我无法解决的问题。我可以迁移这两个合同没有问题,但我不能购买代币,因为汽油价格高得离谱。下面是我的代码,以及我在尝试调用buyTokens()函数时遇到的错误:

truffle控制台中出现错误:

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)
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;
}

我已确保在startTime之后和endTime之前调用该函数,并且每次在迁移契约之前都会更新2_deploy_contracts.js中的startTime。我这样做是为了尽可能少地依赖于调试此代码。我还要确保我发送的Wei少于cap。“c”是我使用deployed()函数得到的已部署契约。感谢您的帮助,干杯

您没有正确发送
值。您需要使用
web3.utils.toWei(0.00000000000001,'ether')

简化版本:

pragma solidity ^0.4.18;

contract Test {
  uint256 public balance;

  function somePayable() public payable {
    balance = msg.value;
  }
}
pragma solidity ^0.4.18;

contract Test {
  uint256 public balance;

  function somePayable() public payable {
    balance = msg.value;
  }
}
truffle(development)> var c
undefined

truffle(development)> Test.deployed().then(i => c = i);
...Output Truncated...

truffle(development)> c.somePayable({from: web3.eth.accounts[0], value: 0.0001})
Error: Error: sender doesn't have enough funds to send tx. The upfront cost is: 1188468318377797841622495538693466475719926236618134981990 and the senders account only has: 299763510000000000000

truffle(development)> c.somePayable({from: web3.eth.accounts[0], value: web3.toWei(0.0001, 'ether')});
{ tx: '0x4bd0e15e22a6a0af3a7cea6c57de18bad0d58cdec27e5a7721234d8ac91c09d4',
  receipt:
   { transactionHash: '0x4bd0e15e22a6a0af3a7cea6c57de18bad0d58cdec27e5a7721234d8ac91c09d4',
     transactionIndex: 0,
     blockHash: '0x76e5c94eced759feb22a511c14fe5ab27f8572b4efc6f0acb5c7e060b922e99f',
     blockNumber: 11,
     gasUsed: 41416,
     cumulativeGasUsed: 41416,
     contractAddress: null,
     logs: [] },
  logs: [] }