I want to call method of another contract. But web3js does not support from .sol so I have to hard code the source in a string. How do I deploy two contracts separately but still call the contract inside the other?

1 Answer 1


You can call an arbitrary contract from another as like the following:

contract Client{

    function call(address servAdd){
        Server s = Server(servAdd);
contract Server{ 
    function a(){
    event FunACalled();

With Server s = Server(servAdd); you can get the referrence to the deployed contract on the address servAdd to interact with it.

  • Do you get two addresses when you deploy this? I only see one address being generated. Dec 21, 2016 at 11:11
  • At least upvote my soluton before asking, man! Dec 21, 2016 at 11:11
  • Thanks for replying. Upvoted now. (was reluctant as I already knew that). But do you get two addresses? Dec 21, 2016 at 11:58
  • In my example you have to deploy two contracts separately and manually so you naturally have two addresses. Dec 21, 2016 at 12:10
  • Thanks for replying. But if you do them separately the Client won't compile. It says Sever not defined. I am getting compile error like that, Dec 21, 2016 at 12:52

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.