I have a token, let's call it TokenA, that inherits from Open Zeppelin Whitelist.sol. TokenB and TokenC both inherit from TokenA and they each have some additional functions.

I want all three Tokens to share the same whitlist, meaning: - if I call addAddressToWhitelist in TokenA, whitelist(address), which is a function that returns true if the address is whitelisted and false if not, should return true if called from contract B or C.

How do I do that (or is it even possible)?

My current solution is to call addAddressToWhitelist in all 3 Tokens which doesn't seem very elegant.

  • 1
    From your description, it sounds like all three token are already sharing the same whitelist. Sep 2 '18 at 17:40
  • No, they don't. If you call TokenB.deployed().then(function(instance){return instance.addAddressToWhitelist(someAddress)}); then TokenC.deployed().then(function(instance){return instance.whitelist(someAddress)}); will return false.
    – user45543
    Sep 2 '18 at 18:05
  • Oh, you deploy them as separate instances. Right then. This means that essentially you have 3 TokenA instances in your system. Are you sure that this aligns well with your design intentions? What exactly is your purpose in having the other two tokens inherit from the first one? Sounds to me like they should take its address at construction rather than inherit from it. Sep 2 '18 at 18:10
  • contract TokenA is MintableToken, Whitelist {...} in the contract, I overwrite some functions, such as transfer and transferFrom such that they include the whitelist modifier, in order to ensure that transfers will only happen between whitelisted addresses. Token B and C have many other properties/functions, but also need to uses these transfer functions. So I thought it was the best design decision to let B and C inherit from A (thanks for looking into my question!)
    – user45543
    Sep 2 '18 at 18:17
  • I have changed TokenB und C such that they access the whitelist function of Token A via an interface. To achieve this, I am passing the contract address of Token A after deployment to the constructor of Token B and C. It now works as I wanted it to. Please let me know if this is the direction you intended to point me to or whether you know smth even better, dear goodvibration?
    – user45543
    Sep 2 '18 at 19:33

This is similar to the idea of sharing the whitelist in TokenA, but that seems lopsided to me. I would take the modularization to its conclusion and make similarly structured token contracts that share a dedicated whitelist contract. The WL contract would be free of other concerns.

Deploy contract WL, then contract TokenA, contract TokenB, etc.

contract WL is Ownable, WLInterface

Use WL to maintain the common whitelist and implement the WLInterface.

For each token contract, have a WLInteface wlContract. Pass the whitelist contract address through the constructor and optionally through a maintenance function to update the list address from time to time (onlyOwner of course). You would say wlContract = WLInterface(whitelistAddress);.

From the token contracts, you would do things like:


Hope it helps.

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.