0

I have created a "Token" and the "Crowdsale" contract as mentioned in the openzeppelin. Below is my deployment code in truffle. I am new to ICO related coding and solidity. The question may be very simple but I am trying hard to find a answer, could you please assist?

Question

  1. I understand the Crowd sale contract needs to have ownership of the token contract. Is it correct ?

  2. If the ownership has to be transferred, how to do that while deploying itself ?

How to transfer the ownership of the token contract

2_deploy_ico.js

return deployer
.then(() => { 
return deployer.deploy(SampleCrowdsaleToken, "Sample Crowdsale Token","SCT",18);
})
.then(() => { 
console.log("Token Address : ",SampleCrowdsaleToken.address) ;
return deployer.deploy(SampleCrowdsale,openingTime,closingTime,rate,wallet,cap,SampleCrowdsaleToken.address,goal);
}).then(() => { 
console.log("Sale Address : ",SampleCrowdsale.address) ;
// TODO: transfer ownerhship of the token to the crowdsale for minting
// Currently doing that in the UI
SampleCrowdsaleToken.transferOwnership(SampleCrowdsale.address);
console.log("!!! Success !!!") ;

});

1 Answer 1

1

Does the Crowdsale contract need to own the token contract?

Not necessarily. It is not a requirement that the Crowdsale contract actually owns the Token contract. You can simply mint/transfer tokens to the Crowdsale contract, which will then be responsible to sell the tokens.

A standard Crowdsale implementation and deployment methodology can be found here: https://www.ethereum.org/crowdsale. It is a very good starting point to get the basics of ICO contracts architecture.

Anyway, how can you transfer contract ownership?

You are probably calling the right method in the deployment script. However you are not calling it on the specific instance of the contract that you deployed. You need to use something like

.then((deployedInstance) => deployedInstance.transferOwnership(...));

Straight after the deployer.deploy(...) call, to call the deployed instance. Hope this helps.

5
  • Thomas, how to create deployedInstance
    – iappmaker
    Commented Oct 26, 2018 at 11:28
  • Actually you created it already ;) it's the argument that gets passed to then() after the deployer.deploy call. So you just need to place the word deployedInstance within the empty parentheses of the third then() statement. Commented Oct 27, 2018 at 10:24
  • in the 3rd then we will get the return from the 2nd then right ? I need both the instance in the 3rd then
    – iappmaker
    Commented Oct 27, 2018 at 10:52
  • in the 3rd then we will get the return from the 2nd then right ? I need both the instance in the 3rd then
    – iappmaker
    Commented Oct 27, 2018 at 10:53
  • Yes exactly. If you want to save the instances across the then blocks, the best way is probably to declare "let" variables on top of the script, then assign the deployed instances to these variables as you go. This way you still get access to the instances in all blocks of your code. Commented Oct 28, 2018 at 9:08

Your Answer

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

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