PHP code example of circularprotocol / circular-enterprise-apis
1. Go to this page and download the library: Download circularprotocol/circular-enterprise-apis 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/ */
circularprotocol / circular-enterprise-apis example snippets
use Circularprotocol\Circularenterpriseapis\CEP_Account;
$account = new CEP_Account();
$account->open('a4fc8b11bfc5dc2911ab41871e6de81f500fe60f3961343b202ad78e7e297ea08');
echo "Account opened successfully.\n";
$blockchain = 'blockchain-address';
$account->setNetwork("testnet"); // chose between multiple networks such as testnet, devnet and mainnet
$account->setBlockchain($blockchain);
if($account->updateAccount()){
//...
}
$pdata = 'Your data to certify';
$privateKey = 'your_private_key_here';
try {
$response = $account->submitCertificate($pdata, $privateKey);
print_r($response);
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
//...
$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";
}
//...
e_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";
}
bash
git clone https://github.com/circular-protocol/circular-php.git
cd circular-enterprise-apis