TronBox

repository·master·Indexed 42 days ago

https://github.com/tronprotocol/tronbox

A development framework and testing environment for smart contracts on the TRON Virtual Machine (TVM), version 4.10.0. It provides a workflow for compiling, deploying, testing, and interacting with smart contracts on TRON networks, including Mainnet, Shasta Testnet, Nile Testnet, and Localnet via the TronBox Runtime Environment (TRE). It supports Solidity compilation, incremental builds, and EVM-compatible blockchains.

Tokens
12.8K
Snippets
56
Records
71
Agent score
52%

What's inside TronBox

  1. Migrate contracts to different networks

    master

    You can deploy your contracts to various networks using the tronbox migrate command with the --network flag. The MetaCoin project supports the following networks:

    # Deploy to Mainnet
    tronbox migrate --network mainnet
    
    # Deploy to Shasta Testnet
    tronbox migrate --network shasta
    
    # Deploy to Nile Testnet
    tronbox migrate --network nile
    
    # Deploy to Localnet
    tronbox migrate
  2. Initialize a default TronBox project

    master

    Create a new project structure by running tronbox init. This command generates the following directory structure:

    • contracts/: Directory for Solidity contracts.
    • migrations/: Directory for scriptable deployment files.
    • test/: Directory for test files for testing your application and contracts.
    • tronbox-config.js: TronBox configuration file.
    $ tronbox init
  3. Use EVM compatibility mode with Ethers.js

    master

    When initializing init with { evm: true }, the wrapper attaches an _ethers object to the returned instance. This object provides access to the ethers library, a provider, and signers, enabling developers to use standard Ethers.js patterns on the TRON network.

    Key properties on tronWrap._ethers:

    • provider: The ethers.JsonRpcProvider instance.
    • getSigner(address): Returns an EthersSignerProxy for the specified address.
    • getSigners(): Returns an array of all available signers as EthersSignerProxy instances.
    const tronWrap = init(options, { evm: true });
    const signer = tronWrap._ethers.getSigner(address);
    // Use signer with standard ethers.js methods
  4. How ConsoleLogger decodes Solidity console.log messages

    master

    The ConsoleLogger utility is used to extract and format console.log output from Tron transactions. It works by inspecting the internal_transactions of a transaction for calls made to the special CONSOLE_ADDRESS (41000000000000000000636f6e736f6c652e6c6f67).

    When a match is found, the logger uses the transaction data to identify the function signature (via its hash), determines the expected parameter types, and decodes the hex data into human-readable values (converting address to standard formats and uint256/int256 to strings).

  5. Structure of a compiled contract definition

    master

    When a compilation is successful, the returnVal object contains contract definitions keyed by the contract_name. Each definition includes:

    • contract_name: The name of the contract.
    • sourcePath: The original path to the source file.
    • source: The raw source code.
    • sourceMap: The EVM bytecode source map.
    • deployedSourceMap: The deployed bytecode source map.
    • abi: The Application Binary Interface.
    • bytecode: The compiled bytecode (prefixed with 0x).
    • deployedBytecode: The deployed bytecode (prefixed with 0x).
    • unlinked_binary: The unlinked binary (deprecated).
    • compiler: An object containing name (e.g., 'solc') and version.
  6. Configure network parameters in TronBox

    master

    The tronWrap instance maintains a networkConfig object derived from the initialization options. This object is used to resolve transaction parameters like feeLimit, originEnergyLimit, and callValue.

    When performing operations, the wrapper resolves options in the following priority:

    1. Explicitly provided txOptions (e.g., in a contract call).
    2. The networkConfig derived from the initial init() call.
    3. Default constants defined in the project.

    Supported configuration keys include:

    • fullNode / fullHost
    • feeLimit / fee_limit
    • originEnergyLimit / origin_energy_limit
    • callValue / call_value
    • tokenValue / token_value
    • userFeePercentage / consume_user_resource_percent
  7. Initialize a new TronBox project

    master

    You can initialize a new TronBox project by running the initialization command (typically via the tronbox init CLI command). The process will prompt you to choose between different project templates or allow you to quit.

    Project Templates

    • Create a sample project: Sets up a standard JavaScript-based TronBox project.
    • Create a MetaCoin project: Sets up a JavaScript project specifically using the MetaCoin template.

    Requirements and Behavior

    • Empty Directory: The initialization must be performed in an empty directory. If the directory contains files (excluding .DS_Store), the process will fail with an error: This directory is not empty. Please execute 'tronbox init' in an empty directory..
    • Dependency Installation: If a package.json file is present in the template, TronBox will automatically attempt to run npm install to install the necessary dependencies.
    • Success: Upon successful creation, you will see a success message and are advised to check the README.md file for example commands.