I'm learning about Solidity.

I would like to write a complex scenario of demo to test the power of Solidity and smart contracts.

My doubts are about interaction between smart contracts.

If there are many smart contracts, what is the best way to interact between them?

Examples of scenarios:

  • I have a ContactA with its functions.
  • When something happened in a ContractA something have to trigger in ContractB (in this example HelloWord.sol).
pragma solidity ^0.6.0;

contract HelloWord 
  string hello= "Hi buddy";
  function getSaluto () public view returns (string memory saluto ){
    return hello;

Another file with another Contract:

pragma solidity ^0.6.0;

import "HelloWord.sol";
contract ContractA is HelloWord
   event LogString(
     string errore,
     string saluto
   receive() external payable {
     emit LogString("errore receive saluto " ,  HelloWord.getSaluto() ); //call to HelloWord function

It works but, is this the best way to interact with another contract?

Another scenario whit different contract that I don't know how implements:

  • If i have to call another contract not related with ContractA (because in not inherited) how to call it in a contraxt o from a client application?

Thanks a lot.

1 Answer 1


In your case there is no interactions between smart contracts. HelloWord.getSaluto() is actually an internal call, i.e. your smart contract calls its own function, just defined in base smart contract. Real interaction scenario would look like this:

contract A {
  uint state = 0;

  function foo (uint x) public returns (uint) {
    return state += x;

contract B {
  A a;

  constructor (A _a) public {
    a = _a;

  function bar (uint y) public {
    emit Zoo (a.foo (y));

  event Zoo (uint z);
  • Just a question. Inserting the contract in 2 different files( importing A in B) to deploy B i have to pass in deploying step the address of contract A. How should deploy with reference programmatically in a real scenario? Commented Apr 9, 2020 at 10:36

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.