Skip to content

Configuration

Location

Your configuration file is located at the root of your project directory. It can be named either tronbox.js or tronbox-config.js; when both are present, tronbox.js takes precedence. It is a JavaScript file that can execute any code necessary to create your configuration. It must export an object that represents the project configuration, as shown below:

JavaScript
javascript
module.exports = {
  networks: {
    development: {
      // For tronbox/tre docker image
      // See https://hub.docker.com/r/tronbox/tre
      privateKey: process.env.PRIVATE_KEY_DEV,
      userFeePercentage: 0, // The percentage of resource consumption ratio.
      feeLimit: 1000 * 1e6, // The TRX consumption limit for the deployment and trigger, unit is SUN
      fullHost: 'http://127.0.0.1:9090',
      network_id: '*'
    }
  },
  compilers: {
    solc: {
      version: '0.8.6',
      // An object with the same schema as the settings entry in the Input JSON.
      // See https://docs.soliditylang.org/en/latest/using-the-compiler.html#input-description
      settings: {
        optimizer: {
          enabled: true,
          runs: 200
        },
        evmVersion: 'istanbul',
        viaIR: true
      }
    }
  }
};

Network configuration is included by default, which runs on 127.0.0.1:9090. Other configuration options are explained below.

Resolve naming conflicts on Windows

When using the Command Prompt on Windows, the default configuration file name can cause a conflict with the tronbox executable, and so you may not be able to run Tronbox commands properly on existing projects.

This is because of the way command precedence works on the Command Prompt. The tronbox.cmd executable is on the path as part of the npm package, while the tronbox.js configuration file is located in the actual directory where the tronbox command runs. As .js is an acceptable executable extension by default, tronbox.js takes precedence over tronbox.cmd, leading to unexpected results.

This issue can be solved by any of the following solutions:

  • Call the executable file explicitly using the .cmd extension (tronbox.cmd compile).
  • Edit the system PATHEXT environment variable and remove .JS; from the list of executable extensions.
  • Rename tronbox.js to something else (tronbox-config.js).
  • Use Windows PowerShell or Git BASH, or shells that do not cause conflicts.

General configuration options

networks

Specify the networks for deployment and the specific transaction parameters (e.g., feeLimit, account address, etc.) that will be used when interacting with each network. Contract artifacts will be saved and recorded for later use when compilation and deployment take place on a specified network.When the contract abstractions detect that we are connected to a specified network, they will use the contract artifacts associated with the aforementioned network to simplify application deployment.

As shown below, the networks object is keyed by network names, and each name contains an object that defines the parameters of the corresponding network. You can provide your own network name and configuration to tell TronBox what network to connect to for deployment and testing.

Once you have defined your network, you can provide the name as an option for some commands; this is possible during testing or running migrations. You may specify a network name as follows during the migration:

Terminal
shell
tronbox migrate --network nile

For example:

JavaScript
javascript
module.exports = {
  networks: {
    shasta: {
      // Obtain test coin at https://shasta.tronex.io/
      privateKey: process.env.PRIVATE_KEY_SHASTA,
      userFeePercentage: 50,
      feeLimit: 1000 * 1e6,
      fullHost: 'https://api.shasta.trongrid.io',
      network_id: '2'
    },
    nile: {
      // Obtain test coin at https://nileex.io/join/getJoinPage
      privateKey: process.env.PRIVATE_KEY_NILE,
      userFeePercentage: 100,
      feeLimit: 1000 * 1e6,
      fullHost: 'https://nile.trongrid.io',
      network_id: '3'
    }
  }
};

If transaction options are not specified, the following values will be used for parameters by default, regardless of the network:

  • feeLimit: feeLimit refers to the upper limit of the Energy cost for deploying or calling a smart contract. Default value is 1000000000 (1,000 TRX).
  • userFeePercentage: userFeePercentage refers to the ratio of Energy consumed by the user to Energy consumed by the developer for smart contract execution. Default value is 100.
  • originEnergyLimit: originEnergyLimit refers to the maximum amount of Energy consumed by the creator in creating or executing a contract. Default value is 10000000 (10,000,000 ENERGY).
  • callValue: callValue refers to the value of TRX sent to the contract address when deploying a contract. Default value is 0.
  • tokenId: tokenId refers to the ID of the TRC10 token sent to a contract address for contract deployment. It has no default value and is not sent unless you set it.
  • tokenValue: tokenValue refers to the amount of the TRC10 token sent to a contract address for contract deployment. It has no default value and is not sent unless you set it.

Using mnemonics

If you prefer to use a mnemonic instead of a private key, you can do so in the configuration of networks, for example:

JavaScript
javascript
module.exports = {
  networks: {
    shasta: {
      // Obtain test coin at https://shasta.tronex.io/
      mnemonic: process.env.MNEMONIC,
      path: "m/44'/195'/0'/0/0",
      userFeePercentage: 50,
      feeLimit: 1000 * 1e6,
      fullHost: 'https://api.shasta.trongrid.io',
      network_id: '2'
    }
  }
};

Then, add the MNEMONIC configuration to your .env file, e.g:

Terminal
shell
export MNEMONIC="... MNEMONIC_HERE ..."

TIP

NOTE: Mnemonic support requires Tronbox v3.0.2 or later.

Project directories

Every directory below must resolve to a location inside the project directory; a path pointing outside the project root makes TronBox abort with config.<key> is outside the project directory.

Absolute paths work only when they resolve inside the project, and aren't recommended since they may not exist on another machine (on Windows, escape the backslashes).

contracts_directory

Uncompiled contract sources. Default ./contracts.

JavaScript
javascript
module.exports = { contracts_directory: './src' };

build_directory

Base directory for build output. Default ./build. contracts_build_directory and build_info_directory sit inside it by default, so changing this moves both.

JavaScript
javascript
module.exports = { build_directory: './output' };

contracts_build_directory

Compiled contract artifacts. Default ./build/contracts.

JavaScript
javascript
module.exports = { contracts_build_directory: './output/contracts' };

build_info_directory

solc build-info for each compilation — the standard-JSON input (<hash>.json) and output (<hash>.output.json). Default ./build/build-info.

JavaScript
javascript
module.exports = { build_info_directory: './output/build-info' };

TIP

NOTE: The build_info_directory option requires TronBox v4.7.0 or later.

migrations_directory

Migration scripts. Default ./migrations.

JavaScript
javascript
module.exports = { migrations_directory: './migrate' };

test_directory

Test files run by tronbox test. Default ./test.

JavaScript
javascript
module.exports = { test_directory: './spec' };

Compiler configuration

In the compilers object, you can specify settings related to the compilers used by TronBox.

solc

Solidity compiler settings support optimizer settings for solc.

For example:

JavaScript
javascript
module.exports = {
  compilers: {
    solc: {
      version: '0.8.6',
      // An object with the same schema as the settings entry in the Input JSON.
      // See https://docs.soliditylang.org/en/latest/using-the-compiler.html#input-description
      settings: {
        optimizer: {
          enabled: true,
          runs: 200
        },
        evmVersion: 'istanbul',
        viaIR: true
      }
    }
  }
};