TronWeb API Documentation

website·Indexed 30 days ago

https://gleaming-choux-c601ed.netlify.app/docs/API List/

API reference for TronWeb (v6.0.0, v6.2.0), a JavaScript library for interacting with the TRON blockchain. Includes methods for managing TRX accounts, querying block information, deploying smart contracts, and utility functions for address conversion and ABI encoding/decoding.

Tokens
132.9K
Snippets
702
Records
993
Agent score
71%

What's inside TronWeb

  1. Retrieve TRC10 token information by ID using tronWeb.trx.getTokenFromID

    The tronWeb.trx.getTokenFromID() method allows you to query information about a TRC10 token using its specific token ID. The method accepts the token ID as either a String or a Number and returns a Promise that resolves to an Object containing token details such as the owner address, token name, abbreviation, total supply, and precision.
    // You can pass the token ID as a number
    tronWeb.trx.getTokenFromID(1002000).then(result => {
      console.log(result);
    });
    
    // Or as a string
    tronWeb.trx.getTokenFromID("1002000").then(result => {
      console.log(result);
    });
    
    /* 
    Example Return Object:
    {
      owner_address: '4137fa1a56eb8c503624701d776d95f6dae1d9f0d6',
      name: 'BitTorrent',
      abbr: 'BTT',
      total_supply: 990000000000000000,
      trx_num: 1,
      precision: 6,
      num: 1,
      start_time: 1548000000000,
      end_time: 1548000001000,
      description: 'Official Token of BitTorrent Protocol',
      url: 'www.bittorrent.com',
      id: '1002000'
    }
    */
  2. Retrieve a list of all exchange pairs using tronWeb.trx.listExchanges()

    Use the tronWeb.trx.listExchanges() method to query a list of all exchange pairs. This method returns a Promise that resolves to an Array of exchange objects. Each object contains details about the exchange, including its unique ID, the creator's address, the timestamp of creation, and information regarding the two tokens involved in the pair (IDs and balances).
    tronWeb.trx.listExchanges().then(result => {
      console.log(result);
    });
  3. Retrieve block information using tronWeb.trx.getBlock

    The tronWeb.trx.getBlock method allows you to query detailed information about a block. You can specify the block by its height (integer), its unique block ID (string), or use the keywords 'latest' or 'earliest' to retrieve the most recent or first block respectively.
    // Get block by height
    await tronWeb.trx.getBlock(12345);
    
    // Get block by block ID
    await tronWeb.trx.getBlock('000000000000303987c7c8ab3f5967c107a619fa47819940597e9938811a1764');
    
    // Get the latest block
    await tronWeb.trx.getBlock('latest');
  4. Retrieve block information using tronWeb.trx.getBlock

    The tronWeb.trx.getBlock method queries information about a specific block. You can identify the block by its height (integer), its unique block ID (string), or by using the keywords 'latest' or 'earliest'. The method returns a Promise that resolves to an object containing the block's ID, header (including raw data like timestamp and parent hash), and the list of transactions included in that block.
    // Retrieve block by height
    tronWeb.trx.getBlock(12345).then(result => {
      console.log(result);
    });
    
    // Retrieve block by blockId
    tronWeb.trx.getBlock('000000000000303987c7c8ab3f5967c107a619fa47819940597e9938811a1764').then(result => {
      console.log(result);
    });
    
    // Retrieve the most recent block
    tronWeb.trx.getBlock('latest').then(result => {
      console.log(result);
    });
  5. Retrieve block information using tronWeb.trx.getBlock

    The tronWeb.trx.getBlock method allows you to query detailed information about a specific block on the TRON network. You can identify the block using its height (block number), its unique block ID, or special keywords for the most recent or earliest blocks.
    tronWeb.trx.getBlock(blockNumberOrBlockId);
  6. Retrieve TRC10 token information by ID

    Use the tronWeb.trx.getTokenByID method to query detailed information about a TRC10 token. The method accepts the token ID as either a string or a number and returns a promise that resolves to an object containing token details such as owner address, name, abbreviation, total supply, and precision.
    // You can pass the token ID as a number or a string
    tronWeb.trx.getTokenByID(1002000).then(result => {
      console.log(result);
    });
    
    // Example output object:
    // {
    //   owner_address: '4137fa1a56eb8c503624701d776d95f6dae1d9f0d6',
    //   name: 'BitTorrent',
    //   abbr: 'BTT',
    //   total_supply: 990000000000000000,
    //   trx_num: 1,
    //   precision: 6,
    //   num: 1,
    //   start_time: 1548000000000,
    //   end_time: 1548000001000,
    //   description: 'Official Token of BitTorrent Protocol',
    //   url: 'www.bittorrent.com',
    //   id: '1002000'
    // }
  7. Retrieve TRON node information using getNodeInfo

    Use the tronWeb.trx.getNodeInfo() method to get detailed status and configuration information about the TRON node. The method returns a Promise that resolves to an object containing node configuration (configNodeInfo), hardware specifications (machineInfo), current connection counts, and a list of connected peers (peerList).
    tronWeb.trx.getNodeInfo().then(result => {
      console.log(result);
    });
  8. Retrieve a list of all exchange pairs using listExchanges

    Use the tronWeb.trx.listExchanges() method to query a list of all exchange pairs. This function returns a Promise that resolves to an Array of exchange objects. Each object contains details about the exchange pair, including the exchange ID, the creator's address, the creation timestamp, and the IDs and balances of the two tokens involved in the pair.
    tronWeb.trx.listExchanges().then(result => {
      console.log(result);
    });
  9. Retrieve the list of Super Representatives using tronWeb

    Use the tronWeb.trx.listSuperRepresentatives() method to query the current list of witnesses (Super Representatives) on the TRON network. The method returns a Promise that resolves to an array of objects, each containing details about a Super Representative such as their address, vote count, production statistics, and associated URL.
    tronWeb.trx.listSuperRepresentatives().then(result => {
      console.log(result);
    });
  10. Retrieve block information by block height using getBlockByNumber

    The tronWeb.trx.getBlockByNumber() method allows you to query detailed information about a specific block on the TRON network using its block height (number). It accepts a single integer representing the block height and returns a Promise that resolves to an object containing the block ID and block header (including raw data like timestamp, parent hash, and witness address).
    // Query block information for block height 12345
    tronWeb.trx.getBlockByNumber(12345).then(result => {
      console.log(result);
    });
    
    /* 
    Expected Return Object Structure:
    {
      blockID: '000000000000303987c7c8ab3f5967c107a619fa47819940597e9938811a1764',
      block_header: {
        raw_data: {
          number: 12345,
          txTrieRoot: '0000000000000000000000000000000000000000000000000000000000000000',
          witness_address: '414b4778beebb48abe0bc1df42e92e0fe64d0c8685',
          parentHash: '0000000000003038c0a3aa1806236bc5b281633728b5fe8a14a51062522e651d',
          timestamp: 1529928585000
        },
        witness_signature: 'cb889103aa9ce691d39df8030b54b50b12b77984684281f3490e0b802cbc364c13af773ede8d9314add0fa4d247165be82fa28721f17493c88761b7039ba1c1100'
      }
    }
    */
  11. Retrieve TRC10 token information by ID

    Use the tronWeb.trx.getTokenByID method to query information about a specific TRC10 token. The method accepts the token ID as either a String or a Number and returns an object containing token details such as the owner address, name, abbreviation, total supply, precision, and description.
    // Using await
    const tokenInfo = await tronWeb.trx.getTokenByID(1002000);
    console.log(tokenInfo);
    
    // Using .then()
    tronWeb.trx.getTokenByID('1002000').then(result => {
      console.log(result);
    });
  12. Build TRON transactions locally with TronWeb v5.2.0

    Starting from version 5.2.0, TronWeb builds transactions locally using protobuf and block header information instead of requesting the TRON node to build them. This increases security by ensuring transaction data is created within the local client. The resulting transaction data remains compatible with previous versions.