
Examples

Hello World
A simple smart contract that stores a
string message on its state. Open in NearPlay
Counter
A friendly counter that stores a number with methods to increment, decrement, and reset it. Open in NearPlay

Guest Book
Users can sign the guest book, optionally paying
0.01 Ⓝ to mark their messages as “premium”. Open in NearPlay
Donation
Forward NEAR tokens to a beneficiary while tracking all donations. Learn how contracts handle token transfers. Open in NearPlay

Coin Flip
Guess the outcome of a coin flip and earn points. Demonstrates how to handle randomness on the blockchain. Open in NearPlay
Structure of the Examples
All examples follow a consistent structure, making it easy to navigate between them. Each repository contains the same smart contract implemented in Rust, Javascript, and sometimes Python, along with a simple frontend to interact with the contract.Frontend
Each example includes a Next.JS frontend that is very simple to start:NEAR Connector Hooks
All frontends usenear-connect-hooks, which wrap the functionality of NEAR Connector to handle the connection between the web app and the NEAR blockchain.
The near-connect-hooks expose a NearProvider that is used to wrap the entire application, usually in pages/_app.js:
We can then use the
useNearWallet hook within any component to access all NEAR-related functionality, such as login/logout, view and call functions, and sign transactions:
Smart Contract
All repositories include the same smart contract implemented in different languages, including Rust, Javascript, and sometimes Python. The contracts are implemented following the latest versions of each SDK, and include sandbox tests showcasing how to properly test smart contracts in a realistic environment.Testing
Each contract includes sandbox tests that simulate real user interactions. For example, in theGuest Book example, the tests cover scenarios like having multiple accounts signing the guest book, including premium messages.
- 🦀 Rust
- 🌐 JavaScript
- 🐍 Python
Creating an Account
All smart contracts can be built and deployed using theNEAR CLI. A good first step is to always create a new NEAR account to deploy your contract:
Building & Deploying
Once you created an account to host the contract, you can build and deploy it:- 🦀 Rust
- 🌐 JavaScript
- 🐍 Python
Interacting via CLI
Once your contract is deployed, check theREADME.md of each repository to see the available methods you can call.
As a general guide, the NEAR CLI has two main ways to interact with smart contracts:
Moving Forward
After exploring these basic examples, you can:- Modify the contracts - Try adding new functionality to deepen your understanding
- Learn the fundamentals - Check out Contract Anatomy and Storage