This project contains an implementation of a token contract similar to ERC20 but simpler. We'll visit a page, sign in and use your browser's console to run commands to initialize, send, and get the balance of a custom token.
Note: this example uses a basic version of a token. It is not the supported token contract laid out in the NEAR Enhancement Proposal for non-fungible tokens. Visit this example illustrating implementations of the non-fungible token in Rust and AssemblyScript. It is not recommended to deploy non-fungible tokens written in AssemblyScript for financial use cases.
There's a button at the top of this file that says "Open in Gitpod." If you want to try out this project as fast as possible, that's what you want. It will open the project in your browser with a complete integrated development environment configured for you. If you want to run the project yourself locally, read on.
There are two ways to run this project locally. The first is quick, and a good way to instantly become familiar with this example. Once familiar, the next step is to create your own NEAR account and deploy the contract to testnet.
Build and deploy this smart contract to a development account. This development account will be created automatically and is not intended for reuse:
In this second option, the smart contract will get deployed to a specific account created with the NEAR Wallet.
near-cli is installed by running:
If needed, install
npm install near-cli -g
If you do not have a NEAR account, please create one with NEAR Wallet. Then, in the project root, login with
near-cli by following the instructions after this command:
Modify the top of
src/config.js, changing the
CONTRACT_NAME to be the NEAR account that you just used to log in.
const CONTRACT_NAME = process.env.CONTRACT_NAME || 'YOUR_ACCOUNT_NAME_HERE'; / TODO: fill this in! /
Start the example!
/assemblyfolder. This code gets deployed to the NEAR blockchain when you run
yarn deploy:contract. This sort of code-that-runs-on-a-blockchain is called a "smart contract" – learn more about NEAR smart contracts.
/srcfolder. /src/index.html is a great place to start exploring. Note that it loads in
/src/main.js, where you can learn how the frontend connects to the NEAR blockchain.
Both contract and client-side code will auto-reload as you change source files.