0
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.13;

contract Carshop{
    constructor()
    {address[] carAssets;
    function createChildContract(string brand , string model) public payable{
        address newCarAsset = new CarAsset(brand, model, msg.sender);
        carAssets.push(newCarAsset);
    }
    function getDevelopedChildContracts() public view returns (address[]){
        return carAssets;
    }
    }

}
contract CarAsset{
    string public brand;
    string public model;
    string public owner;
    function CarAsset(string _brand, string _model, address _owner) public{
        brand = _brand;
        model = _model;
        owner = _owner;
    }
}

error facedParserError: Expected '(' but got identifier --> contracts/CarDealer.sol:7:14: | 7 | function createChildContract(string brand , string model) public payable{ | ^^^^^^^^^^^^^^^^^^^

1 Answer 1

1

I adjusted your smart contract code, adding some notes, in this way:

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.13;
    
contract Carshop{
    // NOTE: I moved outsite the constructor definition the declaration about 'carAssets' variable and 
    //       the two functions called 'createChildContract' and 'getDevelopedChildContract'.
    address[] carAssets;
    
    constructor() {      
    }

    function createChildContract(string memory brand, string memory model) public payable{
        // NOTE: I casted with 'address' keyword the new instance about CarAsset for retrieve the its address.
        address newCarAsset = address(new CarAsset(brand, model, msg.sender));
        carAssets.push(newCarAsset);
    }

    function getDevelopedChildContracts() public view returns (address[] memory){
        return carAssets;
    }
}

contract CarAsset{
    string public brand;
    string public model;
    // NOTE: I changed from datatype string to address
    address public owner;
    
    // NOTE: I changed the constructor parameters changing the last parameter from dataype string to address
    constructor(string memory _brand, string memory _model, address _owner) {
        brand = _brand;
        model = _model;
        owner = _owner;
    }
}

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.