利用Typescript在Aptos发行NFT
This tutorial walk you through the process of issuing NFT on Aptos step by step.
Source code
It's recommended to download the source code which gives you hands on experience.
https://github.com/zengxinhai/issue-NFT-on-Aptos
Prerequisites
You only need to know some Typescript to get started, make sure you have node installed.
Set up the project
Create an empty project and do some init:
mkdir sample-collection
cd sample-collection
npm initInstall necessary packages:
npm install aptos -S
npm install dotenv typescript ts-node -DSetup typescript params:
./node_modules/typescrit/bin/tsc --initMake sure to enable resolveJsonModule, and disable strictNullChecks
Prepare static files
Images
Make an asset folder to put the logo and pictures for the collection. Here, we have 1 logo image, and 2 token images in token-images subfolder.
Token meta data
Make an metadata folder to put the meta data for each token in the collection. Below is a sample for the token meta data.
name, description will be used by marketplace to show info on website.
attributes will be used by users to filter based on different traits.
image will be shown to user. We'll fill it after we upload the images to IPFS.
Now we have folder structure like this:

Host assets on IPFS
Here we use nft.storage to upload files to IPFS
NFTUp tool
Download at: https://nft.storage/docs/how-to/nftup/
Follow its steps to set up the account and on how to upload assets.
Upload the assets
Upload token-images folder, and then we can fill the image field for token meta data. Do it for all your token meta data. (change to your own ipfs urls)
After filling all the info for token meta data, upload metadata folder.
Finally, upload the logo picture.
Set the metadata, royalty, token config
Make a nft-config.json in the project root folder, we'll use these info for later use. Content below:
You can adjust the config according to your need. A few things to be clear:
takeRate: the percent of the royalty, 5 stands for 5%.
feeRecipient: the address that will collect the royalty fees
maxSupply: the maximum supply for this collection
Set up Aptos account
We need an Aptos account to interact with the blockchain. If you don't have an account, you can generate an account using the Petra wallet.
Fund your account with some $APT tokens, 1 $APT tokens should be enough. You can buy on Binance, FTX.
Mint NFT using typescript
Make a src folder in the project root to contain all the source code, also you need a .env file to store PRIV_KEY to prevent you from submitting it to a git repo.
account.ts
Create account.ts under the src folder. Content below:
Get the private key from .env file
Convert to Unit8Array
Initialize the account, and export for later use.
chain.ts
Create chain.ts under the src folder. Content below:
Here we get the tokenClient to interact with Aptos blockchain, and a helper function fundAccountForDev to get $APT for dev purpose. isMainnet flag is used turn on/off mainnet interaction.
issue_NFT.ts
Create issue_NFT.ts under the src folder. Content below:
The above code created a collection, and mint 1 token under the collection. A few things to konw:
You can only create 1 collection with the same name.
If you set CHAIN_NET=main, you'll need to fund your account with $APT to mint tokens
Issue the NFT
Add a command in package.json.
Run the command:
If nothing is wrong, then you've issued your NFT.
Congratulations, you've issued your collection!🎉
Now, you've issued your NFT collection on Aptos. If you do it on mainnet, you can go check how your NFT looks on: topaz.so
Below is the aptos birds on Aptos

Last updated