Skip to main content

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

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 Chain
  • Network.ATC - Asset Chain
  • Network.XBN - Bantu Chain
  • Network.ETTH - Ethereum
  • Network.MATIC - Polygon (Matic)
  • Network.TRX - Tron
  • Network.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:

  1. 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 network
  • AssetType - Asset constants
  • ProviderType - provider constants

Security

  • Uses AES encryption for request data
  • Implements Ed25519 decryption for responses
  • Requires secure storage of API credentials

Contributing

To contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Create a Pull Request

Support

For support, please:

  • Open an issue in the GitHub repository
  • Check existing documentation
  • Contact the support team

License

MIT

Metadata

Release files for cngn-manager 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cngn-manager 1.0.3
File Size Uploaded Provenance Actions
cngn_manager-1.0.3.tar.gz 12.3 kB Without provenance Details for cngn_manager-1.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cngn-manager 1.0.3
File Interpreter ABI Platform Actions
cngn_manager-1.0.3-py3-none-any.whl Python 3 none any Details for cngn_manager-1.0.3-py3-none-any.whl

Total release size: 24.2 kB

Release files / cngn_manager-1.0.3.tar.gz

Download URL cngn_manager-1.0.3.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ee4a5da38229ba4bfd277b3c4182a131ddf84b178218b8ed071f59d964d65c68
BLAKE2b-256 checksum
How to use checksums
39f162d26630a4e8de03f25742e7b95b04f8573ceb6e9468b090230866dd16ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / cngn_manager-1.0.3-py3-none-any.whl

Download URL cngn_manager-1.0.3-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f42ed8a28b9c13f4fb278f75eb1142087817962efca157c9ee3d05897385d12
BLAKE2b-256 checksum
How to use checksums
9ddb2d912cc95a1f08a54d4f94a463779a7e5f50a44da71e56674772646049b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Security for cngn-manager 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page