|
| 1 | +--- |
| 2 | +id: predeployed-contract |
| 3 | +title: Pre-deployed Contract |
| 4 | +sidebar_label: Pre-deployed Contract |
| 5 | +description: "Mint your first NFT using a pre-deployed contract before building your own NFT smart contract." |
| 6 | +--- |
| 7 | + |
| 8 | +import Tabs from '@theme/Tabs'; |
| 9 | +import TabItem from '@theme/TabItem'; |
| 10 | + |
| 11 | +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. |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +To complete this tutorial successfully, you'll need [a NEAR Wallet](https://testnet.mynearwallet.com/create) and [NEAR CLI](/tools/near-cli#installation) |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Using the NFT contract |
| 22 | + |
| 23 | +Minting an NFT token on NEAR is a simple process that involves calling a smart contract function. |
| 24 | + |
| 25 | +To interact with the contract you will need to first login to your NEAR account through `near-cli`. |
| 26 | + |
| 27 | +<hr class="subsection" /> |
| 28 | + |
| 29 | +### Setup |
| 30 | + |
| 31 | +Log in to your newly created account with `near-cli` by running the following command in your terminal: |
| 32 | + |
| 33 | +```bash |
| 34 | +near account import-account using-web-wallet network-config testnet |
| 35 | +``` |
| 36 | + |
| 37 | +Set an environment variable for your account ID to make it easy to copy and paste commands from this tutorial: |
| 38 | + |
| 39 | +```bash |
| 40 | +export NEARID=YOUR_ACCOUNT_NAME |
| 41 | +``` |
| 42 | + |
| 43 | +<hr class="subsection" /> |
| 44 | + |
| 45 | +### Minting your NFTs |
| 46 | + |
| 47 | +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. |
| 48 | + |
| 49 | +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. |
| 50 | + |
| 51 | +<Tabs groupId="cli-tabs"> |
| 52 | + <TabItem value="short" label="Short"> |
| 53 | + |
| 54 | + ```bash |
| 55 | + 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 |
| 56 | + ``` |
| 57 | + </TabItem> |
| 58 | + |
| 59 | + <TabItem value="full" label="Full"> |
| 60 | + |
| 61 | + ```bash |
| 62 | + 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 |
| 63 | + ``` |
| 64 | + </TabItem> |
| 65 | +</Tabs> |
| 66 | + |
| 67 | +<details> |
| 68 | +<summary>Example response: </summary> |
| 69 | +<p> |
| 70 | + |
| 71 | +```json |
| 72 | +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"]}]} |
| 73 | +Transaction Id 8RFWrQvAsm2grEsd1UTASKpfvHKrjtBdEyXu7WqGBPUr |
| 74 | +To see the transaction in the transaction explorer, please open this url in your browser |
| 75 | +https://testnet.nearblocks.io/txns/8RFWrQvAsm2grEsd1UTASKpfvHKrjtBdEyXu7WqGBPUr |
| 76 | +'' |
| 77 | +``` |
| 78 | + |
| 79 | +</p> |
| 80 | +</details> |
| 81 | + |
| 82 | +:::tip |
| 83 | +You can also replace the `media` URL with a link to any image file hosted on your web server. |
| 84 | +::: |
| 85 | + |
| 86 | +<hr class="subsection" /> |
| 87 | + |
| 88 | +### Querying your NFT |
| 89 | + |
| 90 | +To view tokens owned by an account you can call the NFT contract with the following `near-cli` command: |
| 91 | + |
| 92 | +<Tabs groupId="cli-tabs"> |
| 93 | + <TabItem value="short" label="Short"> |
| 94 | + |
| 95 | + ```bash |
| 96 | + near view nft.examples.testnet nft_tokens_for_owner '{"account_id": "'$NEARID'"}' --networkId testnet |
| 97 | + ``` |
| 98 | + </TabItem> |
| 99 | + |
| 100 | + <TabItem value="full" label="Full"> |
| 101 | + |
| 102 | + ```bash |
| 103 | + near contract call-function as-read-only nft.examples.testnet nft_tokens_for_owner json-args '{"account_id": "'$NEARID'"}' network-config testnet now |
| 104 | + ``` |
| 105 | + </TabItem> |
| 106 | +</Tabs> |
| 107 | + |
| 108 | +<details> |
| 109 | +<summary>Example response: </summary> |
| 110 | +<p> |
| 111 | + |
| 112 | +```json |
| 113 | +[ |
| 114 | + { |
| 115 | + "token_id": "Goi0CZ", |
| 116 | + "owner_id": "bob.testnet", |
| 117 | + "metadata": { |
| 118 | + "title": "GO TEAM", |
| 119 | + "description": "The Team Goes", |
| 120 | + "media": "https://bafybeidl4hjbpdr6u6xvlrizwxbrfcyqurzvcnn5xoilmcqbxfbdwrmp5m.ipfs.dweb.link/", |
| 121 | + "media_hash": null, |
| 122 | + "copies": 1, |
| 123 | + "issued_at": null, |
| 124 | + "expires_at": null, |
| 125 | + "starts_at": null, |
| 126 | + "updated_at": null, |
| 127 | + "extra": null, |
| 128 | + "reference": null, |
| 129 | + "reference_hash": null |
| 130 | + }, |
| 131 | + "approved_account_ids": {} |
| 132 | + } |
| 133 | +] |
| 134 | +``` |
| 135 | + |
| 136 | +</p> |
| 137 | +</details> |
| 138 | + |
| 139 | +**Congratulations!** You just minted your first NFT token on the NEAR blockchain! 🎉 |
| 140 | + |
| 141 | +Now try going to your [NEAR Wallet](https://testnet.mynearwallet.com) and view your NFT in the "Collectibles" tab. |
| 142 | + |
| 143 | +--- |
| 144 | + |
| 145 | +## Final remarks |
| 146 | + |
| 147 | +This basic example illustrates all the required steps to call an NFT smart contract on NEAR and start minting your own non-fungible tokens. |
| 148 | + |
| 149 | +Now that you're familiar with the process, you can jump to [Contract Architecture](/tutorials/nfts/skeleton) and learn more about the smart contract structure and how you can build your own NFT contract from the ground up. |
| 150 | + |
| 151 | +***Happy minting!*** 🪙 |
| 152 | + |
| 153 | +:::note Versioning for this article |
| 154 | + |
| 155 | +At the time of this writing, this example works with the following versions: |
| 156 | + |
| 157 | +- near-cli-rs: `0.17.0` |
| 158 | +- NFT standard: [NEP171](https://github.com/near/NEPs/tree/master/neps/nep-0171.md), version `1.0.0` |
| 159 | + |
| 160 | +::: |
0 commit comments