I have a mapping:

mapping(bytes32 => string) requestToCharacterName;

I am trying to access it from HardHat as such:


And receiving the following error:

 TypeError: contract.requestToCharacterName is not a function

What do I need to do in HardHat to properly access this mapping?

1 Answer 1


Every variable is actually just a view function, however, if no visibility is specified, it will default to internal (per the solidity docs).

You cannot call the view function on an internal function, so, you just need to change the visibility of the mapping to public.

mapping(bytes32 => string) public requestToCharacterName;

Otherwise, you can read directly from storage using something like hardhat-storage-layout.

  • i am using hardhat as well. i hav a mapping as follows- mapping(uint => Post) posts; where Post is a struct is there any way to console.log the "posts" OR posts[0]? using hardhat console.log?
    – Subhranshu
    Commented Feb 17, 2022 at 11:38
  • 1
    Yes, you can console.log it, but you'd need to log out a type that console.log accepts. It won't accept a Post type. Commented Feb 20, 2022 at 17:25
  • Thanks Patrick for the reply! so essentially we cannot log it since "console.logX" where logX supports "Post" doesn't exist?
    – Subhranshu
    Commented Feb 22, 2022 at 12:57

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.