Skip to content
You are reading Palm development version documentation and some displayed features may not be available in the stable release. You can switch to stable version using the version box at screen bottom.

Updated on August 8, 2022

Deploy using Truffle

This guide walks you through using Truffle migrations to deploy an NFT smart contract to the Palm network.



  1. Initialize your npm project:

    npm init
  2. Install Truffle on your project folder:

    npm install --save truffle
  3. Initialize Truffle on your project folder:

    npx truffle init
  4. Install Truffle’s HDWalletProvider:

    npm install --save @truffle/hdwallet-provider
  5. Write your contract:

    We’ll use a contract based on the OpenZeppelin library’s ERC-721 implementation.

    First, install the Open Zeppelin library in order to inherit its classes:

    npm install --save @openzeppelin/contracts

    Next, add the following smart contract to the “contracts” folder and name it “NFT.sol”:

    //Contract based on [](
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;
    import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
    import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
    import "@openzeppelin/contracts/utils/Counters.sol";
    import "@openzeppelin/contracts/access/Ownable.sol";
    contract NFT is ERC721URIStorage, Ownable {
        using Counters for Counters.Counter;
        Counters.Counter private _tokenIds;
        constructor() ERC721("NFT", "NFT") {}
        function mintNFT(address recipient, string memory tokenURI)
            returns (uint256)
            uint256 newItemId = _tokenIds.current();
            _mint(recipient, newItemId);
            _setTokenURI(newItemId, tokenURI);
            return newItemId;
  6. Set environment variables with dotenv.

    Install dotenv:

    npm install --save dotenv

    Create a .env file in 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_PROJECT_ID = // Your infura project id

    Security warning

    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.

  7. Edit truffle-config.js with the following text:

    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: () => new HDWalletProvider({
            providerOrUrl: `${process.env.INFURA_PROJECT_ID}`,
            privateKeys: [
          network_id: 11297108099, // chain ID
          gasPrice: 1000 // gas price in gwei
        palm_mainnet: {
          provider: () => new HDWalletProvider({
            providerOrUrl: `${process.env.INFURA_PROJECT_ID}`,
            privateKeys: [
          network_id: 11297108109,
          gasPrice: 1000
  8. Deploy to the target Palm network environment:

    npx truffle migrate --network palm_testnet
    npx truffle migrate --network palm_mainnet
    Compiling your contracts...
    > Everything is up to date, there is nothing to compile.
    Starting migrations...
    > Network name:    'palm_testnet'
    > Network id:      11297108099
    > Block gas limit: 18800000 (0x11edd80)
      Deploying 'Migrations'
      Migrations: 0x588a268a8db4784679c93b99bf6f3ab1c6a4831c
      Saving successful migration to network
      Saving artifacts
  9. Look up your deployment on the Palm network block explorer

    Go to for testnet deployments and to for mainnet deployments and paste the address of your contract into the search bar.


Any question? Drop them on our Discord

Questions or feedback? You can discuss and obtain community support on Palm Discord.
For additional support, contact Palm on Palm website.