Python HTTP for Humans.
Project description
cngn-python-library
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.
Table of Contents
- Installation
- Usage
- Available Methods
- Testing
- Error Handling
- Types
- Security
- Contributing
- Support
- License
Installation
To install CNGnManager and its dependencies, run:
pip install cngn-manager
Usage
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)
Networks
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
Available Methods
cNGNManager Methods
Get Balance
balance = manager.get_balance()
print(balance)
Get Transaction History
page = 1
limit = 10
transactions = manager.get_transaction_history(page, limit)
print(transactions)
Withdraw from chains
withdraw_params = {
"amount": 100,
"address": "0x1234...",
"network": Network.BSC,
"shouldSaveAddress": True
}
withdraw_result = manager.withdraw(withdraw_params)
print(withdraw_result)
Verify Withdrawal Reference
tnxRef = '123-456-789-789405'
verify_result = manager.verify_withdrawal(withdraw_params)
print(verify_result)
Redeem Asset
deposit_params = {
"amount": 1000,
"bankCode": "123",
"accountNumber": "1234567890",
"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 ther codes
Create Virtual Account
mint_params = {
"provider": ProviderType.KORAPAY,
"bank_code": '011'
}
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 Asset
swap_data = {
"destinationNetwork": Network.BSC,
"destinationAddress": '0x123...',
"originNetwork": Network.ETH,
"callbackUrl": 'https://your-callback-url.com' // optional
}
swap_result = manager.swap_asset(swap_data)
print(swap_result)
NOTE: before creating the virtual account you need to have updated your BVN on the dashboard
Update Business
Address Options:
- "xbnAddress": "string";
- "bscAddress": "string";
- "atcAddress": "string";
- "polygonAddress": "string";
- "ethAddress": "string";
- "tronAddress": "string";
- "baseAddress": "string";
- "bantuUserId": "string";
updateData = {
"walletAddress": {
"bscAddress": "0x1234...",
#other chain addresses...
},
"bankDetails": {
"bankName": 'Test Bank',
"bankAccountName": 'Test Account',
"bankAccountNumber": '1234567890'
}
}
updateResult = manager.update_external_accounts(updateData)
print(updateResult)
Get banks
banklist = manager.get_banks()
print(banklist)
WalletManager Methods
Generate Wallet Address
wallet = WalletManager.generate_wallet_address(Network.bsc);
Response format:
{
"mnemonic" : "string";
"address": "string";
"network": Network;
"privateKey": "string";
}
Testing
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.
Test Structure
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
Error Handling
The library uses a custom error handling mechanism. All API errors are caught and thrown as Error objects with descriptive messages.
Constants
The library includes python constant classes for all parameters:
Network- token networkAssetType- Asset constantsProviderType- provider constants
Security
- Uses AES encryption for request data
- Implements Ed25519 decryption for responses
- Requires secure storage of API credentials
Contributing
To contribute:
- Fork the repository
- Create a feature branch
- Commit your changes
- Create a Pull Request
Support
For support, please:
- Open an issue in the GitHub repository
- Check existing documentation
- Contact the support team
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cngn_manager-1.0.3.tar.gz.
File metadata
- Download URL: cngn_manager-1.0.3.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee4a5da38229ba4bfd277b3c4182a131ddf84b178218b8ed071f59d964d65c68
|
|
| MD5 |
6956563e4ae11a5ddd38bfe2427f818a
|
|
| BLAKE2b-256 |
39f162d26630a4e8de03f25742e7b95b04f8573ceb6e9468b090230866dd16ac
|
File details
Details for the file cngn_manager-1.0.3-py3-none-any.whl.
File metadata
- Download URL: cngn_manager-1.0.3-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f42ed8a28b9c13f4fb278f75eb1142087817962efca157c9ee3d05897385d12
|
|
| MD5 |
e775ef4f93a898d5dd3b0efe3e4c63b7
|
|
| BLAKE2b-256 |
9ddb2d912cc95a1f08a54d4f94a463779a7e5f50a44da71e56674772646049b2
|