0

I have wanted to know what concept is it called when we want two contracts which are deployed on the Network, reflect the transaction and updates in another contract.

for example:

contract Base{
  mapping(address => bool) addressTrue; //mapping true some addresses, as per our requirement(s)

  function setTrue(address _address) public {
    addressTrue[_address] = true;
  }
}


contract FromBase{ //Maybe without inheritance/ interface.
    
   function seeStatusAndDoSomething(_address) public returns(bool) {
        //Return: the mapped value of _address is true or false
   }
}

If Alice deploys Base contract and sets the addresses of Bob as true. Later Daves want to see the status of Bob's address, which should return true. But in future if Alice decides to change status of Bob's address to false. Dave, when he checks the by calling seeStatusAndDoSomething should now get false.

What I want to understand is that whenever a function setTrue in contract A is called, where some _address is getting true. How should I see those changed in contract B, without redeploying it? Is such presented above scenario possible in Solidity?

I am familiar with solidity concepts, just want to know which one to use and what should be the workflow.

Thank you.

Edit: Added details in question

3
  • if two contracts are deployed in a network then intercation between them is done via EVM Call() invocation. You can see those in special tab in Etherscan internal txns , if you don't see them, then the contracts haven't interacted one with another. That's how it works. So, answering your question, this is how this kind of interaction is "reflected" – Nulik Feb 15 at 13:42
  • every contract should have its own setTrue set of functions and then you can make communication between contracts calling these functions – Nulik Feb 15 at 13:44
  • @Nulik Thank you for your comment. Well, I don't think Call() helped. I have edited my question for more details. – Yash Madhwal Feb 15 at 14:08
0

There are two basic ways how to reference a contract: either by using the new keyword or without it. The difference is that when you use the new keyword, as new contract instance is created at a new address. Without new, an existing contract is used and you need to know its address.

If the two contracts are really in the same file, then you can simply use something like this:

function seeStatusAndDoSomething(_address) public {
    A contr = A(addressOfA);
    if (contr.addressTrue(_address)) {
        // do something
    }
}

If the two contracts are not in the same file you need to use an interface to access functionality of another contract - otherwise there is no way to know what functionality the other contract provides.

1
  • Thank you for your answer. But, I tried without if statement, and I get a Type error. – Yash Madhwal Feb 15 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.