Skip to content
PHP client for Factom Open API
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
FactomOpenAPI.php
LICENSE
README.md

README.md

PHP client for Factom Open API

This is PHP client for Factom Open API.

Usage

1. Require library

require_once("FactomOpenAPI.php");

2. Initialize client

$endpoint = "http://1.2.3.4:8081";
$api_key = "USER_API_KEY";
$factom = new FactomOpenAPI($endpoint, $api_key);

3. Use client to work with Factom Open API

  1. Get API info
// Get API version
$chains = $factom->getAPIInfo();
  1. Get user info
// Get user info
$user = $factom->getUser();
  1. Create a chain
// Creates chain on the Factom blockchain
$extIds[0] = "My new chain";
$extIds[1] = "Second ExtID";
$content = "Content of the first entry"; // optional
$chain = $factom->createChain($extIds, $content);
  1. Get chains
// Get all user’s chains
$chains = $factom->getChains();

// Get user's chains from 41th to 60th
$chains = $factom->getChains(40, 20);

// Get user's chains with status "queue"
// start=0, limit=0 — use defaults pagination params
// status="queue" — filter chains by status "queue" (also "processing" | "completed")
$chains = $factom->getChains(0, 0, "queue");

// Get user's chains in reverse sorting (from oldest to newest)
// start=0, limit=0 — use defaults pagination params
// status=NULL — not filter by status
// sort="asc" — sort results by createdAt ASC ("desc" is default sorting)
$chains = $factom->getChains(0, 0, NULL, "asc");

// Combine all filters and params
// start=40, limit=20, status="queue", sort="asc"
$chains = $factom->getChains(40, 20, "queue", "asc");
  1. Get chain
// Get Factom chain by Chain ID
$chainId = "fb5ad150761da70e090cb2582445681e4c13107ca863f9037eaa2947cf7d225c";
$chain = $factom->getChain($chainId);
  1. Get chain entries
// Get entries of Factom chain
$chainId = "fb5ad150761da70e090cb2582445681e4c13107ca863f9037eaa2947cf7d225c";
$entries = $factom->getChainEntries($chainId);

// Filters and params may be applied to results
// Example: start=40, limit=20, status="queue", sort="asc"
$entries = $factom->getChainEntries($chainId, 40, 20, "queue", "asc");
  1. Get first/last entry of the chain
$chainId = "fb5ad150761da70e090cb2582445681e4c13107ca863f9037eaa2947cf7d225c";

// Get first entry of Factom chain
$firstEntry = $factom->getChainFirstEntry($chainId);

// Get last entry of Factom chain
$firstEntry = $factom->getChainLastEntry($chainId);
  1. Search user's chains by external ids
// Search for chains with tag "Forum Thread"
$extIds[0] = "Forum Thread";
$chains = $factom->searchChains($extIds);

// Search for entries with 2 tags simultaneously 
$extIds[1] = "v1.0.0";
$chains2 = $factom->searchChains($extIds);

// Filters and params may be applied to results
// Example: start=40, limit=20, status="completed", sort="asc"
$chains = $factom->searchChains($extIds, 40, 20, "completed", "asc");
  1. Search chain entries by external ids
// Search entries into Factom chain by external id(s)
$chainId = "fb5ad150761da70e090cb2582445681e4c13107ca863f9037eaa2947cf7d225c";
// Search for entries with tag "Forum Post"
$extIds[0] = "Forum Post";
$entries = $factom->searchChainEntries($chainId, $extIds);

// Search for entries with 2 tags simultaneously 
$extIds[1] = "v1.0.0";
$entries2 = $factom->searchChainEntries($chainId, $extIds);

// Filters and params may be applied to results
// Example: start=40, limit=20, status="processing", sort="asc"
$entries = $factom->searchChainEntries($chainId, $extIds, 40, 20, "processing", "asc");
  1. Create an entry
// Create entry in the Factom chain
$chainId = "fb5ad150761da70e090cb2582445681e4c13107ca863f9037eaa2947cf7d225c";
$extIds[0] = "My new entry";
$extIds[1] = "Second ExtID";
$content = "Content of the new entry";
$entry = $factom->createEntry($chainId, $extIds, $content);
  1. Get entry
// Get Factom entry by EntryHash
$entryHash = "dc2160b99b5f46f156e54bdebc81aef3243884b68b2c0c05e4741910738273f2";
$entry = $factom->getEntry($entryHash);
  1. Generic factomd interface
// Example of factomd API call without params: 'heights'
$heights = $factom->factomd("heights");

// Example of factomd API call with params: 'chain-head'
// Params sent as JSON string (not object)
$params = "{\"chainid\":\"9b41e5213471aa7dc9bbb1e7107b5c0009d94cd0eb553629984fd07c7039c3db\"}";
$chainHead = $factom->factomd("chain-head", $params);
You can’t perform that action at this time.