Function Saveideahash(String Idea) Returns (Bool): A Complete Guide to Understanding This Blockchain Concept

Note that this function can also return a value if saved, but it is not shown here for simplicity.

The next function is the alreadyHashed function, which is declared to take the variable named hash of type bytes32 and returns a Boolean (either true or false) after checking the hash in the hash map.

A Complete Guide to Understanding This Blockchain Concept

This is again declared as a constant and accessibility is set to private: function alreadyHashed(bytes32 hash) constant private returns(bool) return hashes[hash]; The next function is isAlreadyHashed, which checks whether the “idea” is already hashed.

This takes the input parameter idea of type string such as “my idea”, also declared as a constant, which means that it cannot change the state of the contract and returns either true or false based on the outcome of the execution of the function named alreadyHashed.

This function then calls the alreadyHashed function described earlier to check from the hashes map whether the hash is already stored there.

This would mean that the same string (idea) has already been hashed and stored (patented): function isAlreadyHashed(string idea) constant returns (bool) var hashedIdea = HashtheIdea(idea); return alreadyHashed(hashedIdea); Finally, the HashtheIdea function is shown here, which takes the idea variable of type string and is of constant type, which means that it cannot change the state of the contract.

It is also declared as private as there is no need to expose this function publicly because it is used only internally in the contract.

This function returns the bytes32 type value: function HashtheIdea(string idea) constant private returns (bytes32) return sha3(idea); This function calls solidity’s built-in function sha3 and passes a string to it in a variable idea.

Why This Matters for Blockchain Technology

The sha3 function is an alias for the keccak256() function available in solidity, which computes the Keccak-256 hash of the string passed to it.

Note that this SHA3 function, used in solidity is not the NIST standard SHA-3; instead, it is Keccak-256, which is the original proposal to NIST for the SHA-3 standard competition.

It was later modified slightly and standardized as the SHA-3 standard by NIST.

The actual SHA-3 standard hash function will return a different hash compared to Keccak-256 (Ethereum’s sha3 function).

Key Points to Remember

  • Note that this function can also return a value if saved, but it is not shown here for simplicity.
  • The next function is the alreadyHashed function, which is declared to take the variable named hash of type bytes32 and returns a Boolean (either true or false) after checking the hash in the hash map.
  • This is again declared as a constant and accessibility is set to private: function alreadyHashed(bytes32 hash) constant private returns(bool) return hashes[hash]; The next function is isAlreadyHashed, which checks whether the “idea” is already hashed.
  • This takes the input parameter idea of type string such as “my idea”, also declared as a constant, which means that it cannot change the state of the contract and returns either true or false based on the outcome of the execution of the function named alreadyHashed.

Going Deeper: Advanced Concepts

The complete contract source code is shown as follows: pragma solidity ^0.4.0; contract PatentIdea mapping (bytes32 => bool) private hashes; bool alreadyStored; event ideahashed(bool); function saveHash(bytes32 hash) private hashes[hash] = true; function SaveIdeaHash(string idea) returns (bool) var hashedIdea = HashtheIdea(idea); if (alreadyHashed(HashtheIdea(idea))) alreadyStored=true;

function SaveIdeaHash(string idea) returns (bool) var hashedIdea = HashtheIdea(idea); if (alreadyHashed(HashtheIdea(idea))) alreadyStored=true; ideahashed(false); return alreadyStored; saveHash(hashedIdea); ideahashed(true); This function has a variable declared hashedIdea, which is assigned a value after calling the HashtheIdea function described later. Note that this function can also return a value if saved, but it is not shown here for simplicity. The next function is the alreadyHashed function, which is declared to take the variable named hash of type bytes32 and returns a Boolean (either true or false) after checking the hash in the hash map. This is again declared as a constant and accessibility is set to private: function alreadyHashed(bytes32 hash) constant private returns(bool) return hashes[hash]; The next function is isAlreadyHashed, which checks whether the “idea” is already hashed. This takes the input parameter idea of type string such as “my idea”, also declared as a constant, which means that it cannot change the state of the contract and returns either true or false based on the outcome of the execution of the function named alreadyHashed. This function then calls the alreadyHashed function described earlier to check from the hashes map whether the hash is already stored there. This would mean that the same string (idea) has already been hashed and stored (patented): function isAlreadyHashed(string idea) constant returns (bool) var hashedIdea = HashtheIdea(idea); return alreadyHashed(hashedIdea); Finally, the HashtheIdea function is shown here, which takes the idea variable of type string and is of constant type, which means that it cannot change the state of the contract. It is also declared as private as there is no need to expose this function publicly because it is used only internally in the contract. This function returns the bytes32 type value: function HashtheIdea(string idea) constant private returns (bytes32) return sha3(idea); This function calls solidity’s built-in function sha3 and passes a string to it in a variable idea. This function returns the SHA3 hash of the string. The sha3 function is an alias for the keccak256() function available in solidity, which computes the Keccak-256 hash of the string passed to it. Note that this SHA3 function, used in solidity is not the NIST standard SHA-3; instead, it is Keccak-256, which is the original proposal to NIST for the SHA-3 standard competition. It was later modified slightly and standardized as the SHA-3 standard by NIST. The actual SHA-3 standard hash function will return a different hash compared to Keccak-256 (Ethereum’s sha3 function). The complete contract source code is shown as follows: pragma solidity ^0.4.0; contract PatentIdea mapping (bytes32 => bool) private hashes; bool alreadyStored; event ideahashed(bool); function saveHash(bytes32 hash) private hashes[hash] = true; function SaveIdeaHash(string idea) returns (bool) var hashedIdea = HashtheIdea(idea); if (alreadyHashed(HashtheIdea(idea))) alreadyStored=true;

Conclusion

function SaveIdeaHash(string idea) returns (bool) represents one of the many innovative layers that make blockchain technology so powerful and transformative. As distributed systems continue to evolve, a solid understanding of these core concepts becomes increasingly valuable — not just for developers, but for anyone building, investing in, or working alongside blockchain-powered systems.

Whether you are just starting your blockchain journey or deepening existing expertise, mastering these fundamentals gives you the tools to think clearly about decentralized systems and make smarter decisions in this rapidly evolving space.