TRC-10 is a technical token standard supported by the TRON blockchain natively.
Transfer of TRC-10 generally consume only bandwidth. Unless, recipient is smart contract and that will consume both bandwidth and energy.
<?php
include_once "../libraries/vendor/autoload.php";
include_once("html_iframe_header.php");
include_once("tron_utils.php");
//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;
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
try {
$ownerAddressHex = base58check2HexString($_POST['from']);
$toAddressHex = base58check2HexString($_POST['to']);
$ownerAddressBin = hex2str($ownerAddressHex);
$toAddressBin = hex2str($toAddressHex);
$tokenName = $_POST['token_id'];
$tokenAmount = bcmul($_POST['token_amount'], bcpow("10", $_POST['token_decimals'], 0), 0);
$contract = new \Protocol\Transaction\Contract();
$transferAsset = new \Protocol\TransferAssetContract();
$transferAsset->setAssetName($tokenName);
$transferAsset->setAmount($tokenAmount);
$transferAsset->setOwnerAddress($ownerAddressBin);
$transferAsset->setToAddress($toAddressBin);
$any = new \Google\Protobuf\Any();
$any->pack($transferAsset);
$contract->setParameter( $any );
$contract->setType( \Protocol\Transaction\Contract\ContractType::TransferAssetContract );
?>
<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
}
?>
<form action='' method='post'>
<div class="form-group">
<label for="token_id">Token ID:</label>
<input class="form-control" type='text' name='token_id' id='token_id' value='<?php echo $_POST['token_id']?>'>
</div>
<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="to">To Address:</label>
<input class="form-control" type='text' name='to' id='to' value='<?php echo $_POST['to']?>'>
</div>
<div class="form-group">
<label for="token_decimals">Token Decimal Places:</label>
<input class="form-control" type='text' name='token_decimals' id='token_decimals' value='<?php echo $_POST['token_decimals']?>'>
</div>
<div class="form-group">
<label for="token_amount">Send Token Amount:</label>
<input class="form-control" type='text' name='token_amount' id='token_amount' value='<?php echo $_POST['token_amount']?>'>
</div>
<input type='submit' class="btn btn-success btn-block"/>
</form>
<?php
include_once("html_iframe_footer.php");
message TransferAssetContract {
#token ID
bytes asset_name = 1;
#spender address
bytes owner_address = 2;
#recipient address
bytes to_address = 3;
#token amount
int64 amount = 4;
}
<?php
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: core/contract/asset_issue_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.TransferAssetContract</code>
*/
class TransferAssetContract extends \Google\Protobuf\Internal\Message
{
/**
* this field is token name before the proposal ALLOW_SAME_TOKEN_NAME is active, otherwise it is token id and token is should be in string format.
*
* Generated from protobuf field <code>bytes asset_name = 1;</code>
*/
protected $asset_name = '';
/**
* Generated from protobuf field <code>bytes owner_address = 2;</code>
*/
protected $owner_address = '';
/**
* Generated from protobuf field <code>bytes to_address = 3;</code>
*/
protected $to_address = '';
/**
* Generated from protobuf field <code>int64 amount = 4;</code>
*/
protected $amount = 0;
/**
* Constructor.
*
* @param array $data {
* Optional. Data for populating the Message object.
*
* @type string $asset_name
* this field is token name before the proposal ALLOW_SAME_TOKEN_NAME is active, otherwise it is token id and token is should be in string format.
* @type string $owner_address
* @type string $to_address
* @type int|string $amount
* }
*/
public function __construct($data = NULL) {
\GPBMetadata\Core\Contract\AssetIssueContract::initOnce();
parent::__construct($data);
}
/**
* this field is token name before the proposal ALLOW_SAME_TOKEN_NAME is active, otherwise it is token id and token is should be in string format.
*
* Generated from protobuf field <code>bytes asset_name = 1;</code>
* @return string
*/
public function getAssetName()
{
return $this->asset_name;
}
/**
* this field is token name before the proposal ALLOW_SAME_TOKEN_NAME is active, otherwise it is token id and token is should be in string format.
*
* Generated from protobuf field <code>bytes asset_name = 1;</code>
* @param string $var
* @return $this
*/
public function setAssetName($var)
{
GPBUtil::checkString($var, False);
$this->asset_name = $var;
return $this;
}
/**
* Generated from protobuf field <code>bytes owner_address = 2;</code>
* @return string
*/
public function getOwnerAddress()
{
return $this->owner_address;
}
/**
* Generated from protobuf field <code>bytes owner_address = 2;</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 to_address = 3;</code>
* @return string
*/
public function getToAddress()
{
return $this->to_address;
}
/**
* Generated from protobuf field <code>bytes to_address = 3;</code>
* @param string $var
* @return $this
*/
public function setToAddress($var)
{
GPBUtil::checkString($var, False);
$this->to_address = $var;
return $this;
}
/**
* Generated from protobuf field <code>int64 amount = 4;</code>
* @return int|string
*/
public function getAmount()
{
return $this->amount;
}
/**
* Generated from protobuf field <code>int64 amount = 4;</code>
* @param int|string $var
* @return $this
*/
public function setAmount($var)
{
GPBUtil::checkInt64($var);
$this->amount = $var;
return $this;
}
}