I have 2 Smart Contracts:
B has a function
onlyA() which I want that only
A can call. Below is my approach:
- Make B Ownable, then add the
- Add the interface of
Acan call the function
- Transfer ownership of
Aafter deploying it.
- Now, user can call
I'm building a Protocol Smart Contract (
A) that has an NFT Contract (
B) linked to it. I don't want anyone to directly mint an NFT from
B, but only by calling a function
mintNFT() in the Protocol Smart Contract (
A) which in turn calls the function
B which internally mints the NFT.
Protocol.mintNFT() -> NFT.onlyA() -> ERC721._mint()
So I was thinking of using the above approach I listed. But I have to add the interface of my NFT Smart Contract to my Protocol Contract which I don't want to do. It just seems to me like an anti-pattern. It is considered bad practice to add interfaces like this?
I would highly appreciate any suggestions for an approach different from the one listed above. Also, any suggestions on the overall re-design of my Protocol Smart Contracts are also welcome.
Since both contracts are part of the same project, I was also wondering about simply importing the NFT contract in the Protocol Contract rather than defining the NFT interface. Which one is a better way, gas-wise & Solidity best practices wise?