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_target:
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.
55 changes: 55 additions & 0 deletions website/docs/0-intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
id: introduction
slug: /
title: NFT Zero to Hero JavaScript Edition
sidebar_label: Introduction
description: "Learn NFTs from minting to building a full-featured smart contract in this Zero to Hero series."
---

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

- [Node.js](https://docs.near.org/smart-contracts/quickstart?code-tabs=js)
- [A NEAR Wallet](https://testnet.mynearwallet.com/create)
- [NEAR-CLI](https://docs.near.org/tools/near-cli#installation)

---

## 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 | [Approvals](5-approval.md) | Expand the contract allowing other accounts to transfer NFTs on your behalf. |
| 8 | [Royalty](6-royalty.md) | Add NFT royalties allowing for a set percentage to be paid out to the token creator. |
| 9 | [Events](7-events.md) | in this tutorial you'll explore the events extension, allowing the contract to react on certain events. |
| 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!

:::info Questions?
👉 Join us on [Discord](https://near.chat/) and let us know in the `#development` channels. 👈

We also host daily [Office Hours](https://pages.near.org/developers/get-help/office-hours/) live where the DevRel team will answer any questions you may have. 🤔

Monday – Friday 11AM – 12PM Pacific (6PM – 7PM UTC)
:::
161 changes: 161 additions & 0 deletions website/docs/0-predeployed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
---
id: predeployed-contract
title: Pre-deployed Contract
sidebar_label: Pre-deployed Contract
description: "Learn how to mint NFTs on NEAR using a pre-deployed NFT smart contract without any coding."
---

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

> Learn how to easily create your own non-fungible tokens without doing any software development by using a readily-available NFT smart contract.


## Prerequisites

To complete this tutorial successfully, you'll need:

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

## Using the NFT contract

### Setup

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

<Tabs groupId="cli-tabs">

<TabItem value="short" label="Short">

```bash
near login --networkId testnet
```
</TabItem>

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

```bash
near account import-account using-web-wallet network-config testnet
```
</TabItem>
</Tabs>

- 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` (or `.near` for `mainnet`).

:::

- Test that the environment variable is set correctly by running:

```bash
echo $NEARID
```

### Minting your NFTs

NEAR has deployed an NFT contract to the account `nft.examples.testnet` which allows users to freely mint tokens. Using this pre-deployed contract, let's mint our first token!


- Run this command in your terminal, however you **must replace the `token_id` value with an UNIQUE string**.

<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}}' --accountId $NEARID --deposit 0.1
```
</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>

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

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

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

```bash
near view nft.examples.testnet nft_tokens_for_owner '{"account_id": "'$NEARID'"}'
```

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

```json
[
{
"token_id": "0",
"owner_id": "dev-xxxxxx-xxxxxxx",
"metadata": {
"title": "Some Art",
"description": "My NFT media",
"media": "https://upload.wikimedia.org/wikipedia/commons/thumb/0/00/Olympus_Mons_alt.jpg/1024px-Olympus_Mons_alt.jpg",
"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: `3.0.0`
- NFT standard: [NEP171](https://github.com/near/NEPs/tree/master/neps/nep-0171.md), version `1.0.0`

:::
Loading
Loading