0

When I use mapping to store data, in that case, if I don't know the key (_secretToken), I won't be able to get the data in my dapp.

contract Register {
    mapping(bytes => bool) private myHiddenToken;

    function register(bytes calldata _secretToken) public {
        myHiddenToken[_secretToken] = true;
    }

    function checkAccess(bytes calldata _secretToken) public returns(bool access) {
        access = myHiddenToken[_secretToken];
    }
}

If the contract doesn't provide the list of map's object keys, you can't get it.

Is mapping a good way to store hidden data or are there better options?

  • 1
    TLDR: Do not store private data on a public blockchain, do not pass them as function params... Even `private` properties are readable using off-chain tools. Plus, invoked function params (in this case the `_secretToken`) are also public. – Petr Hejda Jan 16 '22 at 17:20
  • Thank you, if the database dump is publicly available, then nothing prevents pulling data from the database in a low-level way. – Alexey Norilsk Jan 16 '22 at 20:26

0 Answers0