Everything you need to know about creating NFTs on Velas
Creating NFTs on Velas can give teams various benefits. These include leveraging smart contracts that are Ethereum compatible, enjoying lightening fast transaction speed, being free from high gas fees, and more.
مواد:
تعارف
NFT is a revolutionary technology that can benefit users in various ways. For example, it grants users proof of ownership over their digital assets like never before. Moreover, NFTs can lead to an entirely new creator economy.
With all the perks NFTs bring, everyone is talking about empowering their projects with NFTs. But do you know how to develop NFT-supported smart contracts? Don’t worry if not, because this article will walk you through all the steps of creating NFT smart contracts on Velas Testnet.
Please be aware that this tutorial will show you how to create a one-of-one NFT instead of a collection. So this smart contract will enable users to mint any of their photos or videos as an NFT.
کیوں؟
There are many blockchain protocols available out there. But developers still face issues when using them. For example, Ethereum struggles with high gas fees and slow transaction processing, while other blockchains require developers to use unfamiliar languages like Rust.
ساتھ موم بتیاں۔, most of those concerns don’t exist. Velas’s solution inherits the best DNA of Solana’s technology and complements it with additional features to support compatibility with EVM. This gives users and developers an ideal platform that guarantees an excellent user experience with faster transaction time. Moreover, it simplifies the development process with Solidity support.
شرائط
To follow along, you should have Node plus Yarn, the package manager. Also, you should have basic knowledge of Solidity. So if you are not familiar with it, please equip yourself with the basics of Solidity and Hardhat first.
سیٹ اپ
To set up our project, execute the following command in the terminal.
npx hardhat
You will see the following output if you don’t have Hardhat installed.
قسم y اور پر کلک کریں داخل, and it will proceed to install the Hardhat. However, if you have Hardhat already, it won’t show you the prompt for Hardhat installation. Instead, it will ask some questions about how you want to set up the project.
We want a basic Javascript project in our current folder so just click داخل ہر چیز کے لئے.
Then we have to install our dependencies for the project. To install those, we will use the following command.
npm install --save-dev "^2.10.1" "@nomicfoundation/^1.0.1" "@openzeppelin/contracts" "dotenv"
As we are using Yarn, we have to install libraries that hardhat-toolbox uses.
yarn add --dev @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan chai ethers hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v5 @ethersproject/abi @ethersproject/providers
If you’re using npm version 7 or later versions, these libraries will be installed directly.
It is worth noting that we need to take one more step before writing a smart contract. That is to remove any .sol files you see in the contracts folder and create a new file called VELASNFT.sol. This is the folder where we will write our contract.
How to write an NFT smart contract
ڈویلپر
To start with, we will create a barebone smart contract where we define the solidity version and create an empty smart contract body.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9; contract VELASNFT { }
We have to import a base smart contract and a utility smart contract. Notably, these are the contracts that will use to build our NFT smart contract. The base contract is ERC721URIStorage, an ERC721 implementation with storage-based token URI management.
Counters is a utility contract that will be used to count the number of NFTs minted.
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
Our contract will inherit the base contract. This will allow users to access all the functions of the base contract and our smart contracts.
contract VELASNFT is ERC721URIStorage { }
Now we can write constructor for our contract. Notably, our constructor won’t have any arguments, but you have to pass the name and symbol to the ERC721 constructor.
constructor() ERC721("VELASNFT", "VN") {}
At the end of this step, your smart contract should look like this.
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol"; contract VELASNFT is ERC721URIStorage { constructor() ERC721("VELASNFT", "VN") {} }
Writing the mint function
For the mint function, we need to set up the counter first. Paste the following snippet inside the contract above constructor.
using Counters for Counters.Counter; Counters.Counter private _tokenIds;
we assign all the functions of the Counters library to the Counter struct. Then we will create a private variable called _tokenIds.
Now let’s start to develop the function. It will take one argument: tokenURI,and it will be the url to the json file which stores all the metadata. We will get more into metadata in the following sections. The mint function will have public visibility and will return the ID of the minted NFT, which will be type uint256.
function mint(string memory tokenURI) public returns (uint256) { }
Inside the function, we will first get the current count of the counter.
To mint an NFT, we will use _mint function which takes address and ID as arguments. For address, we will use the address of the caller, and ID will be the current count. After that, we have to save the tokenURI.
To do that, we have to _setTokenURI, which will save URI with the corresponding ID as a key. In the end, we will increment the counter, and then the ID of the created NFT.
function mint(string memory tokenURI) public returns (uint256) { uint256 newItemId = _tokenIds.current(); _mint(minter, newItemId); _setTokenURI(newItemId, tokenURI); _tokenIds.increment(); return newItemId; }
Congratulations! Now your smart contract can mint NFTs! Here is the overview of the whole contract.
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.9; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol"; contract VELASNFT is ERC721URIStorage { using Counters for Counters.Counter; Counters.Counter private _tokenIds; constructor() ERC721("VELASNFT", "VN") {} function mint(string memory tokenURI) public returns (uint256) { uint256 newItemId = _tokenIds.current(); _mint(msg.sender, newItemId); _setTokenURI(newItemId, tokenURI); _tokenIds.increment(); return newItemId; }
}
How to deploy the contract
We have built our NFT smart contract. Here comes the exciting step, deployment. But before deploying the contract, we need to compile it and write a script that deploys the contract. To compile the contract, run the following command in terminal.
npx hardhat compile
You will see the following output.
Now let’s move on to the next stage, writing a script for deploying this smart contract. To do so, we will go to the scripts folder and open the deploy.js file. Then, remove all the content and paste the following snippet into that file.
const hre = require("hardhat"); async function main () { // We get the contract to deploy const VELASNFT = await hre.ethers.getContractFactory('VELASNFT'); console.log("Deploying NFT contract..."); const velasnft = await VELASNFT.deploy(); await velasnft.deployed(); console.log('NFT contract deployed to:', velasnft.address); } main() .then(() => process.exit(0)) .catch(error => { console.error(error); process.exit(1);
});
Before deploying the contract, we have to add details about Velas testnet to hardhat.config.js file. Open the file and add Velas testnet configuration.
require("@nomicfoundation/hardhat-toolbox");
const dotenv = require('dotenv');
dotenv.config(); /** @type import('hardhat/config').HardhatUserConfig */
module.exports = { solidity: "0.8.9", networks: { velastestnet: { url: `https://evmexplorer.testnet.velas.com/rpc`, accounts: [process.env.PRIVATE_KEY] } }
};
It is also worth mentioning that before deploying the contract, you have to add private keys for your wallet to the .env file and have some testnet VLX token in the wallet. You can get testnet tokens from یہاں.
Now that we have all things set up, run the following command in the terminal.
npx hardhat run scripts/deploy.js --network velastestnet
If the command is executed successfully, you will see the output similar as shown below in your terminal.
NFT کو ٹکسال کریں۔
As the smart contract is deployed, we can mint the NFT from the terminal. To do that, first start the hardhat console using the following command.
npx hardhat console --network velastestnet
The output are shown below.
Then we will create the contract variable called “velasnft”. getContractAt method will return the contract object.
const velasnft = await ethers.getContractAt("VELASNFT", '0x587133187DEC8E1D5a964254B42FF3627a649313')
Please refer to the output shown below.
To mint the NFT, we will use the mint method of the velasnft variable. We also have to pass the link for metadata to the method. You can read more about Metadata standards HERE.
await velasnft.mint("https://metadatastorage.com/velasnft/0")
Check out the output below.
Now it’s time to check the owner of the NFT. Since we minted using the مالک کا method, now let’s pass the index of the NFT we minted.
await velasnft.ownerOf(0)
That’s how we get the result of the NFT owner.
نتیجہ
In the article, we have learned how to write an NFT smart contract that allows users to mint NFTs. In addition, we have managed to deploy it on Velas testnet. Now, you can develop new NFT-powered applications and explore the dynamic Velas ecosystem.
You can also check out how to build a DAO on Velas via this link.
Velas wants to empower those who strive to speed up the development of Web3. Therefore, Velas has launched a $100 million grant program to accomplish this mission. Meanwhile, this program also aims to support the expansion of the Velas ecosystem.
With Velas’ grant program, developers can bring their exciting ideas to life more efficiently. Each project has the opportunity to receive up to $100,000 in funding. In addition, selected teams will have access to other resources to foster the development of their projects, including marketing, technical consultants, and more.
The grant program covers a wide range of categories, including but not limited to DeFi, NFT, blockchain-powered games, and more.
If you are interested in accelerating the mass adoption of cryptocurrencies and blockchain, apply now to join Velas’ ever-evolving ecosystem.
Find more about Velas:
اعلانِ لاتعلقی - یہ ایک سپانسر شدہ مضمون ہے۔ DappRadar اس صفحہ پر کسی بھی مواد یا پروڈکٹ کی توثیق نہیں کرتا ہے۔ DappRadar کا مقصد درست معلومات فراہم کرنا ہے، لیکن قارئین کو کارروائی کرنے سے پہلے ہمیشہ اپنی تحقیق کرنی چاہیے۔ DappRadar کے مضامین کو سرمایہ کاری کا مشورہ نہیں سمجھا جا سکتا۔
- SEO سے چلنے والا مواد اور PR کی تقسیم۔ آج ہی بڑھا دیں۔
- پلیٹو بلاک چین۔ Web3 Metaverse Intelligence. علم میں اضافہ۔ یہاں تک رسائی حاصل کریں۔
- ماخذ: https://dappradar.com/blog/how-to-create-nft-on-velas
- 100 ڈالر ڈالر
- 000
- 1
- 10
- 7
- 9
- a
- ہمارے بارے میں
- اوپر
- تیز
- تک رسائی حاصل
- اکاؤنٹس
- درست
- عمل
- اس کے علاوہ
- ایڈیشنل
- پتہ
- منہ بولابیٹا بنانے
- مشورہ
- کے بعد
- مقصد ہے
- تمام
- کی اجازت دیتا ہے
- پہلے ہی
- ہمیشہ
- اور
- ایپلی کیشنز
- دلیل
- دلائل
- مضمون
- مضامین
- اثاثے
- دستیاب
- انتظار کرو
- بیس
- بنیادی
- مبادیات
- کیونکہ
- اس سے پہلے
- کیا جا رہا ہے
- نیچے
- فائدہ
- فوائد
- BEST
- blockchain
- بلاکچین سے چلنے والا
- بلاکس
- جسم
- لانے
- تعمیر
- تعمیر
- کہا جاتا ہے
- کالر
- حاصل کر سکتے ہیں
- اقسام
- چیک کریں
- مجموعہ
- مطابقت
- ہم آہنگ
- اندراج
- اختتام
- ترتیب
- سمجھا
- کنسول
- کنسلٹنٹس
- مواد
- کنٹریکٹ
- معاہدے
- اسی کے مطابق
- مقابلہ
- کاؤنٹر
- کا احاطہ کرتا ہے
- تخلیق
- بنائی
- تخلیق
- خالق
- خالق معیشت
- کرپٹو کرنسیوں کی تجارت کرنا اب بھی ممکن ہے
- موجودہ
- ڈی اے او
- DappRadar
- اعداد و شمار
- ڈی ایف
- تعیناتی
- تعینات
- تعینات
- تعیناتی
- تعینات کرتا ہے
- تفصیلات
- ترقی
- ڈویلپرز
- ترقی
- ڈیجیٹل
- ڈیجیٹل اثاثے۔
- براہ راست
- ڈی این اے
- نہیں
- متحرک
- ہر ایک
- معیشت کو
- ماحول
- مؤثر طریقے سے
- بااختیار
- بااختیار بنانے
- کو چالو کرنے کے
- یقین ہے
- مکمل
- ERC721
- خرابی
- ethereum
- سب
- سب کچھ
- مثال کے طور پر
- بہترین
- دلچسپ
- عملدرآمد
- توسیع
- تجربہ
- تلاش
- برآمدات
- چہرہ
- فیس بک
- واقف
- فاسٹ
- تیز تر
- خصوصیات
- فیس
- فائل
- فائلوں
- پہلا
- پر عمل کریں
- کے بعد
- رضاعی
- مفت
- سے
- تقریب
- افعال
- فنڈنگ
- کھیل
- گیس
- گیس کی فیس
- حاصل
- دے دو
- فراہم کرتا ہے
- Go
- عطا
- گرانٹ
- ضمانت دیتا ہے
- یہاں
- ہائی
- کس طرح
- کیسے
- تاہم
- HTTPS
- مثالی
- خیالات
- نفاذ
- درآمد
- in
- شامل
- سمیت
- انڈکس
- معلومات
- انسٹال
- کے بجائے
- دلچسپی
- تعارف
- سرمایہ کاری
- مسائل
- IT
- جاوا سکرپٹ
- میں شامل
- JSON
- کلیدی
- چابیاں
- جان
- علم
- زبانیں
- شروع
- قیادت
- سیکھا ہے
- لیورنگنگ
- لائبریریوں
- لائبریری
- زندگی
- لمیٹڈ
- LINK
- لنکڈ
- دیکھو
- کی طرح دیکھو
- مین
- میں کامیاب
- انتظام
- مینیجر
- بہت سے
- مارکیٹنگ
- ماس
- بڑے پیمانے پر اپنانے
- زیادہ سے زیادہ چوڑائی
- دریں اثناء
- درمیانہ
- یاد داشت
- میٹا ڈیٹا
- طریقہ
- دس لاکھ
- ٹکسال
- ٹکسال
- مشن
- ایم ائی ٹی
- ماڈیول
- زیادہ
- سب سے زیادہ
- منتقل
- نام
- ضرورت ہے
- نیٹ ورک
- نئی
- اگلے
- Nft
- NFT سمارٹ معاہدے
- این ایف ٹیز
- نوڈ
- خاص طور پر
- تعداد
- اعتراض
- ایک
- کھول
- کھلا سمندر
- مواقع
- دیگر
- مجموعی جائزہ
- خود
- مالک
- ملکیت
- پیکج
- مراعات
- پلیٹ فارم
- پلاٹا
- افلاطون ڈیٹا انٹیلی جنس
- پلیٹو ڈیٹا
- مہربانی کرکے
- علاوہ
- ضروریات
- پریزنٹیشن
- نجی
- نجی چابیاں
- عمل
- پروسیسنگ
- مصنوعات
- پروگرام
- منصوبے
- منصوبوں
- ثبوت
- محفوظ
- پروٹوکول
- فراہم
- عوامی
- سوالات
- رینج
- پڑھیں
- قارئین
- وصول
- ہٹا
- کی ضرورت
- تحقیق
- وسائل
- نتیجہ
- واپسی
- واپسی
- انقلابی
- رن
- مورچا
- محفوظ کریں
- سکرپٹ
- سیکشنز
- منتخب
- مقرر
- سیٹ اپ
- ہونا چاہئے
- دکھائیں
- دکھایا گیا
- اسی طرح
- بعد
- سست
- ہوشیار
- سمارٹ معاہدہ
- سمارٹ معاہدہ
- So
- سورج
- استحکام
- حل
- کچھ
- تیزی
- کی طرف سے سپانسر
- اسٹیج
- معیار
- شروع کریں
- مرحلہ
- مراحل
- ابھی تک
- پردہ
- کوشش کریں
- جدوجہد
- کامیابی کے ساتھ
- حمایت
- علامت
- لے لو
- لیتا ہے
- لینے
- بات کر
- ٹیموں
- ٹیکنیکل
- ٹیکنالوجی
- ٹرمنل
- testnet
- ۔
- مبادیات
- ان
- وہاں.
- لہذا
- چیزیں
- کے ذریعے
- وقت
- کرنے کے لئے
- ٹوکن
- ٹوکن
- ٹرانزیکشن
- لین دین کی رفتار
- سچ
- سبق
- ناجائز
- URL
- استعمال کی شرائط
- رکن کا
- صارف کا تجربہ
- صارفین
- کی افادیت
- مختلف
- موم بتیاں۔
- ورژن
- کی طرف سے
- ویڈیوز
- کی نمائش
- W3
- بٹوے
- طریقوں
- Web3
- ویبپی
- جس
- جبکہ
- ڈبلیو
- وسیع
- وسیع رینج
- گے
- قابل
- لکھنا
- تحریری طور پر
- تم
- اور
- اپنے آپ کو
- زیفیرنیٹ