@layerzerolabs/hardhat-tron
TypeScript icon, indicating that this package has built-in type declarations

3.0.6 • Public • Published

@layerzerolabs/hardhat-tron

Hardhat plugin for integrating the Tron Solidity Compiler.

This plugin provides seamless integration of the Tron Solidity Compiler into the Hardhat build environment. It extends Hardhat's native Solidity compilation tasks to support Tron's version of the solc compiler. This allows developers working on Tron blockchain projects to compile their smart contracts within the familiar Hardhat environment, using Tron's specific compiler versions and configurations.

Installation

yarn add -D @layerzerolabs/hardhat-tron

Import the plugin in your hardhat.config.ts:

import "@layerzerolabs/hardhat-tron";

required plugins

The following plugin is needed to support hardhat deployments on Tron chains

Tasks

This plugin overrides several internal Hardhat tasks to integrate the Tron Solidity Compiler:

  • compile: Extended for compiling with the Tron solc compiler.
  • clean: Enhanced to clean Tron-specific artifacts and cache.

Environment extensions

This plugin extends the Hardhat Runtime Environment by adding configurations and utilities for handling the Tron Solidity Compiler. This includes network configurations specific to the Tron blockchain and support for downloading and setting up the Tron version of solc.

Configuration

This plugin extends the HardhatUserConfig with Tron-specific compiler configurations. In addition to the predefined versions known by the plugin, it is possible to select a compiler version greater than the latest known. The plugin will attempt to download and use the specified compiler version. However, if the specified version does not exist, it will throw an error.

All tronSolc.compilers versions must also be declared in the solidity.compilers array.

const hardhatConfig = {
  ...regularHardhatConfig,
  tronSolc: {
    enable: true,
    // Optional: specify an array of contract filenames (without path) to selectively compile. Leave as empty array to compile all contracts.
    filter: [],
    compilers: [{ version: "0.7.7" }, { version: "0.8.20" }], // can be any tron-solc version
    // Optional: Define version remappings for compiler versions
    versionRemapping: [
      ["0.7.7", "0.7.6"], // Remap version "0.7.7" to "0.7.6"
      ["0.8.22", "0.8.20"], // Remap version "0.8.20" to "0.8.19"
    ],
  },
  networks: {
    shasta: {
      url: "https://api.shasta.trongrid.io/jsonrpc",
      accounts: [process.env.TRON_PRIVATE_KEY],
      httpHeaders: { "TRON-PRO-API-KEY": process.env.TRON_PRO_API_KEY },
      tron: true,
    },
  },
};

Usage

After installation, the plugin automatically hooks into Hardhat's compilation tasks. Configure the Tron solc compiler in the Hardhat configuration file as shown above. The plugin handles the rest, ensuring that your smart contracts are compiled with the appropriate version of the Tron Solidity Compiler.

  • If you want to compile contracts using tron-solc, you must pass the network option to force the use of tron-solc. like the following command:

    yarn hardhat compile --network tron

    After compiling the contracts, two non-empty folders, artifacts-tron and cache_hardhat-tron, will be generated.

  • Ensure that your URL supports Ethereum's JSON-RPC. For example, the following command will fail:

    curl -X POST 'https://api.shasta.trongrid.io' --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":79}'

    This is because the URL https://api.shasta.trongrid.io is not supported. However, if you change the URL to https://api.shasta.trongrid.io/jsonrpc, the command will succeed.

    curl -X POST 'https://api.shasta.trongrid.io/jsonrpc' --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":79}'

Note: Make sure to enable the plugin in your Hardhat configuration and specify the required compiler versions for your project.

Version Remapping

The versionRemapping option allows you to specify Solidity versions to remap. This is useful when you want to compile contracts with a specific version of the Tron Solidity Compiler that is different from the one declared in the contract files. The map keys are the original versions specified in your contract files, and the values are the target compiler versions you wish to use instead.

To use this feature, simply add the versionRemapping property to your tronSolc configuration in the Hardhat config file. The map should contain entries where each key is the version to be replaced, and each value is the new target version.

Filter Option

The filter option in the tronSolc configuration allows for selective compilation of Solidity contracts. By specifying an array of contract filenames, you can target specific contracts for compilation. To compile all contracts in your project, set filter to an empty array. Note: The filenames in the filter array should not include the path, only the contract file names without the extension.

Readme

Keywords

none

Package Sidebar

Install

npm i @layerzerolabs/hardhat-tron

Weekly Downloads

242

Version

3.0.6

License

BUSL-1.1

Unpacked Size

6.64 MB

Total Files

74

Last publish

Collaborators

  • layerzero-bot