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 July 20, 2021

Deploy using Truffle

This guide walks you through using Truffle migrations to deploy a dapp to the Palm network.

Prerequisites

Steps

  1. Initialize Truffle on your project folder:

    truffle init
    
  2. Install Truffle’s HDWalletProvider:

    npm install @truffle/hdwallet-provider
    
  3. 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:

    // if deploying to Palm Testnet
    TESTNET_PRIVATE_KEY = // (string) private key of the account you intend to use on Palm Testnet (this can be accessed on MetaMask)
    TESTNET_PROJECT_ID = // (string) project ID corresponding to your Palm Testnet Infura project
    
    // if deploying to Palm Mainnet
    MAINNET_PRIVATE_KEY = // (string) private key of the account you intend to use on Palm Mainnet (this can be accessed on MetaMask)
    MAINNET_PROJECT_ID = // (string) project ID corresponding to your Palm Mainnet Infura project
    

    Security warning

    Keep your private keys secret.

    Private keys must be kept secret and not committed to any code respositories. Improper handling of private keys can lead to loss of funds and identity fraud.

    For example, see MyCrypto’s Protecting Yourself and Your Funds guide.

  4. 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 = {
        networks: {
            palm_testnet: {
                provider: () => new HDWalletProvider({
                    providerOrUrl: "https://palm-testnet.infura.io/v3/" + process.env.TESTNET_PROJECT_ID,
                    privateKeys: [
                        process.env.TESTNET_PRIVATE_KEY
                    ]
                }),
                network_id: 11297108099, // chain ID
                gas: 3000000, // gas limit
                gasPrice: 10000000000 // gas price in gwei
            },
            palm_mainnet: {
                provider: () => new HDWalletProvider({
                    providerOrUrl: "https://palm-mainnet.infura.io/v3/" + process.env.MAINNET_PROJECT_ID,
                    privateKeys: [
                        process.env.MAINNET_PRIVATE_KEY
                    ]
                }),
                network_id: 11297108109,
                gas: 3000000,
                gasPrice: 10000000000
            }
        }
    }
    
  5. Deploy to the target Palm network environment:

    truffle migrate --network palm_testnet
    
    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)
    
    1_initial_migration.js
    ======================
    
      Deploying 'Migrations'
      ----------------------
      ...
      0xa5f964329db84e4afed621a520c37c1aa376596912e509722eedba49a2378cc2
    
      Migrations: 0x588a268a8db4784679c93b99bf6f3ab1c6a4831c
    
      Saving successful migration to network
      --------------------------------------
      ...
      0x6291aff7d5e14f24e8ee1047f10c84dc2ccd8eb17e8c60a52f2239164a8506c2
    
      Saving artifacts
      ----------------
      ...
    
Questions or feedback? You can discuss and obtain community support on Palm Discord.
For additional support, contact Palm on Palm website.