Fenguoz / tron-php

Support TRON's TRX and TRC20, which include functions such as address creation, balance query, transaction transfer, query the latest blockchain, query information based on the blockchain, and query information based on the transaction hash
MIT License
200 stars 72 forks source link

getTRC20报错 #14

Closed mgx888 closed 3 years ago

mgx888 commented 3 years ago

//const URI = 'https://api.shasta.trongrid.io'; // shasta testnet const URI = 'https://api.trongrid.io';//测试地址? const ADDRESS = 'TGytofNKuSReFmFxsgnNx19em3BAVBTpVB'; const PRIVATE_KEY = '0xf1b4b7d86a3eff98f1bace9cb2665d0cad3a3f949bc74a7ffb2aaa968c07f521'; const BLOCK_ID = 13402554; const TX_HASH = '539e6c2429f19a8626fadc1211985728e310f5bd5d2749c88db2e3f22a8fdf69'; const CONTRACT = [ 'contract_address' => 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t', // USDT TRC20 'decimals' => 6, ];

private function getTRC20()
{
    $api = new Api(new Client(['base_uri' => self::URI]));
    $config = self::CONTRACT;
    $trxWallet = new TRC20($api, $config);
    return $trxWallet;
}

public function testGenerateAddress()
{
    $addressData = $this->getTRC20()->generateAddress();
    var_dump($addressData);

    $this->assertTrue(true);
}

报错如下 During class fetch: Uncaught ErrorException: Required parameter $from follows optional parameter $private_key

Fenguoz commented 3 years ago

看上去抱错应该不是这块代码报出来

Fenguoz commented 3 years ago

你可以试着参照测试用例调用 new TRC20

mgx888 commented 3 years ago

[2021-08-19 00:39:04] local.ERROR: During class fetch: Uncaught ErrorException: Required parameter $from follows optional parameter $private_key in /www/wwwroot/test/vendor/iexbase/tron-api/src/Concerns/ManagesUniversal.php:62 Stack trace:

0 /www/wwwroot/test/vendor/composer/ClassLoader.php(478): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()

1 /www/wwwroot/test/vendor/composer/ClassLoader.php(478): include()

2 /www/wwwroot/test/vendor/composer/ClassLoader.php(346): Composer\Autoload\includeFile()

3 /www/wwwroot/test/vendor/iexbase/tron-api/src/Tron.php(38): Composer\Autoload\ClassLoader->loadClass()

4 /www/wwwroot/test/vendor/composer/ClassLoader.php(478): include('...')

5 /www/wwwroot/test/vendor/composer/ClassLoader.php(346): Composer\Autoload\includeFile()

6 /www/wwwroot/test/vendor/fenguoz/tron-php/src/TRX.php(26): Composer\Autoload\ClassLoader->loadClass()

7 /www/wwwroot/test/app/Http/Controllers/Api/V1/test.php(343): Tron\TRX->__construct()

8 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\Http\Controllers\Api\V1\test->index110()

9 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction()

10 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Route.php(261): Illuminate\Routing\ControllerDispatcher->dispatch()

11 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Route.php(204): Illuminate\Routing\Route->runController()

12 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Router.php(695): Illuminate\Routing\Route->run()

13 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing{closure}()

14 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}()

15 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings->handle()

16 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(127): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}()

17 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(103): Illuminate\Routing\Middleware\ThrottleRequests->handleRequest()

18 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(55): Illuminate\Routing\Middleware\ThrottleRequests->handleRequestUsingNamedLimiter()

19 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\ThrottleRequests->handle()

20 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}()

21 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Router.php(697): Illuminate\Pipeline\Pipeline->then()

22 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Router.php(672): Illuminate\Routing\Router->runRouteWithinStack()

23 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Router.php(636): Illuminate\Routing\Router->runRoute()

24 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Router.php(625): Illuminate\Routing\Router->dispatchToRoute()

25 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(166): Illuminate\Routing\Router->dispatch()

26 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http{closure}()

27 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}()

28 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()

29 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()

30 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}()

31 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()

32 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TrimStrings->handle()

33 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}()

34 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()

35 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}()

36 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()

37 /www/wwwroot/test/vendor/fruitcake/laravel-cors/src/HandleCors.php(52): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}()

38 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fruitcake\Cors\HandleCors->handle()

39 /www/wwwroot/test/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}()

40 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle()

41 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}()

42 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(141): Illuminate\Pipeline\Pipeline->then()

43 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()

44 /www/wwwroot/test/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle()

45 {main} {"exception":"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): During class fetch: Uncaught ErrorException: Required parameter $from follows optional parameter $private_key in /www/wwwroot/test/vendor/iexbase/tron-api/src/Concerns/ManagesUniversal.php:62

Stack trace:

0 /www/wwwroot/test/vendor/composer/ClassLoader.php(478): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()

1 /www/wwwroot/test/vendor/composer/ClassLoader.php(478): include()

2 /www/wwwroot/test/vendor/composer/ClassLoader.php(346): Composer\Autoload\includeFile()

3 /www/wwwroot/test/vendor/iexbase/tron-api/src/Tron.php(38): Composer\Autoload\ClassLoader->loadClass()

4 /www/wwwroot/test/vendor/composer/ClassLoader.php(478): include('...')

5 /www/wwwroot/test/vendor/composer/ClassLoader.php(346): Composer\Autoload\includeFile()

6 /www/wwwroot/test/vendor/fenguoz/tron-php/src/TRX.php(26): Composer\Autoload\ClassLoader->loadClass()

7 /www/wwwroot/test/app/Http/Controllers/Api/V1/test.php(343): Tron\TRX->__construct()

8 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\Http\Controllers\Api\V1\test->index110()

9 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction()

10 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Route.php(261): Illuminate\Routing\ControllerDispatcher->dispatch()

11 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Route.php(204): Illuminate\Routing\Route->runController()

12 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Router.php(695): Illuminate\Routing\Route->run()

13 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing\{closure}()

14 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

15 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings->handle()

16 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(127): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

17 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(103): Illuminate\Routing\Middleware\ThrottleRequests->handleRequest()

18 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(55): Illuminate\Routing\Middleware\ThrottleRequests->handleRequestUsingNamedLimiter()

19 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\ThrottleRequests->handle()

20 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

21 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Router.php(697): Illuminate\Pipeline\Pipeline->then()

22 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Router.php(672): Illuminate\Routing\Router->runRouteWithinStack()

23 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Router.php(636): Illuminate\Routing\Router->runRoute()

24 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Routing/Router.php(625): Illuminate\Routing\Router->dispatchToRoute()

25 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(166): Illuminate\Routing\Router->dispatch()

26 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()

27 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

28 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()

29 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()

30 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

31 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()

32 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TrimStrings->handle()

33 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

34 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()

35 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

36 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()

37 /www/wwwroot/test/vendor/fruitcake/laravel-cors/src/HandleCors.php(52): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

38 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fruitcake\Cors\HandleCors->handle()

39 /www/wwwroot/test/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

40 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle()

41 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()

42 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(141): Illuminate\Pipeline\Pipeline->then()

43 /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()

44 /www/wwwroot/test/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle()

45 {main} at /www/wwwroot/test/vendor/iexbase/tron-api/src/Tron.php:38)

[stacktrace]

0 {main}

"} 以上是详细的报错,也确实是按照示例写的,

具体写法: $uri = 'https://api.trongrid.io';// mainnet // $uri = 'https://api.shasta.trongrid.io';// shasta testnet $api = new \Tron\Api(new Client(['base_uri' => $uri])); $config = [ 'contract_address' => 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',// USDT TRC20 'decimals' => 6, ]; $trxWallet = new \Tron\TRX($api); $addressData = $trxWallet->generateAddress(); //$trc20Wallet = new \Tron\TRC20($api, $config); //$addressData = $trc20Wallet->generateAddress();

new \Tron\TRX 和 new \Tron\TRC20 报错是同样的;

扩展包也卸载过,重新安装过,同样的报错;使用的是laravel框架 请指示一下,谢谢;

mgx888 commented 3 years ago

不好意思,是PHP环境的问题,我按照扩展包和运行PHP不是同一个环境;现在正常了