Tron Address


The terms wallet, account & address are usually equivalent to each other but instead we use address herein. An address must be associated with its private key otherwise your fund will just lost!


  • Start with 'T' or 41 in hex string representation.

Tron Address Generate Locally (Account Not Activated)

<?php 
use kornrunner\Keccak;
use BitWasp\Bitcoin\Key\Factory\PrivateKeyFactory;
use BitWasp\Bitcoin\Crypto\Random\Random;
use BitWasp\Buffertools\Buffer;
use BitWasp\Bitcoin\Base58;

include_once "../libraries/vendor/autoload.php";
include_once("html_iframe_header.php");

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    try {
       
        $privKeyFactory = new PrivateKeyFactory();

        if (!$_POST['input'] OR ctype_xdigit($_POST['input'])) 
        {
            if (!$_POST['input']) 
            { 
                $rbg = new Random();
                $privateKey = $privKeyFactory->generateUncompressed($rbg);
                
            } else {
                
                $privateKey = $privKeyFactory->fromHexUncompressed($_POST['input']);
            }
        } 
		
		$publicKey  = $privateKey->getPublicKey();
		$publicKeyHex = substr($publicKey->getHex(), 2);
		
		$hash = Keccak::hash(hex2bin($publicKeyHex), 256);
		$hash = "41" . substr($hash, -40);
		
		$bf = Buffer::hex($hash);
		
		$tronAddress = Base58::encodeCheck($bf);
		
    ?>
        <div class="table-responsive">
            <table border=0 class='table'>
                <tr style='background-color:#f0f0f0'><td>Base58 Address</td><td><?php echo $tronAddress?></td></tr>
				<tr><td>Hex Address</td><td><?php echo $bf->getHex();?></td></tr>
                <tr style='background-color:#f0f0f0'><td>Private Key Hex</td><td><?php echo $privateKey->getHex()?></td></tr>               
                <tr><td>Public Key Hex</td><td><?php echo $publicKey->getHex()?></td></tr>
            </table>
        </div>
<?php 
    } catch (Exception $e) {
        $errmsg .= "Problem found. " . $e->getMessage();

    }
} 

if ($errmsg) {
?>
    <div class="alert alert-danger">
        <strong>Error!</strong> <?php echo $errmsg?>
    </div>
<?php
}
?>
<form action='' method='post'>
    <div class="form-group">
        <label for="input">Private Key (Hex):</label>
        <input class="form-control" type='text' name='input' id='input' value='<?php echo $_POST['input']?>'>
        * Put empty if you want system assign you a random private key.
    </div>
   
    <input type='submit' class="btn btn-success btn-block"/>
</form>
<?php
include_once("html_iframe_footer.php");

Tron new address is inactive after created. There are few ways to activate address.

  • Transfer TRX or TRC10 to newly created address and this will burn initiator's 0.1 Trx for bandwidth (Bandwidth consumed by byte size will be waived automatically.)
  • When transferring TRX or TRC10 from a contract to an inactive address, an additional 25,000 energy is consumed. (Creation fee of 0.1 TRX is exempted.)
  • Call the CreateAccount contract and this will burn initiator's 0.1 Trx for bandwidth.
Once address activated, energy and bandwidth will be shown in address resource page.

Activate Tron Address

<?php 

include_once "../libraries/vendor/autoload.php";
include_once("html_iframe_header.php");
include_once("tron_utils.php");

define("TRX_TO_SUN",'1000000');
define("SUN_TO_TRX", '0.000001');

//include all php files that generated by protoc
$dir   = new RecursiveDirectoryIterator('protobuf/core/');
$iter  = new RecursiveIteratorIterator($dir);
$files = new RegexIterator($iter, '/^.+\.php$/', RecursiveRegexIterator::GET_MATCH); // an Iterator, not an array

foreach ( $files as $file ) {
	
	if (is_array($file)) {
		foreach($file as $filename) {
			include $filename;
		}
	} else {
		include $file;
	}
}

$accType = ["0"=>"Normal","1"=>"Asset Issue", "2"=>"Contract"];

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    try {
		$ownerAddressHex = base58check2HexString($_POST['from']);
		$ownerAddressBin = hex2str($ownerAddressHex);
		
		$acctAddressHex = base58check2HexString($_POST['addr']);
		$acctAddressBin = hex2str($acctAddressHex);
		
		$contract = new \Protocol\Transaction\Contract();
		$accountCreateContract = new \Protocol\AccountCreateContract();
		$accountCreateContract->setType($_POST['type']);
		$accountCreateContract->setOwnerAddress($ownerAddressBin);
		$accountCreateContract->setAccountAddress($acctAddressBin);
		
		$any = new \Google\Protobuf\Any();
		$any->pack($accountCreateContract);
		
		$contract->setParameter( $any );
		$contract->setType( \Protocol\Transaction\Contract\ContractType::AccountCreateContract );
		
    ?>
	<div class="alert alert-success">
		<h6 class="mt-3">Contract Serialized Hex</h6>
		<textarea class="form-control" rows="5" id="comment" readonly><?php echo str2hex($contract->serializeToString());?></textarea>
		
		<h6 class="mt-3">Contract Serialized Json</h6>
		<textarea class="form-control" rows="5" id="comment" readonly><?php echo $contract->serializeToJsonString()?></textarea>
	</div>
<?php 
    } catch (Exception $e) {
        $errmsg .= "Problem found. " . $e->getMessage();

    }
} 

if ($errmsg) {
?>
    <div class="alert alert-danger">
        <strong>Error!</strong> <?php echo $errmsg?>
    </div>
<?php
}


$fullNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$solidityNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$eventServer = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');

$tron = new \IEXBase\TronAPI\Tron($fullNode, $solidityNode, $eventServer);

$chainParams = $tron->getManager()->request("wallet/getchainparameters", [], "get");
$value = getChainParamValue($chainParams['chainParameter'], $key = "getCreateAccountFee");

$createAccountFee = "N/A";
if ($value !== false) {
	$createAccountFee = bcmul($value, SUN_TO_TRX, 6);
}
?>
<div class="alert alert-info">
  <strong>Info!</strong> Create Account Fee: <?Php echo $createAccountFee?> TRX
</div>
<form action='' method='post'>
    <div class="form-group">
        <label for="from">Owner Address:</label>
        <input class="form-control" type='text' name='from' id='from' value='<?php echo $_POST['from']?>'>
    </div>
	
	<div class="form-group">
        <label for="addr">To Be Activated Address:</label>
        <input class="form-control" type='text' name='addr' id='addr' value='<?php echo $_POST['addr']?>'>
    </div>
	
	<div class="form-group">
		<label for="type">Type:</label>
		<select id="type" name="type" class="form-control" >
			<?php
			foreach($accType as $k=>$v) {
				echo "<option value='{$k}'".($k == $_POST['type'] ? " selected": "").">{$v}</option>";
			}
			?>
		</select>
	</div>
	
    <input type='submit' class="btn btn-success btn-block"/>
</form>
<?php
include_once("html_iframe_footer.php");
message AccountCreateContract {
	
	#The owner of the current account
	bytes owner_address = 1;
	
	#The target address to create
	bytes account_address = 2;
	
	#Account type. 0 = normal account, 1 = asset issue genesis account, 2 = contract account
	AccountType type = 3;
}
<?php
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: core/contract/account_contract.proto

namespace Protocol;

use Google\Protobuf\Internal\GPBType;
use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil;

/**
 * Generated from protobuf message <code>protocol.AccountCreateContract</code>
 */
class AccountCreateContract extends \Google\Protobuf\Internal\Message
{
    /**
     * Generated from protobuf field <code>bytes owner_address = 1;</code>
     */
    protected $owner_address = '';
    /**
     * Generated from protobuf field <code>bytes account_address = 2;</code>
     */
    protected $account_address = '';
    /**
     * Generated from protobuf field <code>.protocol.AccountType type = 3;</code>
     */
    protected $type = 0;

    /**
     * Constructor.
     *
     * @param array $data {
     *     Optional. Data for populating the Message object.
     *
     *     @type string $owner_address
     *     @type string $account_address
     *     @type int $type
     * }
     */
    public function __construct($data = NULL) {
        \GPBMetadata\Core\Contract\AccountContract::initOnce();
        parent::__construct($data);
    }

    /**
     * Generated from protobuf field <code>bytes owner_address = 1;</code>
     * @return string
     */
    public function getOwnerAddress()
    {
        return $this->owner_address;
    }

    /**
     * Generated from protobuf field <code>bytes owner_address = 1;</code>
     * @param string $var
     * @return $this
     */
    public function setOwnerAddress($var)
    {
        GPBUtil::checkString($var, False);
        $this->owner_address = $var;

        return $this;
    }

    /**
     * Generated from protobuf field <code>bytes account_address = 2;</code>
     * @return string
     */
    public function getAccountAddress()
    {
        return $this->account_address;
    }

    /**
     * Generated from protobuf field <code>bytes account_address = 2;</code>
     * @param string $var
     * @return $this
     */
    public function setAccountAddress($var)
    {
        GPBUtil::checkString($var, False);
        $this->account_address = $var;

        return $this;
    }

    /**
     * Generated from protobuf field <code>.protocol.AccountType type = 3;</code>
     * @return int
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * Generated from protobuf field <code>.protocol.AccountType type = 3;</code>
     * @param int $var
     * @return $this
     */
    public function setType($var)
    {
        GPBUtil::checkEnum($var, \Protocol\AccountType::class);
        $this->type = $var;

        return $this;
    }

}









Tutorials
About Us
Contents have been open source in GITHUB. Please give me a ⭐ if you found this helpful :)
Community
Problem? Raise me a new issue.
Support Us
Buy me a coffee. so i can spend more nights for this :)

BTCSCHOOLS would like to present you with more pratical but little theory throughout our tutorials. Pages' content are constantly keep reviewed to avoid mistakes, but we cannot warrant correctness of all contents. While using this site, you agree to accept our terms of use, cookie & privacy policy. Copyright 2019 by BTCSCHOOLS. All Rights Reserved.