Calling a nested ERC721 contracts _burn function

Hello,

I have an ERC721 Contract (let's call it contract A) that has a nested erc721 contract (contract B) inside of it.

I want to call the _burn of contract B using contract A.

Is this possible in any sense?

I did the setapprovalforall but doing ERC721._burn(tokenID); Doesn't work as it is assuming I am burning the token from contractA.

If I do contractB._burn(tokenID); That doesn't work either as contractB has no function called _burn but is there something I'm missing like super call or something that can get me access to the contractB erc721 _burn.

For Example

contractA is ERC721
{
     ....
}

contractB is ERC721
{
      contractA public myFirstContract

      contractA._burn(1);
}

Thank you

Hi,
It is possible you just need to expose it, you would need to do something like this:

contractA is ERC721
{
     ....
    function burn(uint tokenId) external {
        _burn(tokenId);
    }
}

contractB is ERC721
{
      contractA public myFirstContract

      contractA.burn(1);
}

If it wasn't exposed prior to deployment then there is no way around it?

Hello @BlockchainDev

This first thing is, when you do contractA public myFirstContract you are by no means putting a contract into another. Contracts are not like C++ structure.

By itself

contractA public myFirstContract

is just a pointer (an ethereum address) to another contract, but B as absolutely no control over A, unless A explicitly has this set up.

You cannot access A's internal function/storage from B, and B is just like any other user.
If you expose the burn function like @JulissaDantes proposed, make sure to properly protect it, with access restriction, otherwise anyone could use it to burn any token. This would be bad.

If it wasn't exposed prior to deployment then there is no way around it?

No, unless you explicitly made the contract upgradeable, you have no way to change it.

1 Like