0

I'm trying to create a contract, and set its owner at the same time

contract ERC721CrowdSale is Ownable { ... }//contract is in the same file and has access to methods


contract CS_Creator is Ownable{
  ERC721CrowdSale _cs;

  function create_crowdsale(string _name, address _wallet, uint256 _token_goal) onlyOwner returns(address){
      address _new_crowdsale = new ERC721CrowdSale(_name,  _wallet,  _token_goal);
      transfer_CS_ownership(_new_crowdsale, _wallet);
      return _new_crowdsale;
  }

  function transfer_CS_ownership (address _new_crowdsale, address _wallet)  internal {
     _cs = ERC721CrowdSale(_new_crowdsale);
    _cs.transferOwnership(_wallet);
  }
}

this creates the crowdsale, but in remix i get an error when i try any methods on the crowdsale

transact to ERC721CrowdSale.(fallback) errored: Cannot read property 'length' of undefined

I just need a convenient way to transfer the ownership of the crowdsale to the wallet address. Right now they are all owned by CS_Creator

0

I have run the code in remix with the according complements for owner and ERC721CrowdSale and your code worked fine. I only slightly modified your contract so that I would get the value of the current owner of the crowdsale returned by the function create_crowdsale(...).

pragma solidity ^0.4.19;

contract Ownable {

    address public owner;

    function Ownable() public {
        owner = msg.sender;
    }

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }

    function transferOwnership(address _newOwner) public onlyOwner {
        owner = _newOwner;
    }
}

contract ERC721CrowdSale is Ownable {

    string public name;
    address public wallet;
    uint256 public token_goal;

    function ERC721CrowdSale(string _name, address _wallet, uint256 _token_goal) public {
        name = _name;
        wallet = _wallet;
        token_goal = _token_goal;
    }
    //...

}

contract CS_Creator is Ownable{
  ERC721CrowdSale _cs;

  function create_crowdsale(string _name, address _wallet, uint256 _token_goal) onlyOwner returns(address, address){
      address _new_crowdsale = new ERC721CrowdSale(_name,  _wallet,  _token_goal);
      transfer_CS_ownership(_new_crowdsale, _wallet);
      return (_new_crowdsale, get_CS_ownership(_new_crowdsale));
  }

  function transfer_CS_ownership(address _new_crowdsale, address _wallet)  internal {
      _cs = ERC721CrowdSale(_new_crowdsale);
      _cs.transferOwnership(_wallet);
  }

  function get_CS_ownership(address _crowdsale) public returns(address) {
      return ERC721CrowdSale(_crowdsale).owner();
  }
}

As a return value for the crowdsale owner I get the value for the wallet address.

I could imagine that you actually created a contract ERC721CrowdSale in remix and then were checking there whether the owner address had changed, after deploying CS_Creator. If so: in this case you are creating a new instance of the contract ERC721CrowdSale with the function create_crowdsale(...) which, therefore, is completely independent from the other ERC721CrowdSale contract, you deployed earlyer. The owner address, however, is only changed in the instance, created by the function create_crowdsale(...).

Hope it helps!

  • So everything appears to work for me, until I create the Crowdsale 'at address" and click on any of the functions (with the remix GUI) and i get the error transact to ERC721CrowdSale.(fallback) errored: Cannot read property 'length' of undefined – Barrard Apr 11 '18 at 4:58
  • Well, it actually worked on the Rinkeby Test-net, as opposed to the JVM. The joys of working with new technology. Spent many hours playing with this code, only to realize it wasn't broken. – Barrard Apr 11 '18 at 5:43

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.