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
• 27,620 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,040 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
• 16,450 points
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
0 votes
1 answer
+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
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,040 points
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.