Jump to content

Quick question regarding the api I am using. It's giving me syntax error.


Go to solution Solved by imgrooot,

Recommended Posts

I am using this API https://github.com/blocktrail/blocktrail-sdk-php.

 

I am suppose to add this to top of my directory where I want to initialize the API. 

require 'vendor/autoload.php';
use Blocktrail\SDK\BlocktrailSDK;

But the second line gives me an error.

use Blocktrail\SDK\BlocktrailSDK;

Parse error: syntax error, unexpected 'use' (T_USE) in C:\xampp\htdocs\site\templates\header.php on line 12

Is the "use" a correct syntax for php? Why is it giving me an error?

I actually did tried this on a test page outside of the normal site and it gives me this error. I'm pretty sure I installed it correctly using composer. 

Fatal error: Uncaught Blocktrail\SDK\Connection\Exceptions\ObjectNotFound: The object you've tried to access does not exist. in C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php:336 Stack trace: #0 C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php(306): Blocktrail\SDK\Connection\RestClient->responseHandler(Object(GuzzleHttp\Psr7\Response)) #1 C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php(173): Blocktrail\SDK\Connection\RestClient->request('GET', 'address/1NcXPMR...', NULL, NULL, NULL, NULL, NULL) #2 C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\BlocktrailSDK.php(162): Blocktrail\SDK\Connection\RestClient->get('address/1NcXPMR...') #3 C:\xampp\htdocs\gift\test.php(28): Blocktrail\SDK\BlocktrailSDK->address('1NcXPMRaanz43b1...') #4 {main} thrown in C:\xampp\htdocs\site\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php on line 336

We know what line 12 is. We want to know what lines 1-11 are.

 

Other files like

 

include init.php

include_once 'metas.php';
include_once 'analyticstracking.php';
 
and so on. They are non related to the API.

Dude. The syntax error isn't in line 12, it's in one of the lines before that. If you want help with a syntax problem, then we need to actually see the exact code, not an “and so on” placeholder. Is this really so hard to understand?

 

Anyway, apparently you've repaired your secret code now. The new error is an interal library exception. Read the source code to understand why it's happening.

Dude. The syntax error isn't in line 12, it's in one of the lines before that. If you want help with a syntax problem, then we need to actually see the exact code, not an “and so on” placeholder. Is this really so hard to understand?

 

Anyway, apparently you've repaired your secret code now. The new error is an interal library exception. Read the source code to understand why it's happening.

 

The error says invalid credentials, I assume it means my API key.  I double checked it and it's the correct key.

 

I am testing it on a test.php page with this code .

require_once 'composer/vendor/autoload.php';

use \Blocktrail\SDK\BlocktrailSDK;
$client = new BlocktrailSDK("0012a34a76bf10cf01c53d0c6059fc84a22f8e9d", "22250773dfde8f4ed0a0252a299549e9c024b132", "BTC", true /* testnet */);

$address = $client->address('1NcXPMRaanz43b1kokpPuYDdk6GGDvxT2T');
$latestBlock = $client->blockLatest();

var_dump($address['balance'], $latestBlock['hash']);

And this is the error i receive.

Fatal error: Uncaught Blocktrail\SDK\Connection\Exceptions\ObjectNotFound: The object you've tried to access does not exist. in C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php:336 Stack trace: #0 C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php(306): Blocktrail\SDK\Connection\RestClient->responseHandler(Object(GuzzleHttp\Psr7\Response)) #1 C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php(173): Blocktrail\SDK\Connection\RestClient->request('GET', 'address/1NcXPMR...', NULL, NULL, NULL, NULL, NULL) #2 C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\BlocktrailSDK.php(162): Blocktrail\SDK\Connection\RestClient->get('address/1NcXPMR...') #3 C:\xampp\htdocs\gift\test.php(7): Blocktrail\SDK\BlocktrailSDK->address('1NcXPMRaanz43b1...') #4 {main} thrown in C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php on line 336
Edited by imgrooot
  • Solution

Alright so I figured out why it was giving me that error. 

 

The reason I was getting the above error was because the wallet address I had in the call was EMPTY. It had no transactions sent or received so it was returning the default error.  All I have to do now is set up my own custom error if the wallet is empty.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.