I am understanding the ICO as explained in openzeppelin https://github.com/OpenZeppelin/openzeppelin-solidity/tree/master/contracts/examples

When I called the "Buy tokens" the beneficiary is getting the tokens but the "Ether" is reaching the an Escrow account.


  1. In the example contract where the Escrow account is getting created?

  2. Does the contract hold the private key of the escrow account?

  3. Please point me the code

Reference Transaction - https://ropsten.etherscan.io/tx/0xb7812ca370cec365b6e0e50fe97ff637f8fdefcf5a31a8ed3420f76e0133b41a#decodetab

enter image description here

enter image description here


_forwardFunds has been overwritten in RefundableCrowdsale

 * @dev Overrides Crowdsale fund forwarding, sending funds to escrow.
function _forwardFunds() internal {

take a look on RefundableCrowdsale's constructor

constructor(uint256 goal) internal {
    require(goal > 0);
    _escrow = new RefundEscrow(wallet());
    _goal = goal;

the escrow contract has 0xF65bafE7D13AC5c44D12B79E293DE85aa4Cfd7C4 address. that is why value was transferred to escrow address, but not to the wallet address

| improve this answer | |
  • Yes Aquila, 1.In the example contract where the Escrow account is getting created? 2.Does the contract hold the private key of the escrow account? 3.How the contract gains access over the escrow address ? – iappmaker Oct 27 '18 at 17:22
  • 1. In a constructor of RefundableCrowdsale contract -> _escrow = new RefundEscrow(wallet()); 2. Contract account doesn't have private key 3. take a look source code of RefundEscrow github.com/OpenZeppelin/openzeppelin-solidity/blob/master/… beneficiary (your wallet) can withdraw funds, when the escrow stopped – Aquila Oct 27 '18 at 17:32
  • In RefundEscrow constructor, I am unable to see the place where the escrow account is generated with a key pair. In the constructor, I see that they are checking require(beneficiary != address(0)); and saving the beneficiary. Where the escrow account comes into picture (I mean the key pair generation). Also as per the logic of blockchain I understand that the transactions in a address is possible only when we know the private key. Where it is generated and stored. The Question may me very basic but I would be happy if you could throw some light on it. Thanks in Advance ! – iappmaker Oct 27 '18 at 20:09
  • here is documentation ethdocs.org/en/latest/contracts-and-transactions/… it can be helpful to read it. contract account is not controlled by private key, it is controlled by code. contract can be created from another contract, the code _escrow = new RefundEscrow(wallet()); does it. you shouldn't have key-pair to do it from code. – Aquila Oct 27 '18 at 20:19
  • 1
    address(this) casts escrow contract to address (simply it gets address of escrow contract). _beneficiary.transfer(address(this).balance) transfers all ethers from escrow to beneficiary – Aquila Oct 28 '18 at 8:55

In the example you linked, the wallet receiving the Ether is in the Crowdsale contract. Each transaction forwards Ether to this address, called _wallet.

You are asking about how SampleCrowdsale.sol works. If you look at lines 48-51, you will see that this contract is simply created a capped and timed crowdsale that is refundable. It does this by creating each of those contacts that it imported at the top of the file.

To get to your answer, look at line 48, Crowdsale(rate, wallet, token). These three parameters are pass in when creating this top level contract. When line 48 gets executed, Crowdsale gets deployed with the given parameters.

Looking at Crowdsale.sol, you can see that its second parameter is wallet, which gets set equal to the global variable, _wallet upon contract creation. The comment above the declaration of _wallet states, Address where funds are collected, which tells you that this is where the Ether is going.

From here, you can look into the buyTokens() function that users call to contribute to the crowdsale. Line 140 calls the _forwardFunds() function that simply sends all of the Ether in that transaction to _wallet.

| improve this answer | |
  • Thanks for the details. Based on the explanation that you have given the escrow account is the account# that I have given in the constructor while creating the contract. But see my transaction details that I have added in the question now. I have passed the address "0x754839c59d9D2C5E3C8ce289E08d78A02af56E65" as wallet address to the contract. but It has routed the ethers to "0xF65bafE7D13AC5c44D12B79E293DE85aa4Cfd7C4" which I don't know from where it came. I understand "0xF65bafE7D13AC5c44D12B79E293DE85aa4Cfd7C4" is the escrow account. But which part of the code creates it is my question. – iappmaker Oct 27 '18 at 3:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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