How to get Ether funds after Refundable Crowdsale?

Testnet: Rinkeby
Address token: 0xeAD7ACF95b260E4C866a036F9E792759Ba0Ad4ce
Address Crowdsale:0xf2D4B282CE60A0abBE7fb74C694A9A04087E5519

Ethers credited at the end of Crowdsale: 0x8be6c677cd26d8836bf75bf22fa651c463072a61

Token and Crowdsale implemented in OpenZeppelin 2.5

  1. How can I take ether to the contract creator’s wallet?
  2. How to make a refund if the amount collected is less than SoftCup?
  3. What code should I add to limit the minimum and maximum investor contribution? (IndividuallyCappedCrowdsale ?)

The code:

pragma solidity ^0.5.5;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/crowdsale/Crowdsale.sol";
import "@openzeppelin/contracts/crowdsale/emission/AllowanceCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/validation/TimedCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/distribution/RefundableCrowdsale.sol";
import "@openzeppelin/contracts/crowdsale/validation/CappedCrowdsale.sol";

contract Sale is Crowdsale, AllowanceCrowdsale, TimedCrowdsale, CappedCrowdsale, RefundableCrowdsale {  
    uint256 _rate,
    address payable _wallet,
    ERC20 _token,
    address _tokenWallet,
    uint256 _openingTime,
    uint256 _closingTime,
    uint256 _cap,
    uint256 _goal
    Crowdsale(_rate, _wallet, _token)
    TimedCrowdsale(_openingTime, _closingTime)
    require(_goal <= _cap);  
1 Like

Hi @Genry,

Welcome to the community :wave:

I recommend going through: Points to consider when creating a fungible token (ERC20, ERC777)

Once the crowdsale has ended you can call finalize, this will transfer the funds or allow refunds if the goal is not met.

You should create unit tests to check this.

You should use RefundablePostDeliveryCrowdsale rather than RefundableCrowdsale

Note that if you allow tokens to be traded before the goal is met, then an attack is possible in which the attacker purchases tokens from the crowdsale and when they sees that the goal is unlikely to be met, they sell their tokens (possibly at a discount). The attacker will be refunded when the crowdsale is finalized, and the users that purchased from them will be left with worthless tokens.

RefundablePostDeliveryCrowdsale will refund participants if the goal is not met.

You should create unit tests to check this.

You can use IndividuallyCappedCrowdsale. For a minimum, you could check using _preValidatePurchase-address-uint256.

You should create unit tests to check this.

Thanks for answers!
Where can I see an example implementation using _preValidatePurchase?

1 Like

Hi @Genry,

If you look at the extensions to Crowdsales for examples of how to use. We override the function, call super and add any of our own validation:

1 Like