Creating a new contract within another contract

shahzad73shahzad73 Member Posts: 3
Hi,

It's been few days that i am struggling with this bug with no reasonable explanations. In short i want to create an instance of another contract within the main contract. Here is the code that is trying to create the instance



//-----------------------------------------------------------------------------------------
// Add new project. This interface will create a new project within this incubator
//-----------------------------------------------------------------------------------------
projectsStruct newProject;
function addNewProject(
address _projectOwner,
address _incubatorOwnerAddress,
uint _incubatorOwnerPercentageInProject,
address _ventureFusionOwnerAddress,
uint _ventureFusionPercentageInProject,
string _name,
string _symbol,
uint8 _decimals
) public onlyOwner
returns ( uint newProjectID,
address projectAddress,
string projectName
)
{

//Create new project contract
address newProjectContract = new ProjectEquity(_projectOwner, _incubatorOwnerAddress, _incubatorOwnerPercentageInProject, _ventureFusionOwnerAddress, _ventureFusionPercentageInProject, _name, _symbol, _decimals);




}


Got error at the point where project is being created. Now if I issue command from Truffle console and create this project manually within Incubator then project is created with no issues.

Incubator.deployed().then(function(i){return i.addNewProject('0xd8183a7359a693475c226cfcb3b48fcccfd383f4','0x35661c0e3f5bde24f71fdb204c39b00e7f2db726',3000,'0x2b51ac6c5edc12791fca855ddaf41b7aaadbe675',1000,'Project 2','PRO2',3,{from:'0x2b51ac6c5edc12791fca855ddaf41b7aaadbe675'})})

I can go back in my web application and see the project listed and then i can work with that project. Now command from javascript is showing me the error. I also checked that command from Javascript web3 is correct and made sure that owner of this incubator is selected in metamask as well as being passed in the following javascript command

incubator.addNewProject.sendTransaction
(
$("#projectOwner").val(),
$("#incubatorOwnerAddress").val(),
$("#incubatorOwnerPercentageInProject").val(),
$("#ventureFusionOwnerAddress").val(),
$("#ventureFusionPercentageInProject").val(),
$("#projectname").val(),
$("#symbol").val(),
$("#decimals").val(),
transactionObject,
(error, result)=>
{
window.location = "/";
});






And here is the ProjectEquity code



contract ProjectEquity is StandardToken, Ownable {

string public name;
string public symbol;
uint8 public decimals;




//-------------------------------------------------
// Contract Constructor
//-------------------------------------------------
constructor( address _projectOwner, // Project Owner address
address _incubatorOwnerAddres, // Incubator Owner address
uint _incubatorOwnerPercentageInProject, // Incubator owner percentage in this project
address _ventureFusionAddress, // VentureFusion owner address
uint _ventureFusionPercentageInProject, // VentureFusion percentage in this project
string _name,
string _symbol,
uint8 _decimals )
public {
require(_projectOwner != address(0));
require(_incubatorOwnerAddres != address(0));
require(_ventureFusionAddress != address(0));
require(_incubatorOwnerPercentageInProject >= 0);
require(_ventureFusionPercentageInProject >= 0);
require(_decimals >= 0 && _decimals <= 6);

if(_decimals == 0)
totalSupply_ = 100;
else if(_decimals == 1)
totalSupply_ = 100 * 10;
else if(_decimals == 2)
totalSupply_ = 100 * 100;
else if(_decimals == 3)
totalSupply_ = 100 * 1000;
else if(_decimals == 4)
totalSupply_ = 100 * 10000;
else if(_decimals == 5)
totalSupply_ = 100 * 100000;
else if(_decimals == 6)
totalSupply_ = 100 * 1000000;

balances[_incubatorOwnerAddres] = _incubatorOwnerPercentageInProject;
balances[_ventureFusionAddress] = _ventureFusionPercentageInProject;
balances[_projectOwner] = totalSupply_.sub(_incubatorOwnerPercentageInProject + _ventureFusionPercentageInProject);

name = _name;
symbol = _symbol;
decimals = _decimals;
}





Will really appreciate if somebody can get me through. Note within the ProjectEquity i am creating another child contract with the same style of code and it is working fine.


Shahzad



Comments

Sign In or Register to comment.