Not able to send Ethereum transaction

0 votes

I write Crowdsale using this example. But I can't send a transaction, my test fails with an error:

 Contract: Crowdsale should accept payments after start:
     AssertionError: expected promise to be fulfilled but it was rejected with 'Error: VM Exception while processing the transaction: revert'

I tried to set gas price to the transaction like this crowdsale.sendTransaction({value, from: buyer, gas: 4712388}) but it doesn't help me.

My Crowdsale:

pragma solidity ^0.4.16;

interface token {
  function transfer(address receiver, uint amount) external;
}

contract Crowdsale {
  address public beneficiary;
  uint public fundingGoal;
  uint public amountRaised;
  uint public deadline;
  uint public price;
  token public tokenReward;
  mapping(address => uint256) public balanceOf;

  event FundTransfer(address backer, uint amount, bool isContribution);

  function Crowdsale(
    address ifSuccessfulSendTo,
    uint fundingGoalInEthers,
    uint durationInMinutes,
    uint etherCostOfEachToken,
    address addressOfTokenUsedAsReward
  ) public {
    beneficiary = ifSuccessfulSendTo;
    fundingGoal = fundingGoalInEthers * 1 ether;
    deadline = now + durationInMinutes * 1 minutes;
    price = etherCostOfEachToken * 1 ether;
    tokenReward = token(addressOfTokenUsedAsReward);
  }

  function () public payable {
    uint amount = msg.value;
    balanceOf[msg.sender] += amount;
    amountRaised += amount;
    tokenReward.transfer(msg.sender, amount / price);
    FundTransfer(msg.sender, amount, true);
  }
}

My tests (I use these tests as an example):

// You can find all those helpers here: https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/test/helpers
import ether from '../helpers/ether';
import { advanceBlock } from '../helpers/advanceToBlock';
import { increaseTimeTo, duration } from '../helpers/increaseTime';
import latestTime from '../helpers/latestTime';

const BigNumber = web3.BigNumber;

const should = require('chai')
  .use(require('chai-as-promised'))
  .use(require('chai-bignumber')(BigNumber))
  .should();

const Crowdsale = artifacts.require('Crowdsale');
const Coin = artifacts.require('Coin');

contract('Crowdsale', accounts => {
  let startTime;

  let crowdsale;
  let token;

  const value = ether(8);
  const buyer = accounts[1];
  const tokenReward = accounts[2];
  const beneficiary = accounts[2];

  before(async () => {
    // Advance to the next block to correctly read time in the solidity "now" function interpreted by testrpc
    await advanceBlock();
  });

  beforeEach(async () => {
    token = await Coin.new();

    // Transfer an amount to address of token used as reward
    const tokenRewardAmount = 1000000;
    token.transfer(tokenReward, tokenRewardAmount);

    startTime = latestTime() + duration.minutes(1);

    crowdsale = await Crowdsale.new(beneficiary, 200, 30, 1, tokenReward);
  });

  it('should accept payments after start', async () => {
    await increaseTimeTo(startTime);
    await crowdsale.sendTransaction({value, from: buyer, gas: 4712388}).should.be.fulfilled;
  });
});

My Coin:

pragma solidity ^0.4.19;

import 'zeppelin-solidity/contracts/token/ERC20/MintableToken.sol';

contract Coin is MintableToken {
  uint8 public decimals = 0;
  uint public initialSupply = 1000000 * 10 ** uint(decimals); // 1,000,000;
  string public name = "My Coin";
  string public symbol = "XMY";

  function Coin() public {
    totalSupply_ = initialSupply;
    balances[msg.sender] = totalSupply_;
  }
}
Sep 24, 2018 in Blockchain by digger
• 26,740 points
494 views

1 answer to this question.

0 votes

Hey, Change this line:

await crowdsale.sendTransaction({value, from: buyer, gas: 4712388}).should.be.fulfilled;

To this and done:

await web3.eth.sendTransaction({
  from: buyer, 
  to: crowdsale,
  value: value,  
  gas: 4712388
}).should.be.fulfilled;
answered Sep 24, 2018 by slayer
• 29,350 points

Related Questions In Blockchain

0 votes
1 answer

Not able to send ethers in private ethereum network

Your account is locked by default due ...READ MORE

answered Jan 9, 2019 in Blockchain by Omkar
• 69,210 points
866 views
0 votes
1 answer

Blockchain Hyperledger private key not able to send coins

From the code you posted, if(whichType == TX_SCRIPTHASH){//pay ...READ MORE

answered Sep 14, 2018 in Blockchain by digger
• 26,740 points
450 views
0 votes
1 answer

Not able send ether to my smart contract's address

It turns out that you need to create ...READ MORE

answered Sep 25, 2018 in Blockchain by slayer
• 29,350 points
1,319 views
0 votes
1 answer

Not able to invoke a contract in Ethereum Private chain using geth

Hope this helps: contract mortal { /* ...READ MORE

answered Oct 22, 2018 in Blockchain by Omkar
• 69,210 points
731 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,693 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,233 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,450 points
1,145 views
0 votes
1 answer

Ethereum wallet not able to make transaction

I can see that the nonce you ...READ MORE

answered Aug 9, 2018 in Blockchain by slayer
• 29,350 points
473 views
0 votes
1 answer

Not able to send payments using Blockchain API.

Try the following code. It should help ...READ MORE

answered Jul 31, 2018 in Blockchain by slayer
• 29,350 points
444 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP