0

I am trying to find a way to look up a way to get the owner of an external ERC721 or ERC1155 contract, in order to require that functions with in my contract can only be called if the msg.sender is the same as the owner of the external contract.

My contract is an airdrop contract with three functions to airdrop either Erc20, 721 or 1155 tokens. I want to require that the msg.sender for all three functions is the owner of the ERC20, 721 or 1155 contract.

I can’t seem to find anything within Solidity, or an interface to handle the checking of ownership.

Would a ChainLink oracle work for this situation? If so, is there an oracle that would be recommended? If it can work within Solidity, what would be the best implementation?

3
  • You can only get the owner if the contract has set some owner. If the contract has no owner then you won't find any owner. Commented Jul 18, 2023 at 4:41
  • I'm trying to access the owner read function from the standard ERC721 and 1155 contracts. When using the IERC721 and IERC1155 interfaces from OpenZeppelin, I noticed that OZ doesn't have a owner() function to retrieve that data when a contract is inputted. I wonder if I can modify it to grab that data?
    – OhItsPM
    Commented Jul 18, 2023 at 15:29
  • Yeah, that's what I am saying, the owner is not something that necessarily will be present in this contract. If the contract doesn't have a owner it simply means there is no owner. Commented Jul 19, 2023 at 5:52

1 Answer 1

1

The owner() function is usually public, so you can use an interface that consists of an owner() function to get the external contract and it's owner function. You can progress from this example pseudo-code:

interface YourOwnerInterface {
    function owner() external view returns (address);
}

address externalOwner = YourOwnerInterface(externalContractAddress).owner();
if(externalOwner != msg.sender){
    // do whatever you would do if the external owner was not the function caller
}
3
  • Yes. I know that the owner is usually public, but I am trying to work with the IERC721 and IERC1155 interfaces from OpenZeppelin and have noticed they don't come with an owner function like there would be for various other needs. Is that done by design? I wonder if I can implement my own owner() function to retrieve that data? Modify the IERC721 from OpenZeppelin
    – OhItsPM
    Commented Jul 18, 2023 at 15:28
  • If a contract doesn't have an ownership mechanism, owner variable, etc., I don't think you can fetch the owner in any way. You could assume the deployer of the contract as the owner, but still, you can not fetch that info using Solidity. Commented Jul 18, 2023 at 16:04
  • True, I guess I can do validation on a front-end instead
    – OhItsPM
    Commented Jul 18, 2023 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.