I am currently a bit stuck with my contract, the issue is following: I define a smartcontract type which is used for another address (aka address is smartcontract that provides the specified interface) The question is whether there is a possibility to make address type checks or cast said contract interface object to address, since that what it's essentially. While I know that in terms of storage those are bytes that represent address, I just can't seem to figure out how to get from interface type back to bare address type and make proper checks against it. I searched around for quite a bit, but couldn't find any samples how to accomplish this on the web or in the solidity docs.

See example bellow:

pragma solidity ^0.5.1;

contract SampleInterface {
    function foo(uint256 someValue) external returns (uint256);

library SampleLibrary {
    enum SampleType {

contract SampleInterfaceManager {
    mapping(uint => SampleInterface[]) public interfacesByType;

    function processFoo(uint256 someValue, SampleLibrary.SampleType sampleType) external returns (uint256) {
        SampleInterface[] storage sampleInterfaces = interfacesByType[uint(sampleType)];
        uint temp = someValue;
        for (uint i = 0; i < sampleInterfaces.length; i++) {
            SampleInterface sampleInterface = sampleInterfaces[i];

            //How to make this check work?

            if (sampleInterface != address(0)) {
                temp = sampleInterface.foo(temp);
        return temp;

This code currently creates compilation error:

smartcontracts/Sample.sol:23:17: Error: Operator != not compatible with types contract SampleInterface and address payable
            if (sampleInterface != address(0)) {

Any advice on how to solve this is most welcome. I can try and do without this check but would rather hope to avoid this scenario.

1 Answer 1


Just cast to address:

if (address(sampleInterface) != address(0)) {

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.