CNGnManager is a PHP library for interacting with a CNGN API. It provides a simple interface for various operations such as checking balance, swapping between chains, depositing for redemption, creating virtual accounts, and more.
- Installation
- Usage
- Available Methods
- Testing
- Error Handling
- Types
- Security
- Contributing
- Support
- License
To install CNGnManager and its dependencies, run:
composer require wrappedcbdc/cngn-php-library
First, import the CNGnManager
class using it namespace WrappedCBDC\CNGNManager: and all necessary constants.
<?php declare(strict_types=1);
require __DIR__ ."/vendor/autoload.php";
use WrappedCBDC\CNGnManager;
use WrappedCBDC\constants\{Network, ProviderType};
Then, create an instance of CNGnManager
with your secrets:
$apiKey = "cngn_live_sk**********";
$encryptionKey = "yourencryptionkey";
$sshPrivateKey = "-----BEGIN OPENSSH PRIVATE KEY-----
your ssh key
-----END OPENSSH PRIVATE KEY-----";
#NOTE: You can as well get your private key from a file using
$sshPrivateKey = file_get_contents("/path/to/sshkey.key");
$manager = new CNGnManager($apiKey, $sshPrivateKey, $encryptionKey);
// Example: Get balance
$balance = $manager->getBalance();
echo $balance;
The library supports multiple blockchain networks:
Network.BSC
- Binance Smart ChainNetwork.ATC
- Asset ChainNetwork.XBN
- Bantu ChainNetwork.ETTH
- EthereumNetwork.MATIC
- Polygon (Matic)Network.TRX
- TronNetwork.BASE
- Base
$balance = $manager->getBalance();
echo $balance;
$page = 1;
$limit = 10;
$transactions = $manager->getTransactionHistory($page, $limit);
echo $transaction;
$swapParams = [
"amount"=> 100,
"address" => '0x1234...',
"network" => Network::BSC,
"shouldSaveAddress" => true
];
$swapResult = $manager->withdraw($swapParams);
echo $swapResult;
$depositParams = [
"amount"=> 1000,
"bankCode"=> '011',
"accountNumber"=> '1234567890'
"saveDetails" => true
];
$depositResult = $manager->redeemAssets($depositParams);
echo $depositResult;
NOTE: to get bank codes please use the getBanks method to fetch the list of banks and ther codes
$mintParams = [
"provider"=> ProviderType::KORAPAY,
"bank_code" => '011'
];
$virtualAccount = $manager->createVirtualAccount($mintParams);
echo $virtualAccount;
NOTE: before creating the virtual account you need to have updated your BVN on the dashboard
$swapData = [
"destinationNetwork"=> Network::BSC,
"destinationAddress" => "0x123....",
"originNetwork" => Network::ETH
"callbackUrl" => 'https://your-callback-url.com'
];
$swapResult = $manager->swapAsset($swapData);
echo $swapResult;
NOTE: before creating the virtual account you need to have updated your BVN on the dashboard
Address Options:
- "xbnAddress": "string";
- "bscAddress": "string";
- "atcAddress": "string";
- "polygonAddress": "string";
- "ethAddress": "string";
- "tronAddress": "string";
- "baseAddress": "string";
- "bantuUserId": "string";
$updateData: [
"walletAddress" => [
"bscAddress" => '0x1234...',
],
"bankDetails" => [
"bankName" => 'Example Bank',
"bankAccountName" => 'Test Account',
"bankAccountNumber" => '1234567890'
]
];
$updateResult = $manager->updateExternalAccounts($updateData);
echo $updateResult;
$banklist = $manager->getBanks();
print($banklist)
Not Available a the moment
This project uses Jest for testing. To run the tests, follow these steps:
-
Run the test command:
composer run test
This will run all tests in the
__tests__
directory.
The tests are located in the __tests__
directory. They cover various aspects of the CNGnManager class, including:
- API calls for different endpoints (GET and POST requests)
- Encryption and decryption of data
- Error handling for various scenarios
All responses are returned as a Json string you have to decode it to an object with; $data = json_decode($response)
or to an array with; $data = json_decode($response, true)
.
The library uses a custom error handling mechanism. All API errors are caught and thrown as Error
objects with descriptive messages.
The library includes python constant classes for all parameters:
Network
- token networkAssetType
- Asset constantsProviderType
- provider constants
This library uses AES encryption for request payloads and Ed25519 decryption for response data. Ensure that your encryptionKey
and privateKey
are kept secure.
Contributions, issues, and feature requests are welcome. Feel free to check issues page if you want to contribute.
To contribute:
- Fork the repository
- Create a feature branch
- Commit your changes
- Create a Pull Request
For support, please:
- Open an issue in the GitHub repository
- Check existing documentation
- Contact the support team