How can I call a contract from another contract

0 votes

This is my contract

pragma solidity ^0.5.2;

contract NewContract{

address[] public deployedContract;


function createContract(uint minimum) public{

    address newContract  = new Contract2(minimum,msg.sender);

    deployedContracts.push(newCampaign);

}


function getDeployedContracts() public view returns(address[] memory){

    return deployedContracts;

}

}

I'm getting the error while assigning calling the Campaign contract inside NewContract contract

TypeError: Type contract Contract2 is not implicitly convertible to expected type address.       
address newContract  = new Contract2(minimum,msg.sender);

I have another contract called Contract2 which I want to access inside NewContract.

contract Contract2{

//some variable declarations and some codes here......

and I have the constructor as below

constructor (uint minimum,address creator) public{

    manager=creator;

    minimumContribution=minimum;


}
Jan 23, 2019 in Blockchain by Suman
1,770 views

1 answer to this question.

0 votes

There are two ways to solve this. One way is to typecast it:

Address newContract = address(new Contract2(minimum,msg.sender));

But I would suggest that instead of address type, you can just use the specific type, like this:

Contract2 newContract = new Contract2(minimum,msg.sender);
answered Jan 23, 2019 by Omkar
• 69,220 points

Related Questions In Blockchain

0 votes
1 answer

How can I deploy a HelloWorld contract on my testrpc network?

The problem lies in the command: truffle migrate Your truffle migrate command ...READ MORE

answered Apr 27, 2018 in Blockchain by Perry
• 17,100 points

edited Aug 10, 2018 by Omkar 2,845 views
0 votes
1 answer
0 votes
1 answer

How do I withdraw the balance from a contract on Ethereum test blockchain?

Your need to improvise your code a ...READ MORE

answered Aug 3, 2018 in Blockchain by Perry
• 17,100 points
2,663 views
0 votes
1 answer

How do I send ether from an EOA to a smart contract?

You include ether to send in the ...READ MORE

answered Sep 27, 2018 in Blockchain by digger
• 26,740 points
1,574 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,923 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,220 points
1,464 views
+1 vote
2 answers

Can I include real world data in a smart contract? If so, how?

You cant access/embed real world data using ...READ MORE

answered Jul 18, 2018 in Blockchain by sapan
1,162 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP