# PHP

### Overview

The **Circular Enterprise APIs** provide a powerful and efficient way to **certify data on the blockchain**, ensuring immutability, transparency, and security. These APIs facilitate **account management, network configuration, data signing, and transaction monitoring**, making it easier for enterprises to integrate blockchain-based certification into their workflows.

This library is designed for developers who need to verify, sign, and submit **data certificates** using the **Circular blockchain** while maintaining seamless integration with **PHP applications**.

### Installation

You can install the **Circular Enterprise APIs** via **npm**:

```bash
composer require circularprotocol/circular-enterprise-apis
```

### Usage example

```php
<?php

require_once __DIR__ . "/vendor/autoload.php"; // IF NEEDED
require_once __DIR__ . "/src/CircularEnterpriseAPIS-php"; // IF NEEDED

use Circularprotocol\Circularenterpriseapis\CEP_Account;

try {
    // Instantiate the CEP Account class
    $account = new CEP_Account();
    echo "CEP_Account instantiated successfully.\n";

    $address = "your-account-address";
    $pk = "your-private-key"; // Note: pk should be a string, not a hex literal
    $blockchain = "blockchain-address"; // Same here, string.
    $txID = ""; // Initialize txID
    $txBlock = ""; // Initialize txBlock

    $account->setNetwork("testnet"); // chose between multiple networks such as testnet, devnet and mainnet
    $account->setBlockchain($blockchain);
    echo "Test variables set.\n";

    if ($account->open($address)) {
        echo "Account opened successfully.\n";

        if ($account->updateAccount()) {
            echo "Nonce: " . $account->Nonce . "\n";

            $txIDTemp = $account->submitCertificate(
                "your-data-to-certificate",
                "1de4fc4d951349a382c9ca58e6c82feeed8a233657683455080338675ad7e61f"
            );
            if ($txIDTemp["Result"] == 200) {
                $txID = $txIDTemp["Response"]["TxID"];
                echo "TxID: " . $txID . "\n";

                $resp = $account->getTransactionOutcome($txID, 10);
                if ($resp["BlockID"]) {
                    $blockID = $resp["BlockID"];
                    $status = $account->getTransaction($blockID, $txID);

                    if ($status == 200) {
                        echo "Transaction Status: " .
                            $status["Response"]["Status"] .
                            "\n";

                        $account->close();
                    } else {
                        echo "Error on retrieving transaction";
                    }
                } else {
                    echo "Error on retrieving transaction status";
                }
            } else {
                echo "Certificate submission error";
            }
        } else {
            echo "Update Account Error: " . $account->lastError . "\n";
        }
    } else {
        echo "Failed to open account: " . $account->lastError . "\n";
    }
} catch (Exception $e) {
    echo "An error occurred: " . $e->getMessage() . "\n";
}

?>
```

### Useful Links

You can find more on the [official GitHub repository](https://github.com/circular-protocol/PHP-Enterprise-APIs) or on the [official Packagist repository](https://packagist.org/packages/circularprotocol/circular-enterprise-apis).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://circular-protocol.gitbook.io/circular-enterprise-apis/php.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
