0

I am new to programming and trying to access a struct located in another smart contract but am receiving the following error.

"TypeError: Member "Address" not found or not visible after argument-dependent lookup in tuple(address,int16,int8,uint256,bool,int256,address). --> Auction.sol:45:23: | 45 | if(bid == r.users(i).Address) x = true;"

Is it possible to access structs in mappings of different contracts?

My code is as follows:

pragma solidity ^0.8.3;

contract Registry {
    
    mapping(int => User) public users;
    int8 public userCount = 0;
    
    struct User {
        address Address;
        int16 Longitude;
        int8 Latitude;
        uint Transformer_ID;
        bool Is_Prosumer;
        int Peak_Power;
        address Smart_Meter;
    }
    
    function addUser(int16 _longitude, int8 _latitude, uint  _transformerID, bool  _isProsumer, int _peakPower, address _smartMeter) public {
        users[userCount] = User(msg.sender, _longitude, _latitude, _transformerID, _isProsumer, _peakPower, _smartMeter);
        userCount ++;
    }
}

contract Auction {

    Registry r;
    address registryAddr;
    function RegistryRead(address addr) public {
        registryAddr = addr;
        r = Registry(r);
    }
    
    function verify(address addr, address bid) public returns (bool) {
        int i; bool x = false;
        
        int8 max = r.userCount();
        
        for(i = 0; i == max; i ++)
            if(bid == r.users(i).Address) x = true;
            
        return x;
    }
    
}
0

It's because when the Auction contract reads the users; it only gets data types of array and not the names you have used in Resigtry contract. Understand it like this;

uint => (address, int16, int8, uint, bool, int, address)

So Auction contract can not lookup Address.

Solution: You can use

(address userAddress,,,,,,) = r.users(i);
if(bid ==userAddress) {
    x = true;
}

Or alternatively; add a getUser function that explictly returs Users type:

contract Registry {
    
    mapping(int => User) public users;
    int8 public userCount = 0;   
    struct User {
        address Address;
        int16 Longitude;
        int8 Latitude;
        uint Transformer_ID;
        bool Is_Prosumer;
        int Peak_Power;
        address Smart_Meter;
    }
    
    function addUser(int16 _longitude, int8 _latitude, uint  _transformerID, bool  _isProsumer, int _peakPower, address _smartMeter) public {
        users[userCount] = User(msg.sender, _longitude, _latitude, _transformerID, _isProsumer, _peakPower, _smartMeter);
        userCount ++;
    }
    
    function getUser(int _id) public view returns(User memory) {
        return users[_id];
    }
}

contract Auction {

    Registry r;
   
    
    address registryAddr;
    function RegistryRead(address addr) public {
        registryAddr = addr;
        r = Registry(r);
    }
    
    function verify(address bid) public view returns (bool) {
        int i; bool x = false;
        int8 max = r.userCount();
       

        for(i = 0; i <= max; i ++) {
            if(bid == r.getUser(i).Address) {
                x = true;
            }
        }
            
        return x;
    }
    
}

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.