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:
Use the interactive menu to set up your first project folder, we recommend you to use
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
Test it online with 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
- The smart contract code is in the
- The compiled smart contract can be found in
- The account's name in which the contract was deployed is in
The contract presents 2 methods:
get_greeting. The first one stores a
String in the contract's parameter
message, while the second one retrieves it. By default, the contract returns the message
- 🦀 Rust
When writing smart contracts, it is very important to test all methods exhaustively. This
project has both unit and integration tests. Before digging into their code,
go ahead and execute them using the command
npm run test.
Unit tests check individual functions in the smart contract. They are written in the
same language as the smart contract. If your contract is in Rust, you will find the tests at the bottom of
- 🦀 Rust
In this way, integration tests simulate user interactions in a realistic scenario.
You will find the integration tests for
That's it for our first quickstart tutorial. You have now seen a fully functional contract with a minimal user interface and testing.
If you have any questions, do not hesitate to join us on Discord. We regularly host Office Hours, in which you can join our voice channel and ask questions.