Table of Contents
This project is created for easy-to-start as a React + Rust loyalty program with fungible tokens template in the Pagoda Gallery. It was initialized with [create-near-app]. Use this template and start to build your own gallery project!
[create-near-app]
Make sure you have a current version of Node.js installed – we are targeting versions 16+
.
Read about other prerequisites in our docs.
Install all dependencies:
npm install
Build your contract:
npm run build
Deploy your contract to TestNet with a temporary dev account:
npm run deploy
Important note: only the factory contract is and should be deployed. This is done automatically when using npm run deploy
command. Two other contracts (ft contract and manager contract) should only be deployed by the factory contract.
The loyalty program with the fungible token template provides a way for merchants to create a fungible token program with just a few clicks.
The template consists of the following modules:
- 3 smart contracts: factory contract, fungible token contract and manager contract
- backend.js that serves as a web2 backend
- frontend that provides the UI for the customer and the merchant
This template features three smart contracts:
- factory contract - this is the contract that is deployed by the user. The contract uses a factory pattern to deploy fungible token contract and manager contract for each merchant that logs in and creates a loyalty program with the UI. See factory-rust for a simple factory pattern.
- fungible token contract - this is a standard fungible token contract. Read more about the FTs here.
- manager contract - this contract manages the whole loaylty program flow
Frontend consists of two views:
- merchant view - this is the view where a merchant can create a loyalty program. The merchant needs to log in first.
- customer view - the view used by the customer to use the loyalty program and gain fungible tokens. This view is hidden until a merchant creates a loaylty program. The customer does not have to log in or create an account in order to use the loyalty program.
Backend.js is a simple web2 backend simulated on the frontend in this template.
Start your frontend:
npm run dev
Important note: This project uses a browser local storage to store important data. Be sure to always run it in the same browser. It won't work in an incognito mode.
Test your contract:
npm test
- The smart-contract code lives in the
/contracts
folder. - The frontend code lives in the
/frontend
folder./frontend/index.html
is a great place to start exploring. Note that it loads in/frontend/pages/index.js
, this is your entrypoint to learn how the frontend connects to the NEAR blockchain. - There is a backend code in the
backend.js
file in thefrontend
directory. This code simulates a web2 backend. - Test your contract:
npm test
, this will run the tests inintegration-tests
directory.
Loyalty Program with Fungible Tokens Template follows good practices of security, but 100% security cannot be assured. Loyalty Program with Fungible Tokens Template is provided "as is" without any warranty. Use at your own risk.