Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Deploy to GitHub Pages

on:
push:
branches:
- main
# Review gh actions docs if you want to further define triggers, paths, etc
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on

defaults:
run:
working-directory: ./website

jobs:
build:
name: Build Docusaurus
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn

- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build website
run: yarn build

- name: Upload Build Artifact
uses: actions/upload-pages-artifact@v3
with:
path: build

deploy:
name: Deploy to GitHub Pages
needs: build

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source

# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

31 changes: 31 additions & 0 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test deployment

on:
pull_request:
branches:
- main
# Review gh actions docs if you want to further define triggers, paths, etc
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on

defaults:
run:
working-directory: ./website

jobs:
test-deploy:
name: Test deployment
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
# cache: yarn

- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Test build website
run: yarn build

20 changes: 20 additions & 0 deletions website/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
41 changes: 41 additions & 0 deletions website/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Website

This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.

## Installation

```bash
yarn
```

## Local Development

```bash
yarn start
```

This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.

## Build

```bash
yarn build
```

This command generates static content into the `build` directory and can be served using any static contents hosting service.

## Deployment

Using SSH:

```bash
USE_SSH=true yarn deploy
```

Not using SSH:

```bash
GIT_USER=<Your GitHub username> yarn deploy
```

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
53 changes: 53 additions & 0 deletions website/docs/0-intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
id: intro
slug: /
title: Fungible Tokens Zero to Hero
sidebar_label: Introduction
description: "Master NEAR fungible tokens from pre-deployed contracts to building fully-featured FT smart contracts."
---

In this _Zero to Hero_ series, you'll find a set of tutorials covering every aspect of a fungible token (FT) smart contract. You'll start by interacting with a pre-deployed contract and by the end you'll have built a fully-fledged FT smart contract that supports every extension of the standards.

---

## Prerequisites

To complete these tutorials successfully, you'll need:

- [Rust](https://docs.near.org/smart-contracts/quickstart#prerequisites)
- [A NEAR wallet](https://testnet.mynearwallet.com)
- [NEAR-CLI](https://docs.near.org/tools/near-cli#installation)
- [cargo-near](https://github.com/near/cargo-near)

:::info New to Rust?
If you are new to Rust and want to dive into smart contract development, our [Quick-start guide](https://docs.near.org/smart-contracts/quickstart) is a great place to start.
:::

---

## Overview

These are the steps that will bring you from **_Zero_** to **_Hero_** in no time! 💪

| Step | Name | Description |
| ---- | ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| 1 | [Pre-deployed contract](0-predeployed.md) | Receive FTs without the need to code, create, or deploy a smart contract. |
| 2 | [Contract architecture](1-skeleton.md) | Learn the basic architecture of the FT smart contract and compile the code. |
| 3 | [Defining a Token](2-define-a-token.md) | Flesh out what it means to have a FT and how you can customize your own. |
| 4 | [Circulating Supply](3-circulating-supply.md) | Learn how to create an initial supply and have the token show up in your wallet. |
| 5 | [Registering Accounts](4.storage.md) | Explore how you can implement and understand the storage management standard to avoid malicious users from draining your funds. |
| 6 | [Transferring FTs](5.transfers.md) | Learn how to transfer FTs and discover some of the true powers that the core standard brings |
| 7 | [Marketplace](6-marketplace.md) | Learn about how common marketplaces operate on NEAR and dive into some of the code that allows buying and selling NFTs by using Fungible Tokens. |

<!--
1. [Events](/tutorials/fts/events): in this tutorial you'll explore the events extension, allowing the contract to react on certain events.
1. [Marketplace](/tutorials/fts/marketplace): in the last tutorial you'll be exploring some key aspects of the marketplace contract.
-->

---

## Next steps

Ready to start? Jump to the [Pre-deployed Contract](0-predeployed.md) tutorial and begin your learning journey!

If you already know about fungible tokens and smart contracts, feel free to skip and jump directly to the tutorial of your interest. The tutorials have been designed so you can start at any given point!
146 changes: 146 additions & 0 deletions website/docs/0-predeployed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
id: predeployed-contract
title: Pre-deployed Contract
sidebar_label: Pre-deployed Contract
description: "Learn how to easily receive fungible tokens without coding."
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

Learn how to easily receive fungible tokens without doing any software development by using a readily-available FT smart contract.

---

## Prerequisites

To complete this tutorial successfully, you'll need:

- [A NEAR testnet account](https://testnet.mynearwallet.com)
- [NEAR-CLI](https://docs.near.org/tools/near-cli/#installation)

---

## Using the FT contract

Create a new `testnet` account using the [web wallet](https://testnet.mynearwallet.com).

### Setup

Log in to your newly created account with `near-cli-rs` by running the following command in your terminal:

```bash
near account import-account using-web-wallet network-config testnet
```

Set an environment variable for your account ID to make it easy to copy and paste commands from this tutorial:

```bash
export NEARID=YOUR_ACCOUNT_NAME
```
:::note

Be sure to replace `YOUR_ACCOUNT_NAME` with the account name you just logged in with including the `.testnet`.

:::

Test that the environment variable is set correctly by running:

```bash
echo $NEARID
```

<hr className="subsection" />

### Receiving Fungible Tokens

NEAR has deployed a new Fungible Token contract to the account `ft.predeployed.examples.testnet` which allows users to freely receive some `gtNEAR` - a new fungible token aimed to promote the power of teamwork! Each `gtNEAR` is equal to `1e24 yocto-gtNEAR` similar to how 1 $NEAR is equal to 1e24 yoctoNEAR.

Using this pre-deployed contract, let's get some gtNEAR!

Start by calling the method `ft_mint` which is a custom function implemented on this contract in order to send your account some `gtNEAR`! The following command will send `0.01 gtNEAR` to your account.

<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">

```bash
near call ft.predeployed.examples.testnet ft_mint '{"account_id": "'$NEARID'", "amount": "10000000000000000000000"}' --gas 100000000000000 --accountId $NEARID --networkId testnet
```
</TabItem>

<TabItem value="full" label="Full">

```bash
near contract call-function as-transaction ft.predeployed.examples.testnet ft_mint json-args '{"account_id": "'$NEARID'", "amount": "10000000000000000000000"}' prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' sign-as $NEARID network-config testnet sign-with-keychain send
```
</TabItem>
</Tabs>

<details>
<summary>Example response: </summary>
<p>

```json
Log [ft.predeployed.examples.testnet]: EVENT_JSON:{"standard":"nep141","version":"1.0.0","event":"ft_mint","data":[{"owner_id":"benjiman.testnet","amount":"10000000000000000000000","memo":"FTs Minted"}]}
Transaction Id Fhqa8YDLKxnxM9jjHCPN4hn1w1RKESYrav3kwDjhWWUu
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/Fhqa8YDLKxnxM9jjHCPN4hn1w1RKESYrav3kwDjhWWUu
''
```

</p>
</details>

To view tokens owned by an account you can call the FT contract with the following `near-cli` command:

<Tabs groupId="cli-tabs">
<TabItem value="short" label="Short">

```bash
near view ft.predeployed.examples.testnet ft_balance_of '{"account_id": "'$NEARID'"}' --networkId testnet
```
</TabItem>

<TabItem value="full" label="Full">

```bash
near contract call-function as-read-only ft.predeployed.examples.testnet ft_balance_of json-args '{"account_id": "'$NEARID'"}' network-config testnet now
```
</TabItem>
</Tabs>

<details>
<summary>Example response: </summary>
<p>

```json
'10000000000000000000000'
```

</p>
</details>

***Congratulations! You just received your first Team Tokens on the NEAR blockchain!*** 🎉

👉 Now try going to your [NEAR Wallet](https://testnet.mynearwallet.com) and view your FTs in the "Balances" tab. 👈

:::note Pre-deployed Contract
The contract used in this section has been modified such that you can infinitely get `gtNEAR` by calling `ft_mint`. This function is not part of the FT [standards](https://github.com/near/NEPs/tree/master/neps/nep-0141.md) and has been implemented for the purpose of this tutorial.
:::

---

## Final remarks

This basic example illustrates all the required steps to call an FT smart contract on NEAR and receive your own fungible tokens.

Now that you're familiar with the process, you can jump to [Contract Architecture](1-skeleton.md) and learn more about the smart contract structure and how you can build your own FT contract from the ground up.

***Happy minting!*** 🪙

:::note Versioning for this article

At the time of this writing, this example works with the following versions:

- near-cli-rs: `0.17.0`
:::
Loading