--- tags: hunt title: Scavenger Hunt 4 description: What is the `code_hash` exposed by the Guest Book contract? image: https://near.org/wp-content/themes/near-19/assets/downloads/near_logo.svg GA: UA-188414449-3 --- # Scavenger Hunt Challenge `#4` ## What is the `code_hash` exposed by the Guest Book contract? This challenge will take you on a tour of our most popular example on near.dev, the Guest Book example. You will have to follow several steps and pay close attention to what is happening but the payoff will be great: you will understand how to identify whether a specific contract has been deployed to any account on NEAR Protocol. Good luck and have fun! --- **Estimates for Time to Complete** - Fastest time: **< 1 minute** (if you already know how to do this) - Most likely time: **10 minutes** - Time to quit: **15+ minutes** (we can help you with some hints in this case) --- **Expected Response Format** - **name:** Firstname Lastname - **email:** you@example.com - **hunt:** 4 - **answer:** _(here the letter and numbers below represent a Base58 hash)_ - `account: <near account name>`` - `code_hash: ABCDEFG012345678` --- **1. Visit [near.dev](https://near.dev)** The site near.dev has several examples built by the NEAR core team and members of the community to showcase features of the platform. This isn't the complete list of sample applications! There are dozens of applications built by the community during hackathons, weekly dog-food Friday's and for the bounty and grants programs. There are also companies with systems in production that are live on NEAR MainNet today. You can learn more here: - [near.org / learn](https://near.org/learn) - [Winners of Hack the Rainbow](https://near.org/blog/winners-of-hack-the-rainbow/) - [awesomenear.com](http://awesomenear.com) **2. Open the Guest Book example** Each of the examples on near.dev are self-contained with their own documentation, GitHub repository with issues and PRs. To make it easier for developers to get started without having to setup their local environment, NEAR uses a cloud-based development environment called Gitpod that provides a one-click setup experience for developers in the browser. Take a moment to skim the Guest Book landing page. **3. Open in Gitpod (or clone the GitHub repo locally)** Whether you choose to open the example using Gitpod or clone it locally, either way you will end up with the same end result: a working development environment for building NEAR-powered dApps. The fastest way to move forward is to use Gitpod unless you already have a NodeJS development environment setup locally including git, Node 12+, VSCode (or similar). If you're familiar with these technologies and already working with them on your computer then cloning the repo is actually faster than waiting for a new Gitpod instance to spin up (which can take up to 5 minutes). **4. Deploy the contract using `yarn dev` as per instructions.** Once you've launched your development environment, whether using Gitpod or locally, you can run `yarn` to install dependencies (Gitpod does this for you, by the way) and then run `yarn dev` to automatically create a new TestNet account and deploy the Guest Book dApp. > Make sure you're using Node version 12 (**do not use Node 15**) Pay careful attention to what is logged to the terminal at this point because the name of the account will appear in your terminal. You will see a new account created with the name similar to `dev-TIMESTAMP` This is the value you should use in subsequent steps in place of `<account-name>` **5. Run `near state <account-name>`** Make sure to use the same `<account-name>` as whatever "temp" account was created by the `yarn dev` command in **step 4**. This account is the one that has the Guest Book contract deployed to it. When a contract, like Guest Book, is deployed to an account, the `code_hash` changes from its default value to a new value representing the SHA256 digest of the contract bytecode encoded as Base58. In JavaScript this looks like: ```javascript= const code_hash = Base58.encode(sha256.digest(contract_bytecode)) ``` From the above you can assume that the _same_ contract will always produce the _same_ `code_hash` which is true (assuming you have deterministic compiles or are using a copy of the same contract after having been compiled) You can experiment with generating the `code_hash` for any contract using this simple demonstration: https://github.com/near-examples/code-hash-generator **6. Format and submit your response** To submit your response to this challenge, compose your answer in the following format: ``` account: <near account name> code_hash: ABCDEFG012345678 ``` --- **Bonus: what's the default `code_hash` of _every_ new account?** All accounts start out with the same default `code_hash` which signals, to anyone who cares to look, that the account has no contract deployed to it. --- You can read more about the NEAR account system here: [[NEAR docs] concepts::account](https://docs.near.org/docs/concepts/account) You can also read more about NEAR's core contracts, the most advanced examples of contracts written for NEAR and available as open source for learning: https://github.com/near/core-contracts