1

kinda new to the development side of Ethereum. Been searching around for days but can't seem to find an answer for my specific case. I'm trying this challenge here.

The problem is that I can't seem to access the variable in the Stamp contract using address(stamp).id() when trying to check if the var Id exists as I get "TypeError: Member 'id' not found or not visible after argument-dependent lookup in address."

Referencing the validator file, I can't create new contracts via the 'new' keyword to check that Id() exists as the validator is the one creating the contract at the particular address. As such, I need some way of accessing the variable of the external contract without using low level calls. This is why I haven't found answers on similar threads because in this instance, I can't modify the original Stamp or NotStamp contract.

Any pointers greatly appreciated. My attempt below. Thanks

pragma solidity ^0.5.0;

interface IStampCollector {   
  function isCollected(address stamp) external returns (bool);   
  function collectStamp(address stamp) external; 
}

contract Stamp {   bytes32 public id;   uint public rarity;
    constructor(bytes32 _id, uint _rarity) public {
      id = _id;
      rarity = _rarity;   } 
    }

contract NotStamp {   bytes32 public notId;   uint public notRarity;
    constructor(bytes32 _id, uint _rarity) public {
      notId = _id;
      notRarity = _rarity;   } 
    }

contract StampCollector is IStampCollector, Stamp, NotStamp {

    bool public genuine;

    function isCollected(address stamp) public returns (bool) {
      require(address(stamp).id());
      genuine = true;
       }

      function collectStamp(address stamp) public {
       }
     }
1

Change this:

address(stamp).id()

To this:

Stamp(stamp).id()

Or better yet, to this:

Stamp(stamp).id

BTW, something is your design looks fundamentally wrong (or extremely suspicious):

Why does StampCollector inherit from Stamp?

  • Hey, thx for suggestions. I get a different TypeError where "no matching declaration found after argument-dependent lookup." for the require function. From my understanding, the above code should return that the .id exists if a contract has been initialized via the original Stamp or NotStamp contract. I initially use the inheritance cause I thought that the contract needs to know what kind of value will be returned. Sorry if confusing, I'm still trying to wrap my head around the contract structures – Kai Shin Aw Feb 15 at 9:01
  • @KaiShinAw: Well what exactly do you want to require about this id? It is not even a boolean variable, I just noticed. A require statement expects a boolean expression, which your id (without being compared to anything) is obviously not! – goodvibration Feb 15 at 9:37
  • I guess that's the part which i'm still confused about as I just wanted to find out if id is not null (or >0 in the case of solidity). I can't use operators to compare Stamp(stamp).id to null/zero. Also, from the validator file, it seems like the address provided by argument stamp for the function isCollected() seems to be pointing to a contract where the contract Stamp has already been initialized. Appreciate your help on this as I might have just misunderstood fundamental parts of the language. – Kai Shin Aw Feb 16 at 3:59
  • @KaiShinAw: Well, it sounds pretty obious that you don't need to inherit from Stamp and NotStamp. With regards to the comparison, I believe that require(uint256(Stamp(stamp).id) > 0) should do the job. – goodvibration Feb 16 at 7:40
0

I managed to compile using require(uint(Stamp(stamp.id()) > 0)

Thanks @goodvibrations for the pointer

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.