How to check the mapping value via OpenZeppelin-Cli

We can’t get the Mapping value via OpenZeppelin-Cli.
I expected to enter key value “1” and get the return value “test” in the sample code below but in fact there is no interface in Cli allowing me to do it.
Also I don’t want to prepare any get functions but instead want to directly access to the storage value.
Is there any ways to to get the _storage[1] from command line?


contract Test {
  mapping(uint256 => string) public _storage;

  function setStorage() public {
    _storage[1] = "test";
  }
}
1 Like

Hi @Shinsaku
Welcome to the community :wave:

After calling setStorage() to set the value:

$ npx oz send-tx
? Pick a network development
? Pick an instance Test at 0xA94B7f0465E98609391C623d0560C5720a3f2D33
? Select which function setStorage()
✓ Transaction successful. Transaction hash: 0x73ea3701929d73e6e0174479ae56f61c98e82109151eda451dff750865795208

We can read the value using the following:

$ npx oz call --method "_storage(uint256)" --args 1
? Pick a network development
? Pick an instance Test at 0xA94B7f0465E98609391C623d0560C5720a3f2D33
✓ Method '_storage(uint256)' returned: test
test

Unfortunately using the interactive commands without specifying the method and args doesn’t work currently, I will create an Issue.

$ npx oz call
? Pick a network development
? Pick an instance Test at 0xA94B7f0465E98609391C623d0560C5720a3f2D33
? Select which function _storage(: uint256)
You must provide a `name` parameter
1 Like

Created Issue: https://github.com/OpenZeppelin/openzeppelin-sdk/issues/1209

@abcoathup
Thank you for the answer.
I can get the mapping value with your command.
Thank you, I appreciate it.

2 Likes