4

I'm using the crowdsale contract (https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/crowdsale/Crowdsale.sol). I have deployed a detailedERC20 smart contract. When I send the ether to the crowdsale contract it shows me the following error: SafeERC20: low-level call failed

When I use transfer() externally it works fine.

computer Environment Ganache-cli

6

2 Answers 2

3

Potential areas to look at which could be causing your problem when using the default emission Crowdsale:

  • Set an appropriate rate
  • Need to transfer (enough) tokens to the Crowdsale

For information on the rate: https://docs.openzeppelin.org/v2.3.0/crowdsales#crowdsale-rate

Understanding the rate of a crowdsale is super important, and mistakes here are a common source of bugs.

✨ HOLD UP FAM THIS IS IMPORTANT ✨

Firstly, all currency math is done in the smallest unit of that currency and converted to the correct decimal places when displaying the currency.

For information on default emission: https://docs.openzeppelin.org/v2.3.0/crowdsales#default-emission

In the default scenario, your crowdsale must own the tokens that are sold.

I recommend reading through the OpenZeppelin documentation on Crowdsales: https://docs.openzeppelin.org/v2.3.0/crowdsales

If you have more questions about OpenZeppelin you can always ask in the community forum

1
  • 2
    I think the problem is that crowdsale smart contract doesn't have enough tokens. Hence transfer is reverted. Jun 29, 2019 at 17:58
0

The crowdsale token balance is lower, And you need to consider the value that you're passing as the smallest unit which is wei.

this is not working

var amount = web3.utils.toWei('1', 'ether');
await this.crowdsale.buyTokens(accounts[1], { value: amount });

this works

var amount = web3.utils.toWei('1', 'wei');

await this.crowdsale.buyTokens(accounts[1], { value: amount });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.