Call other contract function through interface in solidity

In this example the problem is that the address can be of an account or any other contract which will through an error. To solve this problem ERC-165 contract comes into play.

//SPDX-License-Identifier: No-Idea!

pragma solidity >=0.4.16 <0.9.0;

contract Store {
  uint256 internal value;
  function setValue(uint256 v) external {
    value = v;
  }
  function getValue() external view returns (uint256) {
    return value;
  }
}

interface StoreInterface {
  function getValue() external view returns (uint256);
}

contract StoreReader {
  function readStoreValue(address store) 
    external view returns (uint256) {
    return StoreInterface(store).getValue();
  }
}

By Shabair

Frontend | Blockchain | Smart Contract Developer