CNGnManager is a Python 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:
pip install cngn-manager
First, import the CNGnManager
WalletManager
class using and all necessary constants.
from cngn_manager import CNGnManager, WalletManager, Network, ProviderType, AssetType
Then, create an instance of CNGnManager
with your secrets:
import os
api_key = "cngn_live_sk**********"
encryption_key = "yourencryptionkey"
ssh_private_key = """-----BEGIN OPENSSH PRIVATE KEY-----
your ssh key
-----END OPENSSH PRIVATE KEY-----"""
# NOTE: You can also get your private key from a file using
# ssh_private_key = os.open("/path/to/sshkey.key").read()
manager = CNGnManager(api_key, ssh_private_key, encryption_key)
# Example: Get balance
balance = manager.get_balance()
print(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.get_balance()
print(balance)
page = 1 #page
limit = 10 #limit
transactions = manager.get_transaction_history(page, limit)
print(transactions)
withdraw_params = {
"amount": 100, # amount
"address": "0x1234...", # address
"network": Network.BSC, # network
"shouldSaveAddress": True
}
withdraw_result = manager.withdraw(withdraw_params)
print(withdraw_result)
tnxRef = '123-456-789-789405' # Transaction Ref
verify_result = manager.verify_withdrawal(withdraw_params)
print(verify_result)
deposit_params = {
"amount": 1000, # Amount
"bankCode": "123", # bankCode
"accountNumber": "1234567890", # Account Number
"saveDetails": True
}
deposit_result = manager.redeem_assets(deposit_params)
print(deposit_result)
NOTE: to get bank codes please use the getBanks method to fetch the list of banks and their codes
mint_params = {
"provider": ProviderType.KORAPAY, # provider
"bank_code": '011' # bank_code
}
virtual_account = manager.create_virtual_account(mint_params)
print(virtual_account)
NOTE: before creating the virtual account you need to have updated your BVN on the dashboard
swap_data = {
"destinationNetwork": Network.BSC, #destinationNetwork
"destinationAddress": '0x123...', # destinationAddress
"originNetwork": Network.ETH, # originNetwork
"callbackUrl": 'https://your-callback-url.com' # optional
}
swap_result = manager.swap_asset(swap_data)
print(swap_result)
swap_data = {
"destinationNetwork": Network.BSC, #destinationNetwork
"destinationAddress": '0x123...', # destinationAddress
"originNetwork": Network.ETH, # originNetwork
"amount": 1000
}
swap_result = manager.swap_quote(swap_data)
print(swap_result)
Address Options:
- "xbnAddress": "string";
- "bscAddress": "string";
- "atcAddress": "string";
- "polygonAddress": "string";
- "ethAddress": "string";
- "tronAddress": "string";
- "baseAddress": "string";
- "bantuUserId": "string";
updateData = {
"walletAddress": {
"bscAddress": "0x1234...", #bscAddress
#other chain addresses...
},
"bankDetails": {
"bankName": 'Test Bank', # bankName
"bankAccountName": 'Test Account', #bankAccountName
"bankAccountNumber": '1234567890' # bankAccountNumber
}
}
updateResult = manager.update_external_accounts(updateData)
print(updateResult)
banklist = manager.get_banks()
print(banklist)
wallet = WalletManager.generate_wallet_address(Network.bsc);
Response format:
{
"mnemonic" : "string";
"address": "string";
"network": Network;
"privateKey": "string";
}
This project uses Jest for testing. To run the tests, follow these steps:
- Run the test command:
python3 -m unittest discover tests
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
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
- Uses AES encryption for request data
- Implements Ed25519 decryption for responses
- Requires secure storage of API credentials
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