1

I have a mapping:

mapping(bytes32 => string) requestToCharacterName;

I am trying to access it from HardHat as such:

contract.requestToCharacterName(bytes32)

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

2

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.

3
  • 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
    Feb 17 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. Feb 20 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
    Feb 22 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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