Pre-deployed Contract
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:
Using the NFT contractโ
Setupโ
- Log in to your newly created account with
near-cli
by running the following command in your terminal:
- Short
- Full
near login --networkId testnet
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:
export NEARID=YOUR_ACCOUNT_NAME
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:
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.
- Short
- Full
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
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
You can also replace the media
URL with a link to any image file hosted on your web server.
Example response:
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
''
- To view tokens owned by an account you can call the NFT contract with the following
near-cli
command:
near view nft.examples.testnet nft_tokens_for_owner '{"account_id": "'$NEARID'"}'
Example response:
[
{
"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": {}
}
]
Congratulations! You just minted your first NFT token on the NEAR blockchain! ๐
๐ Now try going to your NEAR Wallet 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 and learn more about the smart contract structure and how you can build your own NFT contract from the ground up.
Happy minting! ๐ช
At the time of this writing, this example works with the following versions:
- near-cli:
3.0.0
- NFT standard: NEP171, version
1.0.0