# Encode Club NEAR Bootcamp 1 - DAY 1 17/01/2022 ## First session of Encode Club's NEAR Bootcamp https://youtu.be/bOY14y1Oz0I --- ## Questions: --- ## Why do I get an error message that says "Yarn is not supported on your platform"? https://youtu.be/bOY14y1Oz0I?t=3044 [Yarn](https://yarnpkg.com/) is a [package manager](https://en.wikipedia.org/wiki/Package_manager) for [Node.js](https://nodejs.org/). This occurs because you are most likely using a Mac with Apple Silicon (M1 Chips). You would need to set NodeJS to support it. You may follow the steps below to get it running. ### Configuring Node for Mac M1 #### Step 0. Pre-setup: Before you start, check and make sure your Mac shell would run in arm64 mode. This is because from macOS Big Sur and newer OS's come woth zsh as a default shell, and there's no need to install it separately anymore. To solve this, you'll have to remove the x86 compiled zsh that may have been installed via Homebrew. You can't do this with `brew remove` as Homebrew does no have enough permissions, so you will have to do it manually. Verify whether or not you are running native zsh: ``` which zsh ``` If it is not /bin/zsh, run: ``` rm "$(which zsh)" ``` #### Step 1. Install Homebrew If you have not done that yet, install Homebrew. ``` /bin/bash -c "$(curl -fsSL https://raw.Githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` Remember you'll need to enter the sudo password to authenticate and complete the installation. If you wish to opt-out of Homebrew’s default “Anonymous Aggregate User Behaviour Analytics” tracking, run the following command after the installation is complete: ``` brew analytics off ``` You should then run: ``` brew update ``` Now you should be ready to go. #### Step 2. Install Node Version Manager You should now be ready to install Node.js on your computer. Node Version Manager (nvm)is the recommended installer you should use. Run the following command: ``` $ curl -o- https://raw.Githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash ``` Install the latest version ``` $ nvm install node ``` You should then restart the terminal and run the final command: ``` $ nvm use node ``` Confirm the versions of Node and NPM that you have installed ``` $ node -v && npm -v ``` #### Step 3. Switch Architechture Confirm that you are using ``` `arm64` ``` ``` $ node -p process.arch arm64 ``` You may still need to work on x64 architecture sometimes, usually because libraries or npm packages may not be natively available on Apple Silicon yet. Switch to x64 architecture environment. ``` $ arch -x86_64 zsh ``` Verify that you have switched architectures ``` $ node -p process.arch x64 ``` #### Step 4. Install Node 14 Install Node 14 using NVM. This would download the precompiled binary. ``` $ nvm install v14 ``` Check once again to make sure the architecture is right one ``` $ node -p process.arch x64 ``` You may now return to arm64 zsh. ``` $ exit ``` Check to make sure you are using the native shell. ``` $ arch arm64 ``` #### Step 5. Use Node Whenever you want to work with Node for NEAR, you change to Node 14. Check to see what version of Node is active ``` $ node -v v17.1.0 ``` Using NVM, you should change to Node 14 ``` $ nvm use 14 Now using node v14.18.1 (npm v8.2.0) ``` Check to see what version of Node you are using ``` $ node -v v14.18.1 ``` You may now start working with NEAR. When you are done, you should return to your primary Node installation. ``` $ nvm use node Now using node v17.1.0 (npm v8.2.0) ``` Check what version of Node you are using ``` $ node -v v17.1.0 ``` --- ## How does one clone a Git repository? https://youtu.be/bOY14y1Oz0I?t=3450 To clone a repo locally, you must have git [installed](https://github.com/git-guides/install-git) on your computer. Next, you'll need the `URI` of the repo (eg https://github.com/Learn-NEAR/starter--near-sdk-as). Open the `URI` in your browser, and click the button `code` as shown in the image below. ![](https://hackmd.io/_uploads/HJpCFGgRt.png) It should produce a drop-down menu like this: ![](https://hackmd.io/_uploads/S18_3fe0t.png). ### Option 1. Cloning with `SSH`: This is the recommended, and most secure, method. This also requires the most technical ability. If you do not have `SSH` installed, you may follow this [link](https://docs.github.com/en/authentication/connecting-to-github-with-ssh) for instructions. Once you are done, click on the `SSH` tab on the `Code` drop down menu: ![](https://hackmd.io/_uploads/rJz50MgAF.png) and copy the `URI` displayed there. It should be something like `git@github.com:<Account>/<repo>.git`. Remember to replace `<Account>` and `<repo>` with the respective account and repo names. You then open your command prompt and type in: ``` git clone git@github.com:Git-Account/repo.git ``` ### Option 2. Clone with `HTTPS` If you decide to clone the repo using `HTTPS`, you should copy the `URI` in shown in the `HTTPS` tab in the `Clone` menu ![](https://hackmd.io/_uploads/rkRrLmeAY.png). You type the following in your terminal: ``` git clone https://github.com/<Account>/<repo>.git ``` Remember to replace `<Account>` and `<repo>` with the respective account and repo names. ### Option 3.GitHub CLI If you have `the GitHub CLI` installed -see how to install it [here](https://cli.github.com/manual/installation)- you should copy the link in from the `GitHub CLI` button ![](https://hackmd.io/_uploads/SkoBQNgAt.png) In your terminal you then type: ``` gh repo clone <Account>/<repo> ``` Remember to replace `<Account>` and `<repo>` with the respective account and repo names. Once you are done, you `cd` into the local repo, and may now start work. --- ## I cannot seem to run NEAR on Windows. https://youtu.be/bOY14y1Oz0I?t=3142 To run NEAR on Windows,you'll need to have Windows Subsystem for Linux (WSL) installed,and switch to it. ### Install WSL through the Command Line If you are running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11, installing WSL is an easy process. Check your Windows version and build number by selecting the Windows logo key + R, type `winver`, select `OK`. You can update to the latest Windows version by selecting Start > Settings > Windows Update > [Check for updates](ms-settings:windowsupdate). Once you are ready, open up PowerShell and enter the following command: ``` wsl --install ``` This would enable required optional components, download the latest Linux kernel, set WSL2 as your default, and install a Linux distribution for you. It installs Ubuntu by default. If you want a different Linux distribution see the directions below. To see the list of Linux distributions availabe for download run: ``` wsl --list --online ``` or ``` wsl -l -o ``` You then enter `wsl --install -d <Distro>`. Remember to replace `<Distro>` with the name of the distribution you want to install. If you want to install additional distributions, you simply run `wsl --install -d <Distro>` again as many times as you want, simply replacing `<Distro>` each time with the name of the new distribution you would like to install. If you want to install additional distributions from inside a Linux/Bash commad line (as opposed to from PowerShell or Command Prompt), you must use `wsl.exe` instead: ``` wsl.exe --install -d <Distro> ``` To check the version of WSL you are using, type `wsl -l -v` in PowerShell. To set your default version, use the command `wsl --set-default-version <Version#>`, replacing <Version#> with either 1 or 2. ### Manual installation If you are either using an older build of Windows 10, or prefer to install WSL manually, you should take the following steps to complete the process. #### Step 1. Enable the Windows Subsytem for Linux: You have to enable the "Windows Subsystem for Linux" option first before you can install any Linux distribution on Windows. Open PowerShell as Administrator (Start menu > PowerShell > right-click > Run as Administrator) and run: ``` dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart ``` While it is recommended that you update to WSL 2 (shown in [step2](#requirements), you may decideto only install WSL 1. If so, restart your computer and jump to [Step 6](#installation). #### Step 2. Check the requirements for running WSL 2: You'll need to have Windows 10 to be able to update to WSL 2. For x86 systems you need to have *Version 1903*or higher, with *Build 18362* or higher. If you are using an ARM64 computer, you need to be running *Version 2004* or higher, with *Build 19041* or higher. Builds lower than *183862* do not support WSL 2. You canuse the [Windows Update Assistant](https://www.microsoft.com/software-download/windows10) to update your Windows version. You can check your version and build number by selecting *Windows logo key + R*, typing `winver`, select *OK*. #### Step 3. Enable the Virtual Machine: *Virtual Machine Platform*'s optional feature must be enabled before WSL 2 can be installed. First check to make sure your computer has [virtualization capabilities](https://docs.microsoft.com/en-us/windows/wsl/troubleshooting#error-0x80370102-the-virtual-machine-could-not-be-started-because-a-required-feature-is-not-installed). Open PowerShell as Adminstrator and run this: ``` dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart ``` You may then restart your machine to complete the WSL installation and update to WSL 2. #### Step 4. Download the Linux Kernel update package: Download the latest Linux kernel package. Use this [link](https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi) for x64 machines, and this [one](https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_arm64.msi) if your machine is ARM64. If you don't know what machine you are using, open PowerShell or Command Prompt and type ``` systeminfo | find "System Type" ``` #### Step 5 - Set WSL 2 as your default version: Run the following command in PowerShell to set WSL 2 as the default version when installing a new Linux distribution: ``` wsl --set-default-version 2 ``` #### Step 6. Install your favorite Linux distribution: On your computer, go to the [Microsoft Store](https://aka.ms/wslstore) and choose your preferred Linux distribution. ![](https://hackmd.io/_uploads/H1CnNfhTK.png) From the distribution's page, you select "GET". ![](https://hackmd.io/_uploads/S12wKfnaY.png) And now you are good to go. ## I get an "account does not exist" error https://youtu.be/bOY14y1Oz0I?t=3644 Server error says "account does not exist." You are most likely using wrong account id. Check to make sure you are using the correct id, make the neccessary changes, and try running the contract again. ## What version of Yarn should be used? https://youtu.be/bOY14y1Oz0I?t=3724 Try using the latest one possible, whenever you can. ## I get a "no such directory open" https://youtu.be/bOY14y1Oz0I?t=3783 You are working in the wrong directory. Run `pwd` to find out where you are, and then try and find your way to the correct place and run the script you were working on again. ###### tags: `bootcamp transcripts`