Your First NFT

This tutorial describes how to create and transfer NFTs on the Aptos blockchain. The Aptos implementation for core NFTs can be found in the token.movearrow-up-right Move module.

Step 1: Pick an SDKarrow-up-right

Install your preferred SDK from the below list:


Step 2: Run the examplearrow-up-right

Each SDK provides an examples directory. This tutorial covers the simple-nft example.

Clone the aptos-core repo:

git clone git@github.com:aptos-labs/aptos-core.git ~/aptos-core
  • Typescript

  • Python

  • Rust

Navigate to the Typescript SDK examples directory:

cd ~/aptos-core/ecosystem/typescript/sdk/examples/typescript

Install the necessary dependencies:

Run the Typescript simple_nftarrow-up-right example:


Step 3: Understand the outputarrow-up-right

The following output should appear after executing the simple-nft example, though some values will be different:

This example demonstrates:

  • Initializing the REST and faucet clients.

  • The creation of two accounts: Alice and Bob.

  • The funding and creation of Alice and Bob's accounts.

  • The creation of a collection and a token using Alice's account.

  • Alice offering a token and Bob claiming it.

  • Bob unilaterally sending the token to Alice via a multiagent transaction.


Step 4: The SDK in deptharrow-up-right

  • Typescript

  • Python

  • Rust

SEE THE FULL CODE

See simple_nftarrow-up-right for the complete code as you follow the below steps.


Step 4.1: Initializing the clientsarrow-up-right

In the first step the example initializes both the API and faucet clients.

  • The API client interacts with the REST API, and

  • The faucet client interacts with the devnet Faucet service for creating and funding accounts.

  • Typescript

  • Python

  • Rust

Using the API client we can create a TokenClient, which we use for common token operations such as creating collections and tokens, transferring them, claiming them, and so on.

common.ts initializes the URL values as such:

TIP

By default the URLs for both the services point to Aptos devnet services. However, they can be configured with the following environment variables:

  • APTOS_NODE_URL

  • APTOS_FAUCET_URL


Step 4.2: Creating local accountsarrow-up-right

The next step is to create two accounts locally. Accountsarrow-up-right represent both on and off-chain state. Off-chain state consists of an address and the public, private key pair used to authenticate ownership. This step demonstrates how to generate that off-chain state.

  • Typescript

  • Python

  • Rust


Step 4.3: Creating blockchain accountsarrow-up-right

In Aptos, each account must have an on-chain representation in order to support receive tokens and coins as well as interacting in other dApps. An account represents a medium for storing assets, hence it must be explicitly created. This example leverages the Faucet to create Alice and Bob's accounts:

  • Typescript

  • Python

  • Rust


Step 4.4: Creating a collectionarrow-up-right

Now begins the process of creating tokens. First, the creator must create a collection to store tokens. A collection can contain zero, one, or many distinct tokens within it. The collection does not restrict the attributes of the tokens, as it is only a container.

  • Typescript

  • Python

  • Rust

Your application will call createCollection:

The function signature of createCollection. It returns a transaction hash:


Step 4.5: Creating a tokenarrow-up-right

To create a token, the creator must specify an associated collection. A token must be associated with a collection and that collection must have remaining tokens that can be minted. There are many attributes associated with a token, but the helper API only exposes the minimal amount required to create static content.

  • Typescript

  • Python

  • Rust

Your application will call createToken:

The function signature of createToken. It returns a transaction hash:


Step 4.6: Reading token and collection metadataarrow-up-right

Both the collection and token metadata are stored on the creator's account within their Collections in a table. The SDKs provide convenience wrappers around querying these specific tables:

  • Typescript

  • Python

  • Rust

To read a collection's metadata:

To read a token's metadata:

Here's how getTokenData queries the token metadata:


Step 4.7: Reading a token balancearrow-up-right

Each token within Aptos is a distinct asset, the assets owned by the user are stored within their TokenStore. To get the balance:

  • Typescript

  • Python

  • Rust


Step 4.8: Offering and claiming a tokenarrow-up-right

Many users have received unwanted tokens that may cause minimally embarrassment to serious ramifications. Aptos gives the rights to each owner of an account to dictate whether or not to receive unilateral transfers. By default, unilateral transfers are unsupported. So Aptos provides a framework for offering and claiming tokens.

To offer a token:

  • Typescript

  • Python

  • Rust

To claim a token:

  • Typescript

  • Python

  • Rust


Step 4.9: Safe unilateral transferring of a tokenarrow-up-right

To support safe unilateral transfers of a token, the sender may first ask the recipient to acknowledge off-chain about a pending transfer. This comes in the form of a multiagent transaction request. Multiagent transactions contain multiple signatures, one for each on-chain account. Move then can leverage this to give signer level permissions to all that signed. For token transfers, this ensures that the receiving party does indeed desire to receive this token without requiring the use of the token transfer framework described above.

  • Typescript

  • Python

  • Rust


Step 4.10: Enabling unilateral token transfersarrow-up-right

Coming soon.

  • Python

  • Rust

  • Typescript

Coming soon.

Last updated