0

I'm facing a problem with the function return type in solidity. Here is my code:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

contract Birth {
    mapping(uint256 => bool) public isValidBirthCerti;

    function birthCertiGenerator(
        string memory _Name

    ) public returns (uint256) {
        uint256 birthCerti = uint256(
            keccak256(
                abi.encodePacked(
                    _Name
                )
            )
        ) % 100000000000000000;
        isValidBirthCerti[birthCerti] = true; //if I remove this ,then I get the returned value.
        return birthCerti;
    }
}

In the birthCertiGenerator function which returns a uint256 type value, is not returning the value if I use isValidBirthCerti[birthCerti] = true; this line. Is there anything wrong ? Or Am I missing something here?

1
  • ``` mapping(uint256 => bool) public isValidBirthCerti;``` is a mapping , not a modifier. @alberto Feb 24, 2023 at 12:16

1 Answer 1

1

If you are referring to call the birthCertiGenerator from ethers.js or web3 is normal that you don't receive the unit256 as adding isValidBirthCerti[birthCerti] = true; you are changing the state, and this your method is a transaction, not a view/pure any more.

Hope it helps

2
  • so state changing function dosen't return anything ? Thats the point? Feb 24, 2023 at 12:30
  • When calling outside the blockchain they return the transaction receipt
    – donoso.eth
    Feb 24, 2023 at 13:12

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.