Hello NEAR 👋
Hi! Let us guide you in starting and interacting with your first decentralized app (dApp) in NEAR: Hello NEAR.
Hello NEAR is a friendly dApp composed by two main components:
- A smart contract that stores and retrieves a greeting message
- A simple web-based frontend that displays the greeting and enables to change it.
Create NEAR App
If you already have Node.js installed, simply run:
npx create-near-app@latest
Use the interactive menu to set up your first project folder, we recommend you to use javascript
.
Once the folder is ready, check the README. It will show you how to build and deploy the smart contract, and start the frontend.
npm run build
npm start
Test it online with Gitpod
A new browser window will open automatically with the code, give it a minute and the frontend will pop-up (make sure the pop-up window is not blocked).
🌐 JavaScript | 🦀 Rust |
---|---|
Open in Gitpod | Open in Gitpod |
Interacting With Hello NEAR
Once the app starts you will see the screen below. Now go ahead and sign in with your NEAR account. If you don't have one, you will be able to create one in the moment.
Frontend of Hello NEAR
Once logged in, change the greeting and see how our Hello NEAR app greets you!
Structure of a dApp
Now that you understand what the dApp does, let us take a closer look to its structure:
- The frontend code lives in the
/frontend
folder. - The smart contract code is in the
/contract
folder. - The compiled smart contract can be found in
/out/main.wasm
. - The account's name in which the contract was deployed is in
/neardev/dev-account
.
Frontend
The frontend is composed by a single HTML file (frontend/index.html
). This file defines the components displayed in the screen.
The website's logic lives in frontend/index.js
, which communicates with the contract through frontend/near-interface.js
. You will notice in /frontend/index.js
the following code:
- 🌐 JavaScript
loading...
It indicates our app, when it starts, to check if the user is already logged in and execute either signedInFlow()
or signedOutFlow()
.