-
Notifications
You must be signed in to change notification settings - Fork 328
Open
Description
this is the sample that I tested on my local node tron/quickstart:
and base on examples it didn't work! but the tronweb.js works perfectly on this local node!
Based on my test these functions didn't work!
doc_balance($tron); // didn't work!
doc_isConnected($tron); //didn't work!
doc_transferTrx($tron); // didn't work!
doc_universal($tron); //didn't work!
the transfer trx gets these logs:
ULL-NODE /wallet/createtransaction
[Output] {"Error":"class org.tron.core.exception.ContractValidateException : Invalid ownerAddress"}
and get balance gives this logs:
SOLIDITY-NODE /walletsolidity/getaccount
[Output] {}
the code samples
// Include Composer's autoloader
error_reporting(E_ALL);
ini_set('display_errors', 1);
require 'vendor/autoload.php';
// Import necessary classes
use IEXBase\TronAPI\Tron;
use IEXBase\TronAPI\Provider\HttpProvider;
use IEXBase\TronAPI\Support\Utils;
$fullNode = new HttpProvider('http://192.168.152.130:9090');
$solidityNode = new HttpProvider('http://192.168.152.130:9090');
$eventServer = new HttpProvider('http://192.168.152.130:9090');
$tron = new Tron($fullNode, $solidityNode, $eventServer);
//getBlock($tron);
//createAccount($tron);
//doc_createAccount($tron);
//doc_amount($tron);
//doc_hex($tron);
doc_balance($tron); // not working!
//doc_isConnected($tron); // not working!
//doc_transferTrx($tron); // not working!
//doc_universal($tron); // not working!
function doc_universal($tron) {
$tron->setPrivateKey('7f42e17cd37bc3a36d0ac17c3c6ef801f45b9a815d9809eb68af6b4395a1b498');
$addresses = [
['TRWBqiqoFZysoAeyR1J35ibuyc8EvhUAoY', true],
['TADUxt3ttLmTCjUxaWiDwZdZyTJMKiSini', true],
['TAtFWgZxaLLcWY2geWQCJYsHgTLmLZUi7x', false],
];
$check = $tron->balances($addresses);
var_dump($check);
$toArray = [
['TADUxt3ttLmTCjUxaWiDwZdZyTJMKiSini', 10000],
['TAtFWgZxaLLcWY2geWQCJYsHgTLmLZUi7x', 50000]
];
//default: $this->setPrivateKey();
$send = $tron->sendOneToMany('TAtFWgZxaLLcWY2geWQCJYsHgTLmLZUi7x', $toArray, '7f42e17cd37bc3a36d0ac17c3c6ef801f45b9a815d9809eb68af6b4395a1b498');
var_dump($send);
}
function doc_transferTrx($tron) {
$tron->setAddress('TAtFWgZxaLLcWY2geWQCJYsHgTLmLZUi7x');
$tron->setPrivateKey('7f42e17cd37bc3a36d0ac17c3c6ef801f45b9a815d9809eb68af6b4395a1b498');
try {
$transaction = $tron->getTransactionBuilder()->sendTrx('TXJ4Qn2xiYTSVz3UoXCrxBhmpGS96GEGoj', 1000000, 'TAtFWgZxaLLcWY2geWQCJYsHgTLmLZUi7x');
$signedTransaction = $tron->signTransaction($transaction);
$response = $tron->sendRawTransaction($signedTransaction);
} catch (\IEXBase\TronAPI\Exception\TronException $e) {
die($e->getMessage());
}
var_dump($response);
}
function doc_balance($tron) {
$tron->setAddress('TAtFWgZxaLLcWY2geWQCJYsHgTLmLZUi7x');
$balance = $tron->getBalance(null, true);
var_dump($balance);
}
function doc_isConnected($tron) {
var_dump($tron->isConnected());
}
function doc_hex($tron) {
$hex = $tron->toHex('TXJ4Qn2xiYTSVz3UoXCrxBhmpGS96GEGoj');
//result: 41e9eb5f8ee07f33f3d218789078ccd2a22a2164db
$base58 = $tron->fromHex($hex);
//result: TXJ4Qn2xiYTSVz3UoXCrxBhmpGS96GEGoj
var_dump($hex);
var_dump($base58);
}
function doc_amount($tron) {
$from = $tron->toTron(12); //12000000
$to = $tron->fromTron(20000000); //20
var_dump($from);
var_dump($to);
}
function doc_createAccount($tron) {
try {
try {
$generateAddress = $tron->generateAddress(); // or createAddress()
$isValid = $tron->isAddress($generateAddress->getAddress());
echo 'Address hex: ' . $generateAddress->getAddress();
echo 'Address base58: ' . $generateAddress->getAddress(true);
echo 'Private key: ' . $generateAddress->getPrivateKey();
echo 'Public key: ' . $generateAddress->getPublicKey();
echo 'Is Validate: ' . $isValid;
// echo 'Raw data: '.$generateAddress->getRawData();
var_dump($generateAddress->getRawData());
} catch (\IEXBase\TronAPI\Exception\TronException $e) {
echo $e->getMessage();
}
} catch (TronException $e) {
echo "Error: " . $e->getMessage();
}
}
function createAccount($tron) {
try {
// Create a new account
$newAccount = $tron->createAccount();
// Using reflection to access protected properties
$reflection = new ReflectionClass($newAccount);
$responseProperty = $reflection->getProperty('response');
$responseProperty->setAccessible(true);
$response = $responseProperty->getValue($newAccount);
// Now you can access the keys
var_dump("Private Key: " . $response['private_key']);
var_dump("Public Key: " . $response['public_key']);
var_dump("Address (Hex): " . $response['address_hex']);
var_dump("Address (Base58): " . $response['address_base58']);
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}
function getBlock($tron) {
try {
// $block = $tron->getBlock();
var_dump($tron->getBlock());
// echo "Block Number: " . $block['block_header']['raw_data']['number'] . "\n";
} catch (TronException $e) {
echo "Error: " . $e->getMessage();
}
}
?>
Metadata
Metadata
Assignees
Labels
No labels