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: website/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.
52 changes: 52 additions & 0 deletions website/docs/0-intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
id: introduction
slug: /
title: NFT Zero to Hero
sidebar_label: Introduction
description: "Learn how to mint NFTs and build a full NFT contract step by step."
---

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.
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.

---

## Prerequisites

To complete these tutorials successfully, you'll need:

- [Rust](https://www.rust-lang.org/tools/install)
- [A Testnet wallet](https://testnet.mynearwallet.com/create)
- [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) | Mint an NFT without the need to code, create, or deploy a smart contract. |
| 2 | [Contract architecture](1-skeleton.md) | Learn the basic architecture of the NFT smart contract and compile code. |
| 3 | [Minting](2-minting.md) | Flesh out the skeleton so the smart contract can mint a non-fungible token. |
| 4 | [Upgrade a contract](2-upgrade.md) | Discover the process to upgrade an existing smart contract. |
| 5 | [Enumeration](3-enumeration.md) | Explore enumeration methods that can be used to return the smart contract's states. |
| 6 | [Core](4-core.md) | Extend the NFT contract using the core standard which allows token transfer. |
| 7 | [Events](7-events.md) | The events extension, allowing the contract to react on certain events. |
| 8 | [Approvals](5-approvals.md) | Expand the contract allowing other accounts to transfer NFTs on your behalf. |
| 9 | [Royalty](6-royalty.md) | Add NFT royalties allowing for a set percentage to be paid out to the token creator. |
| 10 | [Marketplace](8-marketplace.md) | Learn about how common marketplaces operate on NEAR and dive into some of the code that allows buying and selling NFTs. |

---

## 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 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!
160 changes: 160 additions & 0 deletions website/docs/0-predeployed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
---
id: predeployed-contract
title: Pre-deployed Contract
sidebar_label: Pre-deployed Contract
description: "Mint your first NFT using a pre-deployed contract before building your own NFT smart contract."
---

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

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.

---

## Prerequisites

To complete this tutorial successfully, you'll need [a NEAR Wallet](https://testnet.mynearwallet.com/create) and [NEAR CLI](https://docs.near.org/tools/near-cli#installation)

---

## Using the NFT contract

Minting an NFT token on NEAR is a simple process that involves calling a smart contract function.

To interact with the contract you will need to first login to your NEAR account through `near-cli`.

<hr class="subsection" />

### Setup

Log in to your newly created account with `near-cli` 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
```

<hr class="subsection" />

### Minting your NFTs

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.

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.

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

```bash
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
```
</TabItem>

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

```bash
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
```
</TabItem>
</Tabs>

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

```json
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"]}]}
Transaction Id 8RFWrQvAsm2grEsd1UTASKpfvHKrjtBdEyXu7WqGBPUr
To see the transaction in the transaction explorer, please open this url in your browser
https://testnet.nearblocks.io/txns/8RFWrQvAsm2grEsd1UTASKpfvHKrjtBdEyXu7WqGBPUr
''
```

</p>
</details>

:::tip
You can also replace the `media` URL with a link to any image file hosted on your web server.
:::

<hr class="subsection" />

### Querying your NFT

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

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

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

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

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

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

```json
[
{
"token_id": "Goi0CZ",
"owner_id": "bob.testnet",
"metadata": {
"title": "GO TEAM",
"description": "The Team Goes",
"media": "https://bafybeidl4hjbpdr6u6xvlrizwxbrfcyqurzvcnn5xoilmcqbxfbdwrmp5m.ipfs.dweb.link/",
"media_hash": null,
"copies": 1,
"issued_at": null,
"expires_at": null,
"starts_at": null,
"updated_at": null,
"extra": null,
"reference": null,
"reference_hash": null
},
"approved_account_ids": {}
}
]
```

</p>
</details>

**Congratulations!** You just minted your first NFT token on the NEAR blockchain! 🎉

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

---

## Final remarks

This basic example illustrates all the required steps to call an NFT smart contract on NEAR and start minting your own non-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 NFT 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`
- NFT standard: [NEP171](https://github.com/near/NEPs/tree/master/neps/nep-0171.md), version `1.0.0`

:::
Loading
Loading