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.



  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: "" + process.env.TESTNET_PROJECT_ID,
                    privateKeys: [
                network_id: 11297108099, // chain ID
                gas: 3000000, // gas limit
                gasPrice: 10000000000 // gas price in gwei
            palm_mainnet: {
                provider: () => new HDWalletProvider({
                    providerOrUrl: "" + process.env.MAINNET_PROJECT_ID,
                    privateKeys: [
                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)
      Deploying 'Migrations'
      Migrations: 0x588a268a8db4784679c93b99bf6f3ab1c6a4831c
      Saving successful migration to network
      Saving artifacts
Questions or feedback? You can discuss and obtain community support on Palm Discord.
For additional support, contact Palm on Palm website.