a) First, install the Open Zeppelin library in order to inherit its classes:
Shell
|
npminstall --save @openzeppelin/contracts
b) Next, create a file named NFT.sol under the contracts folder.
c) Lastly, add the following smart contract to NFT.sol file. Note that we have named our contract NFT, this can be any name.
The name will be important in the next step.
JS
|
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;import"@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract NFT is ERC721{constructor()ERC721("MyERC721","M721"){}}
6. Create Your Migration File
What are Migrations?
Migrations are JavaScript files that help you deploy contracts to the Ethereum network. These files are responsible for staging your deployment tasks, and they're written under the assumption that your deployment needs will change over time.`
Under the migrations folder, create your filename: 1_example_migration.js
// At the beginning of the migration, we tell Truffle// which contracts we'd like to interact with via the artifacts.require() method.var MyContract = artifacts.require("NFT");//The deployer object is your main interface for staging deployment tasks,// and its API is described at the bottom of this page.
module.exports=function(deployer){// deployment steps
deployer.deploy(MyContract);};
Keep Your Private Keys Secret
Private keys must be kept secret and not committed to any code repository. In the example of this tutorial, the .env file should be added to your .gitignore file and kept local.
For example, see MyCrypto's Protecting Yourself and Your Funds guide.
Create an .env file n your project's root folder, and set environment variables in the file as follows
PRIVATE_KEY = #The private key of the account you intend to use on the Palm network
INFURA_API_KEY = #Your Infura API key
.env file
8. Edit truffle-config.js with the following text
JS
|
const HDWalletProvider =require("@truffle/hdwallet-provider");require('dotenv').config()// store environment variables from '.env' to process.env
module.exports ={compilers:{solc:{version:"^0.8.0"}},networks:{palm_testnet:{provider:()=>newHDWalletProvider({providerOrUrl:`https://palm-testnet.infura.io/v3/${process.env.INFURA_API_KEY}`,privateKeys:[
process.env.PRIVATE_KEY]}),network_id:11297108099,// chain IDgasPrice:1000// gas price in gwei},palm_mainnet:{provider:()=>newHDWalletProvider({providerOrUrl:`https://palm-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`,privateKeys:[
process.env.PRIVATE_KEY]}),network_id:11297108109,gasPrice:1000}}}
9. Deploy to the Target Palm Network Environment
Palm Testnet
Palm Mainnet
Example Logs
|
npx truffle migrate --network palm_testnet
10. Look Up Your Deployment on the Palm Network Block Explorer
Paste your `contract address:` from the log of the previous step into the search bar. It may take 10-20 minutes to appear.
If successful, you will see something like this screenshot:
11. Install Truffle-Plugin-Verify
This plugin will allow you to automatically verify your smart contracts's source code straight from the CLI.
Shell
|
npminstall -D truffle-plugin-verify
12. Add the plugin to your truffle-config.js file
JS
|
const HDWalletProvider =require("@truffle/hdwallet-provider");require('dotenv').config()// store environment variables from '.env' to process.env
module.exports ={plugins:['truffle-plugin-verify'],//<== added linecompilers:{solc:{version:"^0.8.0"}},networks:{palm_testnet:{provider:()=>newHDWalletProvider({providerOrUrl:`https://palm-testnet.infura.io/v3/${process.env.INFURA_API_KEY}`,privateKeys:[
process.env.PRIVATE_KEY]}),network_id:11297108099,// chain IDgasPrice:1000,// gas price in gwei},palm_mainnet:{provider:()=>newHDWalletProvider({providerOrUrl:`https://palm-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`,privateKeys:[
process.env.PRIVATE_KEY]}),network_id:11297108109,gasPrice:1000,}}}
13. Verify Contract
Use the name of your contract to verify on the desired network.