# How to store a string/variable in a smart contract that is encoded and only the owner of that contract can call a function to decode it?

**URL:** <https://forum.soliditylang.org/t/how-to-store-a-string-variable-in-a-smart-contract-that-is-encoded-and-only-the-owner-of-that-contract-can-call-a-function-to-decode-it/1192>\
**Category:** Code Wizards\
**Created:** [August 15, 2022, 1:15pm UTC](https://forum.soliditylang.org/t/how-to-store-a-string-variable-in-a-smart-contract-that-is-encoded-and-only-the-owner-of-that-contract-can-call-a-function-to-decode-it/1192 "2022-08-15T13:15:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bruff](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/bruff/32/665_2.png) [@bruff](https://forum.soliditylang.org/u/bruff)\
**Post date:** [August 15, 2022, 1:15pm UTC](https://forum.soliditylang.org/t/how-to-store-a-string-variable-in-a-smart-contract-that-is-encoded-and-only-the-owner-of-that-contract-can-call-a-function-to-decode-it/1192/1 "2022-08-15T13:15:05Z")

</div>

Let’s say we wanted to protect a string. Would it be possible to encode this and have a function in the smart contract that only the owner can use to decode it?

---

<div class="post-metadata">

**Author:** ![MicahZoltu](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.soliditylang.org/micahzoltu/32/67_2.png) [@MicahZoltu](https://forum.soliditylang.org/u/MicahZoltu)\
**Post date:** [August 15, 2022, 2:28pm UTC](https://forum.soliditylang.org/t/how-to-store-a-string-variable-in-a-smart-contract-that-is-encoded-and-only-the-owner-of-that-contract-can-call-a-function-to-decode-it/1192/2 "2022-08-15T14:28:32Z")

</div>

Depending on what you are trying to accomplish, you can just store a hash of the string on-chain, and then the owner can bring the full string to the blockchain later and the contract will check that the hash matches. Beware of front runners though! [How To Get Front-Run on Ethereum mainnet - YouTube](https://www.youtube.com/watch?v=UZ-NNd6yjFM)
