1. Go to this page and download the library: Download onematrix/tracing-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
onematrix / tracing-sdk example snippets
use Tracing\Sdk\SendOptions;
use Tracing\Sdk\TracingSDK;
$sdk = new TracingSDK([
'endpoint' => 'https://indexer.example.com',
'options' => SendOptions::dataType('json'), // default: 'json' | 'xml' | 'raw'
'auth' => [
'type' => 'apiToken', // 'mTLS' | 'basic' | 'apiToken'
'token' => 'your-api-token',
],
]);
// Send one record: canonicalize + hash + POST {endpoint}/api/anchors
$result = $sdk->send($rawJsonOrXml, $signingTime);
// ['hash' => '0x1c8a…', 'response' => ['statusCode' => 200, 'body' => …, 'recordCount' => 1]]
// Or send several together: POST {endpoint}/api/anchors/batch
$results = $sdk->sendBatch([
['rawData' => $rawA, 'signingTime' => $signingTimeA],
['rawData' => $rawB, 'signingTime' => $signingTimeB],
]);
// [['hash' => '0xaaa…', 'response' => […]], ['hash' => '0xbbb…', 'response' => […]]]
// Look up an already-anchored record by its hash.
$anchor = $sdk->queryByHash($result['hash']); // GET {endpoint}/api/anchors?hash=...
echo $anchor['txHashes'][0];
use Tracing\Sdk\SendOptions;
// Uses the config default.
$sdk->send($rawJson, $signingTime);
// Overrides it for this call only.
$sdk->send($rawXml, $signingTime, SendOptions::dataType('xml'));
$sdk->sendBatch($xmlRecords, SendOptions::dataType('xml'));
use Tracing\Sdk\Exception\TransportException;
try {
$anchor = $sdk->queryByHash('0x1c8a…');
// ['hash' => '0x1c8a…', 'txHashes' => ['0x9f42…', '0x3b07…']]
} catch (TransportException $e) {
// Not yet anchored, unknown hash, or the Indexer was unreachable.
echo $e->getMessage();
}