1

what is the best way to store ASCII characters/strings on the ethereum blockchain? scenario: there are users that want to upload ONLY ASCII strings to the blockchain. these strings don't contain private info , so they can be stored as plaintext. this is my implementation, is there a better solution?


contract storagex {
    mapping(address => string[]) public users;

    function add(string memory _data) public {
        users[msg.sender].push(_data);
    }

    function retrieve(address ad) public view returns (string[] memory) {
        return users[ad];
    }
}

1 Answer 1

1

That's it, that's all you need. Solidity string is designed to hold ASCII printable characters only, from the range 0x20 to 0x7E, which would be in decimal from 32 to 126, which is from "Space" to "~".

Take a look at the docs:

https://docs.soliditylang.org/en/v0.8.14/types.html#string-literals-and-types

ASCII table:

https://www.asciitable.com/

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.