[blockchain | dnft | polygon] dynamic NFT development tutorial based on chainlink on polygon [including source code]

Blockchain Development Engineer 2022-05-14 03:57:00 阅读数:680

blockchaindnftpolygondynamicnft

Catalog

1、Polygon brief introduction

2、 Why dynamic NFT Very important ?

3、 Example : Dynamic weather NFT

4、 stay Etherscan Check out dNFT

5、 Conclusion


dynamic NFT (dNFT) yes NFT The next stage of development , It will NFT Verifiable uniqueness with dynamic data input and output Combined with off chain calculation . The Oracle is to introduce dynamic elements into NFT The basis of , Give them input , For example, it can be proved Fair 、 Tamper proof randomness and all kinds of data from the real world .

In this tutorial , We will learn how to base on Polygon Upper Chainlink The real-time weather data provided by the Oracle is constructed dNFT.

1、Polygon brief introduction

Polygon( Formerly known as Matic Network) It is an extension framework for building Ethereum compatible blockchain .Polygon It's not just about One or two extended solutions , It's about creating an ecosystem , Connect multiple different extension solutions , Including side chains with different consensus mechanisms And second tier options , Such as Plasma、Optimistic Rollups and ZK-Rollups.Polygon The framework also allows new projects to quickly and easily Build your own unique extension solution .Polygon With its Ethereum virtual machine (EVM) Compatibility 、 Optional shared security model and its advanced technology The flexibility of the , Distinguish yourself from other blockchain expansion and interoperability projects .

Popular is based on NFT The game project , Such as Aavegotchi and Polychain Monsters Has been used Polygon Scalable technology to start , Both are integrated Chainlink Verifiable random function (VRF), Create a more dynamic experience for users . However , Verifiable randomness is not Developers can use it in Polygon Build on dApp The only input for . By using Chainlink on Polygon The weather source provided , Developers can create dynamic NFT, these NFT It changes according to the offline data provided by the security oracle .

2、 Why dynamic NFT Very important ?

NFT It is often used to express the ownership of unique assets such as works of art , But they can also be used to represent dynamic assets , For example, the statistics of athletes in sports competitions data . Data can be used to create encrypted security 、 Decentralized and fraud proof transaction cards , And update in real time when the data changes —— for example , When you get New scores or record successful assists . This is NFT Collectors have created a new level , And based on NFT A new game has been unlocked in the game application Utilities .

Dynamic driven by Oracle NFT In the game dApp Aavegotchi Plays a key role in , It integrates Chainlink VRF To provide it with Provable sources of randomness .Chainlink VRF Helps to ensure that... Is fairly determined Aavegotchi dNFT The unique characteristics of , And for unpredictable Game scenes and random DAO Jurors choose to provide support .Aavegotchi stay Polygon Of the 2 layer PoS Push on the chain , With near zero Transaction costs and fast settlement time , Make the game expand cost effectively to meet the needs of users .

Chainlink By providing anti manipulation low-cost off chain services , In support of Polygon And other extended solutions . With the help of Chainlink, Developers can access weather data , for example , Building real-world data dNFT Express , For example, in some geographical locations Current temperature .

Like this, dNFT A use case for is to support blockchain based insurance . An insurance policy can be converted into dNFT, Allow on the basis of Chainlink Predicting machine Customize crop insurance policies with weather data from the outside world . Because they allow real-time coverage over a wide area and improve payment efficiency , therefore dNFT It is a powerful alternative to traditional forms of insurance , Traditional forms of insurance are often affected by manual processing delays and subjective assessments .

FarmerNet NFTs yes GeoDB Geolocation Oracle and Chainlink Virtual Hackathon Spring 2021 Government Technology Award The winner of , They use Chainlink Created a blockchain market for farmers , Earn income through carbon credit . Projects like this can make Buyers get immutable evidence , Prove that they passed dNFT Claim to reduce carbon and use renewable energy . It's just that the Oracle is creating the next generation NFT An example of the many benefits offered in the process .

3、 Example : Dynamic weather NFT

because Polygon And EVM compatible , So we can use it Solidity Tools in the environment , for example Truffle、Hardhat、MetaMask etc. . In this tutorial , We will use Truffle, This is a smart contract development framework , Allow us to use Polygon.

First , We need to set the environment variables , So we need one PRIVATE_KEY And a MATIC_RPC_URL environment variable . PRIVATE_KEY It's a mnemonic for a wallet , You can start your Infura Wait for the node provider to find MATIC_RPC_URL. You also need... In your wallet some Mumbai Test net Of MATIC Tokens, , It can be downloaded from Mumbai Faucet Get these tokens .

then , Set them to bash_profile File or export on the terminal :

1
2
export MNEMONIC='cat dog frog....'
export RINKEBY_RPC_URL='www.infura.io/asdfadsfafdadf'

Next, execute the following command to start using repo, This will be Polygon Dynamic deployment on the chain NFT:

1
2
3
4
5
6
7
8
9
yarn global add truffle
git clone https://github.com/kwsantiago/weather-nft
cd weather-nft
yarn
truffle migrate --network mumbai

We just deployed on the chain dNFT Based on the WeatherFeed.sol  In file getWeather() Function to update the weather data , This function gets the current temperature in Boston, Massachusetts .

1
2
3
4
5
6
7
function getWeather() public onlyOwner
returns (bytes32 requestId) {
Chainlink.Request memory req = buildChainlinkRequest(jobid, address(this), this.fulfill.selector);
req.add("city", "boston");
req.add("copyPath", "weather.0.main");
requestId = sendChainlinkRequestTo(oracle, req, fee);
}

Congratulations , You have deployed your first dNFT, And you can see its operation as the weather changes !

4、 stay Etherscan Check out dNFT

You can get it for free Etherscan API Key and connect with the chain dNFT Interact . then , Can be ETHERSCAN_API_KEY Set to environment variable .

We can verify this by doing the following :

1
2
3
4
5
yarn add truffle-plugin-verify
truffle run verify WeatherNFT --network mumbai --license MIT
truffle run verify WeatherFeed --network mumbai --license MIT

This will validate and publish your contract , You can go to Etherscan Of “ Read contract ” part .

otherwise , have access to  oneclickdapp  And add the contract address and ABI. Can be in  build/contracts  Found in folder ABI. please remember ,ABI Not the whole file , Just show “ABI” Part of .

5、 Conclusion

The source code of this tutorial can be downloaded from here https://github.com/kwsantiago/weather-nft download .

take Polygon And other fast and cost-effective platforms and powerful decentralized Oracle network (DON) When combined , establish dNFT It will be easy , Thus expanding the possibility of smart contracts .Polygon dApp Can also be Chainlink For a wide range of other use cases , For example, in Polygon Use random numbers to build a provably fair blockchain game , Or in Polygon Quote decentralized prices on Information to support the next revolutionary DeFi agreement .

版权声明:本文为[Blockchain Development Engineer]所创,转载请带上原文链接,感谢。 https://netfreeman.com/2022/134/202205140348123185.html