tron-php icon indicating copy to clipboard operation
tron-php copied to clipboard

I can't get balance

Open jomagalo opened this issue 2 years ago • 1 comments

Following the example indicating to create a trc20 wallet, it is created correctly.

use GuzzleHttp\Client;

$uri = 'https://api.trongrid.io';// mainnet
// $uri = 'https://api.shasta.trongrid.io';// shasta testnet
$api = new \Tron\Api(new Client(['base_uri' => $uri]));

$trxWallet = new \Tron\TRX($api);
$addressData = $trxWallet->generateAddress();
// $addressData->privateKey
// $addressData->address

$config = [
    'contract_address' => 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',// USDT TRC20
    'decimals' => 6,
];
$trc20Wallet = new \Tron\TRC20($api, $config);
$addressData = $trc20Wallet->generateAddress();

But I try to modify the same code to get the balance and it gives errors.

These are the unsuccessful tests:

use GuzzleHttp\Client;

$uri = 'https://api.trongrid.io';// mainnet
// $uri = 'https://api.shasta.trongrid.io';// shasta testnet
$api = new \Tron\Api(new Client(['base_uri' => $uri]));

$wallet = "TXXXXX...";

$trxWallet = new \Tron\TRX($api);
$balance = $trxWallet->balance($wallet);
// $addressData->privateKey
// $addressData->address

$config = [
    'contract_address' => 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',// USDT TRC20
    'decimals' => 6,
];
$trc20Wallet = new \Tron\TRC20($api, $config);
$balance = $trc20Wallet->balance($wallet);

I have also tried like this:

use GuzzleHttp\Client;

$uri = 'https://api.trongrid.io';// mainnet
// $uri = 'https://api.shasta.trongrid.io';// shasta testnet
$api = new \Tron\Api(new Client(['base_uri' => $uri]));

$wallet = "TXXXXX...";

$trxWallet = new \Tron\TRX($api);
$balance = $trxWallet->balance(Address $wallet);
// $addressData->privateKey
// $addressData->address

$config = [
    'contract_address' => 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',// USDT TRC20
    'decimals' => 6,
];
$trc20Wallet = new \Tron\TRC20($api, $config);
$balance = $trc20Wallet->balance(Address $wallet);

jomagalo avatar May 02 '22 06:05 jomagalo

https://github.com/Fenguoz/tron-php/blob/master/tests/TRC20Test.php#L59

Fenguoz avatar May 09 '22 00:05 Fenguoz