Skip to content

A working example of NodeJS server-side integration with Near Protocol smart-contract 🫡

License

Notifications You must be signed in to change notification settings

nearuaguild/near-server-side

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Near Protocol | Server-Side

A working example of NodeJS server-side integration with Near Protocol smart-contract

Explore other examples · Report Bug

Developed by

Near Ukrainians Guild cover

Near Ukrainians Guild is a fast-growing guild aimed at providing high-quality educational content and assistance to grow a strong community of Ukrainian developers/entrepreneurs in the Near Protocol ecosystem

Twitter Youtube Telegram Chat Telegram Channel Medium Github


About The Project

This example is basically a Fungible Token faucet API which provides a possibility to distribute tokens among users by their request

Implementing server-side integration for communication with Near Protocol smart-contract has its own pros & cons - you must consider them when planning the use cases of your application

Pros

  • Additional features can be implemented (Authorization, Notifications, Delayed execution, etc)
  • End users don't need to have deep knowledge about smart contracts, because they have a way to communicate through well-known REST API

Cons

  • Transactions that change state aren't free and must be paid - you'll pay for them
  • Your application has to implement rate limits, so your Near funds wouldn't fire covering millions of unnecessary transactions
  • Your smart contract's change methods must be closed from calling directly by the end-user otherwise someone would definitely call it directly avoiding your authorization

Built With


Getting Started

💡 Before you begin, make sure you have the following installed

Installation

Follow these simple instructions to set up a local development environment

  1. Clone the repo

    git clone https://github.com/nearuaguild/near-server-side.git
  2. Install NPM packages

    yarn install
  3. Copy the example env file to .env

    cp .env.dist .env
  4. Enter your Fungible Token contract address & private key in .env (variables below are just examples, you must fill them with your own values)

     CONTRACT_ID=test_ft_token.denbite.testnet
    
     PRIVATE_KEY=ed25519:14sZJ64JFLxuocU7xu2DkV2yE7mAGCnfFhjbH10vQePR32JzpcMVK63jSSHgzb29mBzEMv27Sqs87SHsR3PMxhp6
  5. Build server

    yarn build
  6. Launch application

    yarn start

Usage

We've prepared Postman collection for you to easily communicate with API once it's started

Demo

  1. Retrieve initial balance for account
  2. Then request allocation in 100 tokens for this account
  3. Retrieve balance one more time, and confirm that balance has changed

License

Distributed under the MIT License. See LICENSE.txt for more information.

About

A working example of NodeJS server-side integration with Near Protocol smart-contract 🫡

Topics

Resources

License

Stars

Watchers

Forks