Return bytes32 or address in one or two functions?

Hello everyone.

I have a question in solidity regarding different methods concerned with returning an address that is either as it is, an (address) type or encrypted therefore resulting as (bytes32).

If I can just create a quick example to try and get across what I mean. Pls excuse the crude example.

// SPDX-License-Identifier: MIT
pragma solidity 0.8.14;

contract c_wherewasa {

    struct dudesData {
        address payable dudesAddress;
        bool dudesAnonymity;
        // more dude data to justify  struct

    mapping (uint256 => dudesData) internal dude;
    uint256 internal dudeIndex;

    function f_encryptDudesAddress(address _dudesAddress)  internal pure returns (bytes32) {
        return keccak256(abi.encode(_dudesAddress));

    function f_dudesEncryptToggle(uint256 _dudeIndex) external {
        if (dude[_dudeIndex].dudesAnonymity == true ){
            dude[_dudeIndex].dudesAnonymity = false;
            dude[_dudeIndex].dudesAnonymity = true;

    function f_addDude(address payable _dudesAddress) external {
        dude[dudeIndex].dudesAddress = payable(_dudesAddress);
        dude[dudeIndex].dudesAnonymity = false;

Addressing the simple example above, “Dude” can be anonymous or not anonymous , and when his data is called it should return either encrypted or decrypted something like below.

    function f_showEncryptedDude(uint256 _dudeIndex) external view returns (bytes32){
        require(f_isAnonomous(_dudeIndex), "Not Anon" );
        return f_encryptDudesAddress(dude[dudeIndex].dudesAddress);

    function f_showDecryptedDude(uint256 _dudeIndex) external view returns (address){
        require(!f_isAnonomous(_dudeIndex), "Is Anon" );
        return dude[dudeIndex].dudesAddress;

    function f_isAnonomous(uint256 _dudeIndex) internal view returns (bool){
        return dude[_dudeIndex].dudesAnonymity;

I know a simple option would be to have the code on the front end call two functions the first to check if the user is anonymous to then select which function should be returned the bytes32 or the address. (f_showEncryptedDude || f_showDecryptedDude))

I also know I could do the following, just because if unassigned the values will be 0ish, so I can display which ever return has been assigned and ignore the other one, as shown below.

  function f_viewDude(uint256 _dudeIndex) external view returns (address _unencrypted, bytes32 _encrypted) {
        if (dude[_dudeIndex].dudesAnonymity == true ){
            _encrypted = f_encryptDudesAddress(dude[dudeIndex].dudesAddress);
            _unencrypted = dude[dudeIndex].dudesAddress;

Of course if I attempt to call external functions from an external function it does not work they cannot see one another and it all becomes a puzzle and adding middle internal functions is not practical.

My question is then what would be considered the most practical method.

A). having the front end function call two solidity functions, 1st to check anonymity 2nd to call the relative function with the correct variable type returning (address) || (bytes32).

B.) just creating the one function that can return both types (address) && (bytes32), one or the other then is carrying its unassigned value, from which the front end can easily ignore.

and or neither and there is another solution to this such as how you would return like on a void ?

A variant type .i.e. returns (variant) which can hold either the (address) && (bytes32) would be useful.