Access variables through auto-generated getters from a different contract

0 votes

I am storing the variables of my token outside of the main contract in a contract called Storage and, therefore, need to access the auto generated getters of the publicly declared variables from a different contract than the one in which they are declared.

contract Storage {

    mapping (address => uint256) public balanceOf;
    mapping (address => mapping (address => uint256)) public allowance;

}

contract TokenA {

    address public storageAddress;

    function getAllowance(address _owner, address _spender) public returns (uint256) {
        return Storage(storageAddress). allowance( /** ? */);
    }

}

How could I access the variable allowance without specifically defining a getter inside the contract Storage?

Oct 3, 2018 in Blockchain by digger
• 26,740 points
507 views

1 answer to this question.

0 votes

You just need to pass it in as if you were calling a function:

function getAllowance(address _owner, address _spender) public view returns (uint256) {
    Storage s = Storage(storageAddress);
    return s.allowance(_owner, _sender);
}

Be careful of the order. You may have to swap it depending on how you're handling storage.

answered Oct 3, 2018 by slayer
• 29,370 points

Related Questions In Blockchain

0 votes
1 answer

How is a request sent from an app to a smart contract?

Yes, the contract is distributed by every node ...READ MORE

answered Jun 4, 2018 in Blockchain by Perry
• 17,100 points
713 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,922 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,610 points
1,413 views
0 votes
1 answer

Is it possible to send eth to a contract through its constructor from another contract?

I found the solution for this: pragma solidity ...READ MORE

answered Sep 26, 2018 in Blockchain by slayer
• 29,370 points
1,715 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP