Is it ok to use interfaces from openzeppelin-solidity in an upgradeable contract?

It’s fine to use ERC20 from https://github.com/openzeppelin/openzeppelin-solidity rather than https://github.com/openzeppelin/openzeppelin-eth in an upgradeable contract as long as it only is being used as an interface in the contract and the upgradeable contact is not inheriting from it, right?

This question is related to this part of the docs: https://docs.zeppelinos.org/docs/writing_contracts.html#use-upgradeable-packages

Thanks!

2 Likes

Hi @pcowgill I have changed the topic title based on my understanding of your question.

I assume that there are no issues using Interfaces from openzeppelin-solidity in an upgradeable contract.

Is there a reason that you don’t want to use the Interfaces in openzeppelin-eth?

I imported an interface from openzeppelin-solidity into an upgradeable contract with dummy implementations and used the ZeppelinOS tutorial: https://docs.zeppelinos.org/docs/deploying.html

ZeppelinOS didn’t show any warnings or errors and I was able to access the values from truffle console as I would expect.

pragma solidity ^0.5.0;

import "zos-lib/contracts/Initializable.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";

contract MyContract is Initializable, IERC20 {
    string private _name;
    string private _symbol;
    uint8 private _decimals;

    function initialize(string memory name, string memory symbol, uint8 decimals) public initializer {
        _name = name;
        _symbol = symbol;
        _decimals = decimals;
    }

    function name() public view returns (string memory) {
        return _name;
    }

    function symbol() public view returns (string memory) {
        return _symbol;
    }

    function decimals() public view returns (uint8) {
        return _decimals;
    }

    function totalSupply() external view returns (uint256) {
        return 0;
    }

    function balanceOf(address account) external view returns (uint256) {
        return 0;
    }

    function transfer(address recipient, uint256 amount) external returns (bool) {
        return false;
    }

    function allowance(address owner, address spender) external view returns (uint256) {
        return 0;
    }

    function approve(address spender, uint256 amount) external returns (bool) {
        return false;
    }

    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool) {
        return false;
    }
}
1 Like