A system contract used to interact with smart contract.
<?php define("TRX_TO_SUN",'1000000'); define("SUN_TO_TRX", '0.000001'); 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 { $data = ltrim($_POST['data'], '0x'); $ownerAddressHex = base58check2HexString($_POST['from']); $contractAddressHex = base58check2HexString($_POST['caddress']); $ownerAddressBin = hex2str($ownerAddressHex); $contractAddressBin = hex2str($contractAddressHex); $callValueInSun = bcmul($_POST['callvalue'], TRX_TO_SUN); $contract = new \Protocol\Transaction\Contract(); $triggerSmartContract = new \Protocol\TriggerSmartContract(); $triggerSmartContract->setData(hex2str($data)); $triggerSmartContract->setOwnerAddress($ownerAddressBin); $triggerSmartContract->setContractAddress($contractAddressBin); $triggerSmartContract->setCallValue($callValueInSun); $any = new \Google\Protobuf\Any(); $any->pack($triggerSmartContract); $contract->setParameter( $any ); $contract->setType( \Protocol\Transaction\Contract\ContractType::TriggerSmartContract ); ?> <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="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="caddress">Contract Address:</label> <input class="form-control" type='text' name='caddress' id='caddress' value='<?php echo $_POST['caddress']?>'> </div> <div class="form-group"> <label for="callvalue">Call Value:</label> <div class="input-group mb-3"> <input class="form-control" type='text' name='callvalue' id='callvalue' value='<?php echo $_POST['callvalue']?>'> <div class="input-group-append"> <span class="input-group-text">TRX</span> </div> </div> <small>* Put 0 if you do not want to send any TRX to contract address.</small> </div> <div class="form-group"> <label for="data">Encoded Data (Hex):</label> <input class="form-control" type='text' name='data' id='data' value='<?php echo $_POST['data']?>'> <small>* You can use <a href="https://www.btcschools.net/ethereum/eth_abi_data_encoding.php" target="_blank">ethereum abi encoding tool</a> to generate this data.</small> </div> <input type='submit' class="btn btn-success btn-block"/> </form> <?php include_once("html_iframe_footer.php");
message TriggerSmartContract { #The owner of the current account bytes owner_address = 1; #A contract address to interact bytes contract_address = 2; #TRX value int64 call_value = 3; #Encoded data includes contract function and its params bytes data = 4; }
<?php # Generated by the protocol buffer compiler. DO NOT EDIT! # source: core/contract/smart_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.TriggerSmartContract</code> */ class TriggerSmartContract extends \Google\Protobuf\Internal\Message { /** * Generated from protobuf field <code>bytes owner_address = 1;</code> */ protected $owner_address = ''; /** * Generated from protobuf field <code>bytes contract_address = 2;</code> */ protected $contract_address = ''; /** * Generated from protobuf field <code>int64 call_value = 3;</code> */ protected $call_value = 0; /** * Generated from protobuf field <code>bytes data = 4;</code> */ protected $data = ''; /** * Generated from protobuf field <code>int64 call_token_value = 5;</code> */ protected $call_token_value = 0; /** * Generated from protobuf field <code>int64 token_id = 6;</code> */ protected $token_id = 0; /** * Constructor. * * @param array $data { * Optional. Data for populating the Message object. * * @type string $owner_address * @type string $contract_address * @type int|string $call_value * @type string $data * @type int|string $call_token_value * @type int|string $token_id * } */ public function __construct($data = NULL) { \GPBMetadata\Core\Contract\SmartContract::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 contract_address = 2;</code> * @return string */ public function getContractAddress() { return $this->contract_address; } /** * Generated from protobuf field <code>bytes contract_address = 2;</code> * @param string $var * @return $this */ public function setContractAddress($var) { GPBUtil::checkString($var, False); $this->contract_address = $var; return $this; } /** * Generated from protobuf field <code>int64 call_value = 3;</code> * @return int|string */ public function getCallValue() { return $this->call_value; } /** * Generated from protobuf field <code>int64 call_value = 3;</code> * @param int|string $var * @return $this */ public function setCallValue($var) { GPBUtil::checkInt64($var); $this->call_value = $var; return $this; } /** * Generated from protobuf field <code>bytes data = 4;</code> * @return string */ public function getData() { return $this->data; } /** * Generated from protobuf field <code>bytes data = 4;</code> * @param string $var * @return $this */ public function setData($var) { GPBUtil::checkString($var, False); $this->data = $var; return $this; } /** * Generated from protobuf field <code>int64 call_token_value = 5;</code> * @return int|string */ public function getCallTokenValue() { return $this->call_token_value; } /** * Generated from protobuf field <code>int64 call_token_value = 5;</code> * @param int|string $var * @return $this */ public function setCallTokenValue($var) { GPBUtil::checkInt64($var); $this->call_token_value = $var; return $this; } /** * Generated from protobuf field <code>int64 token_id = 6;</code> * @return int|string */ public function getTokenId() { return $this->token_id; } /** * Generated from protobuf field <code>int64 token_id = 6;</code> * @param int|string $var * @return $this */ public function setTokenId($var) { GPBUtil::checkInt64($var); $this->token_id = $var; return $this; } }