8

I want to access / modify data from a contract from another contract. If you could help me understand the error that would be great!

I get the following error:

Untitled1:33:8: Error: Indexed expression has to be a type, mapping or array >(is function (address) constant external returns (bool,address,uint256,bool))
        if (a.Owners[msg.sender].sub = false){
            ^------^

below is the code :

pragma solidity ^0.4.7;

contract abc{
    struct Owner{
        bool exist;
        address owner;
        uint share;
        bool sub;
    } // un owner as son address et son percent d'ownership

    mapping (address => Owner) public Owners;
    uint public no_owners; 
    uint public no_sub;


    function abc(){ // a l'execution, l'ownership est transferer a l'excecuteur avec 100 shares.
        //initate
    }

    function transfer(address to,uint amount){
        //transfer ownership
    }
}

contract cde{
    mapping (uint => abc) all_cde;
    uint public f;


    function ask_subdivise(abc a){
        //les different owners vont devoir lancer la fonction
        // une fois que tout les owners on lancer la fonction, le lot est diviser.
        if (a.Owners[msg.sender].sub = false){
            a.Owners[msg.sender].sub=true;
            a.no_sub+=1;

        }
    }
}   
4

Struct structure (...) is internal to the compiled contract and other contracts have no visibility in it.

Instead, you need to have an accessor and mutator functions that unpacks and returns the struct data for you. See this answer for the example.

2

As I understand you can access variable via function. So, to solve your problem you have to call a.Owners(msg.sender). But after you will have this error:

Error: Member "sub" not found or not visible after argument-dependent lookup in tuple

see: access struct from other contract

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.