Skip to content

Commit 3ad92e1

Browse files
committed
docs
1 parent 4f7f993 commit 3ad92e1

42 files changed

Lines changed: 6176 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/deploy.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
# Review gh actions docs if you want to further define triggers, paths, etc
8+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
9+
10+
defaults:
11+
run:
12+
working-directory: ./website
13+
14+
jobs:
15+
build:
16+
name: Build Docusaurus
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: 20
25+
# cache: yarn
26+
27+
- name: Install dependencies
28+
run: yarn install --frozen-lockfile
29+
- name: Build website
30+
run: yarn build
31+
32+
- name: Upload Build Artifact
33+
uses: actions/upload-pages-artifact@v3
34+
with:
35+
path: website/build
36+
37+
deploy:
38+
name: Deploy to GitHub Pages
39+
needs: build
40+
41+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
42+
permissions:
43+
pages: write # to deploy to Pages
44+
id-token: write # to verify the deployment originates from an appropriate source
45+
46+
# Deploy to the github-pages environment
47+
environment:
48+
name: github-pages
49+
url: ${{ steps.deployment.outputs.page_url }}
50+
51+
runs-on: ubuntu-latest
52+
steps:
53+
- name: Deploy to GitHub Pages
54+
id: deployment
55+
uses: actions/deploy-pages@v4
56+

.github/workflows/test-deploy.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Test deployment
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
# Review gh actions docs if you want to further define triggers, paths, etc
8+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
9+
10+
defaults:
11+
run:
12+
working-directory: ./website
13+
14+
jobs:
15+
test-deploy:
16+
name: Test deployment
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: 20
25+
# cache: yarn
26+
27+
- name: Install dependencies
28+
run: yarn install --frozen-lockfile
29+
- name: Test build website
30+
run: yarn build
31+

website/.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
6+
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
10+
11+
# Misc
12+
.DS_Store
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*

website/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Website
2+
3+
This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.
4+
5+
## Installation
6+
7+
```bash
8+
yarn
9+
```
10+
11+
## Local Development
12+
13+
```bash
14+
yarn start
15+
```
16+
17+
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
18+
19+
## Build
20+
21+
```bash
22+
yarn build
23+
```
24+
25+
This command generates static content into the `build` directory and can be served using any static contents hosting service.
26+
27+
## Deployment
28+
29+
Using SSH:
30+
31+
```bash
32+
USE_SSH=true yarn deploy
33+
```
34+
35+
Not using SSH:
36+
37+
```bash
38+
GIT_USER=<Your GitHub username> yarn deploy
39+
```
40+
41+
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.

website/docs/0-intro.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
id: introduction
3+
title: NFT Zero to Hero
4+
sidebar_label: Introduction
5+
description: "Learn how to mint NFTs and build a full NFT contract step by step."
6+
---
7+
8+
In this _Zero to Hero_ series, you'll find a set of tutorials that will cover every aspect of a non-fungible token (NFT) smart contract.
9+
You'll start by minting an NFT using a pre-deployed contract and by the end you'll end up building a fully-fledged NFT smart contract that supports every extension.
10+
11+
---
12+
13+
## Prerequisites
14+
15+
To complete these tutorials successfully, you'll need:
16+
17+
- [Rust](https://www.rust-lang.org/tools/install)
18+
- [A Testnet wallet](https://testnet.mynearwallet.com/create)
19+
- [NEAR-CLI](/tools/near-cli#installation)
20+
- [cargo-near](https://github.com/near/cargo-near)
21+
22+
:::info New to Rust?
23+
If you are new to Rust and want to dive into smart contract development, our [Quick-start guide](../../smart-contracts/quickstart.md) is a great place to start
24+
:::
25+
26+
---
27+
28+
## Overview
29+
30+
These are the steps that will bring you from **_Zero_** to **_Hero_** in no time! 💪
31+
32+
| Step | Name | Description |
33+
|------|---------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
34+
| 1 | [Pre-deployed contract](/tutorials/nfts/predeployed-contract) | Mint an NFT without the need to code, create, or deploy a smart contract. |
35+
| 2 | [Contract architecture](/tutorials/nfts/skeleton) | Learn the basic architecture of the NFT smart contract and compile code. |
36+
| 3 | [Minting](/tutorials/nfts/minting) | Flesh out the skeleton so the smart contract can mint a non-fungible token. |
37+
| 4 | [Upgrade a contract](/tutorials/nfts/upgrade-contract) | Discover the process to upgrade an existing smart contract. |
38+
| 5 | [Enumeration](/tutorials/nfts/enumeration) | Explore enumeration methods that can be used to return the smart contract's states. |
39+
| 6 | [Core](/tutorials/nfts/core) | Extend the NFT contract using the core standard which allows token transfer. |
40+
| 7 | [Events](/tutorials/nfts/events) | The events extension, allowing the contract to react on certain events. |
41+
| 8 | [Approvals](/tutorials/nfts/approvals) | Expand the contract allowing other accounts to transfer NFTs on your behalf. |
42+
| 9 | [Royalty](/tutorials/nfts/royalty) | Add NFT royalties allowing for a set percentage to be paid out to the token creator. |
43+
| 10 | [Marketplace](/tutorials/nfts/marketplace) | Learn about how common marketplaces operate on NEAR and dive into some of the code that allows buying and selling NFTs. |
44+
45+
---
46+
47+
## Next steps
48+
49+
Ready to start? Jump to the [Pre-deployed Contract](/tutorials/nfts/predeployed-contract) tutorial and begin your learning journey!
50+
51+
If you already know about non-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!

website/docs/0-predeployed.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
---
2+
id: predeployed-contract
3+
title: Pre-deployed Contract
4+
sidebar_label: Pre-deployed Contract
5+
description: "Mint your first NFT using a pre-deployed contract before building your own NFT smart contract."
6+
---
7+
8+
import Tabs from '@theme/Tabs';
9+
import TabItem from '@theme/TabItem';
10+
11+
Create your first non-fungible token by using a pre-deployed NFT smart contract which works exactly as the one you will build on this tutorial.
12+
13+
---
14+
15+
## Prerequisites
16+
17+
To complete this tutorial successfully, you'll need [a NEAR Wallet](https://testnet.mynearwallet.com/create) and [NEAR CLI](/tools/near-cli#installation)
18+
19+
---
20+
21+
## Using the NFT contract
22+
23+
Minting an NFT token on NEAR is a simple process that involves calling a smart contract function.
24+
25+
To interact with the contract you will need to first login to your NEAR account through `near-cli`.
26+
27+
<hr class="subsection" />
28+
29+
### Setup
30+
31+
Log in to your newly created account with `near-cli` by running the following command in your terminal:
32+
33+
```bash
34+
near account import-account using-web-wallet network-config testnet
35+
```
36+
37+
Set an environment variable for your account ID to make it easy to copy and paste commands from this tutorial:
38+
39+
```bash
40+
export NEARID=YOUR_ACCOUNT_NAME
41+
```
42+
43+
<hr class="subsection" />
44+
45+
### Minting your NFTs
46+
47+
We have already deployed an NFT contract to `nft.examples.testnet` which allows users to freely mint tokens. Let's use it to mint our first token.
48+
49+
Run this command in your terminal, remember to replace the `token_id` with a string of your choice. This string will uniquely identify the token you mint.
50+
51+
<Tabs groupId="cli-tabs">
52+
<TabItem value="short" label="Short">
53+
54+
```bash
55+
near call nft.examples.testnet nft_mint '{"token_id": "TYPE_A_UNIQUE_VALUE_HERE", "receiver_id": "'$NEARID'", "metadata": { "title": "GO TEAM", "description": "The Team Goes", "media": "https://bafybeidl4hjbpdr6u6xvlrizwxbrfcyqurzvcnn5xoilmcqbxfbdwrmp5m.ipfs.dweb.link/", "copies": 1}}' --gas 100000000000000 --deposit 0.1 --accountId $NEARID --networkId testnet
56+
```
57+
</TabItem>
58+
59+
<TabItem value="full" label="Full">
60+
61+
```bash
62+
near contract call-function as-transaction nft.examples.testnet nft_mint json-args '{"token_id": "TYPE_A_UNIQUE_VALUE_HERE", "receiver_id": "'$NEARID'", "metadata": { "title": "GO TEAM", "description": "The Team Goes", "media": "https://bafybeidl4hjbpdr6u6xvlrizwxbrfcyqurzvcnn5xoilmcqbxfbdwrmp5m.ipfs.dweb.link/", "copies": 1}}' prepaid-gas '100.0 Tgas' attached-deposit '0.1 NEAR' sign-as $NEARID network-config testnet sign-with-keychain send
63+
```
64+
</TabItem>
65+
</Tabs>
66+
67+
<details>
68+
<summary>Example response: </summary>
69+
<p>
70+
71+
```json
72+
Log [nft.examples.testnet]: EVENT_JSON:{"standard":"nep171","version":"nft-1.0.0","event":"nft_mint","data":[{"owner_id":"benjiman.testnet","token_ids":["TYPE_A_UNIQUE_VALUE_HERE"]}]}
73+
Transaction Id 8RFWrQvAsm2grEsd1UTASKpfvHKrjtBdEyXu7WqGBPUr
74+
To see the transaction in the transaction explorer, please open this url in your browser
75+
https://testnet.nearblocks.io/txns/8RFWrQvAsm2grEsd1UTASKpfvHKrjtBdEyXu7WqGBPUr
76+
''
77+
```
78+
79+
</p>
80+
</details>
81+
82+
:::tip
83+
You can also replace the `media` URL with a link to any image file hosted on your web server.
84+
:::
85+
86+
<hr class="subsection" />
87+
88+
### Querying your NFT
89+
90+
To view tokens owned by an account you can call the NFT contract with the following `near-cli` command:
91+
92+
<Tabs groupId="cli-tabs">
93+
<TabItem value="short" label="Short">
94+
95+
```bash
96+
near view nft.examples.testnet nft_tokens_for_owner '{"account_id": "'$NEARID'"}' --networkId testnet
97+
```
98+
</TabItem>
99+
100+
<TabItem value="full" label="Full">
101+
102+
```bash
103+
near contract call-function as-read-only nft.examples.testnet nft_tokens_for_owner json-args '{"account_id": "'$NEARID'"}' network-config testnet now
104+
```
105+
</TabItem>
106+
</Tabs>
107+
108+
<details>
109+
<summary>Example response: </summary>
110+
<p>
111+
112+
```json
113+
[
114+
{
115+
"token_id": "Goi0CZ",
116+
"owner_id": "bob.testnet",
117+
"metadata": {
118+
"title": "GO TEAM",
119+
"description": "The Team Goes",
120+
"media": "https://bafybeidl4hjbpdr6u6xvlrizwxbrfcyqurzvcnn5xoilmcqbxfbdwrmp5m.ipfs.dweb.link/",
121+
"media_hash": null,
122+
"copies": 1,
123+
"issued_at": null,
124+
"expires_at": null,
125+
"starts_at": null,
126+
"updated_at": null,
127+
"extra": null,
128+
"reference": null,
129+
"reference_hash": null
130+
},
131+
"approved_account_ids": {}
132+
}
133+
]
134+
```
135+
136+
</p>
137+
</details>
138+
139+
**Congratulations!** You just minted your first NFT token on the NEAR blockchain! 🎉
140+
141+
Now try going to your [NEAR Wallet](https://testnet.mynearwallet.com) and view your NFT in the "Collectibles" tab.
142+
143+
---
144+
145+
## Final remarks
146+
147+
This basic example illustrates all the required steps to call an NFT smart contract on NEAR and start minting your own non-fungible tokens.
148+
149+
Now that you're familiar with the process, you can jump to [Contract Architecture](/tutorials/nfts/skeleton) and learn more about the smart contract structure and how you can build your own NFT contract from the ground up.
150+
151+
***Happy minting!*** 🪙
152+
153+
:::note Versioning for this article
154+
155+
At the time of this writing, this example works with the following versions:
156+
157+
- near-cli-rs: `0.17.0`
158+
- NFT standard: [NEP171](https://github.com/near/NEPs/tree/master/neps/nep-0171.md), version `1.0.0`
159+
160+
:::

0 commit comments

Comments
 (0)