A working example of NodeJS server-side integration with Near Protocol smart-contract
Explore other examples
·
Report Bug
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
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
- 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
- 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
💡 Before you begin, make sure you have the following installed
Follow these simple instructions to set up a local development environment
-
Clone the repo
git clone https://github.com/nearuaguild/near-server-side.git
-
Install NPM packages
yarn install
-
Copy the example env file to
.env
cp .env.dist .env
-
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
-
Build server
yarn build
-
Launch application
yarn start
We've prepared Postman collection for you to easily communicate with API once it's started
- Retrieve initial balance for account
- Then request allocation in 100 tokens for this account
- Retrieve balance one more time, and confirm that balance has changed
Distributed under the MIT License. See LICENSE.txt
for more information.