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);



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{



Jan 23 in Blockchain by Suman

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 by Omkar
• 66,990 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
• 16,450 points

edited Aug 10, 2018 by Omkar 384 views
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
• 16,450 points
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
• 27,620 points
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
0 votes
1 answer
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
• 66,990 points
+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 17, 2018 in Blockchain by sapan

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.