0

Interacting with one smart contract to another ? , Multiple smart contract interaction ? , One contract calls to another contract ? in Solidity.

My questions are:

  1. How does a contract with each other ?
  2. One contract interaction with another contract ?
  3. Contract invocation without inheritance ?

1 Answer 1

0

Ok, So to solve this problem, Solidity not only provides for inheritance to invoke contracts in one another, It also provides a cool feature that helps devs/coders to invoke a contracts function from one contract to another without inheritance, Isn't that a neat feature.

Its solves the problem, e.g: A scenario where you want interact or invoke only one function of another contract, Why would you inherit and override all of its functions.

Solidity also gives the feature of invoking a Interfaces contract but the condition is that its implementer needs to implement that exact same function that was in its Interface.

Two Examples:

  1. Simple contract invokes another contract
  2. Interface is invoked in another contract

//import the contract you want to invoke first to do this in both examples

Example 1:

contract A
{
function someLikeableFunction()internal view returns(uint256){/*Does Something*/}
}

contract B{
function someDisLikeableFunction()internal returns(address){

A(/*Pass an Address of owner or caller*/).someLikeableFunction();

//you can store its value in a variable as well
}

}

Example 2:

contract Interface_A
{
function someLikeableFunction()external view returns(uint256);
}

contract A is Interface_A {

function someLikeableFunction()external override view returns(uint256){/*Does Something*/}

}

contract B{
function someDisLikeableFunction()internal returns(address){

Interface_A(/*Pass an Address of owner or caller*/).someLikeableFunction();

}

}

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.