0
contract B {
  struct Player {
    uint id;
  } 
  mapping (uint=> Player) Players; 
}

contract A {
  constructor() public {
    B.Player storage p = B.Players[1];
  }
}

Report err at B.Players[1]:Member "Players" not found or not visible after argument-dependent lookup in type(contract B).

So, how can I use mapping Players in A from B?

  • 1
    You cannot access private variables of other contracts. The variables need to be public if you want others to access them. – Mikko Ohtamaa Jan 30 at 10:20
  • contract B { struct Player { uint id; } mapping (uint=> Player) public Players; } contract A { constructor() public { B.Player storage p = B.Players[1]; } } – xu mo Jan 30 at 10:31
  • its the same err – xu mo Jan 30 at 10:32
1

You can not directly access variables of other contracts. One of the way that you have to inherit contract B for using its variable.

contract B {    
    struct  Player {
        uint id;   
    }
    mapping (uint=> Player) public Players; 
 }

contract A is B {
    constructor() public {
        B.Player storage p = B.Players[1];   
    }
 }
  • Inherit will make my code too long(over 1000 line) then out of gas.I'm finding the way that I can access variables in B contract. – xu mo Jan 31 at 2:15

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.