sarangparikh22 / token-contract-as

Implementation of token contract similar to ERC20.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Token Contract in AssemblyScript

Open in Gitpod

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.

Getting started

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.

Quick option

  1. Install dependencies:

    yarn

  2. Build and deploy this smart contract to a development account. This development account will be created automatically and is not intended for reuse:

    yarn dev

Standard deploy option

In this second option, the smart contract will get deployed to a specific account created with the NEAR Wallet.

  1. Ensure near-shell is installed by running:

    near --version
    

    If needed, install near-shell:

    npm install near-shell -g
    
  2. If you do not have a NEAR account, please create one with NEAR Wallet. Then, in the project root, login with near-shell by following the instructions after this command:

    near login
    
  3. 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! */
    
  4. Start the example!

    yarn start
    

Exploring The Code

  1. The backend code lives in the /assembly folder. 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.
  2. The frontend code lives in the /src folder. /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.
  3. Tests: there are different kinds of tests for the frontend and backend. The backend code gets tested with the asp command for running the backend AssemblyScript tests, and jest for running frontend tests. You can run both of these at once with yarn test.

Both contract and client-side code will auto-reload as you change source files.

About

Implementation of token contract similar to ERC20.

License:Apache License 2.0


Languages

Language:JavaScript 52.2%Language:TypeScript 34.7%Language:HTML 11.9%Language:Dockerfile 1.2%