Skip to main content

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

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)

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cngn_manager-1.0.2.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cngn_manager-1.0.2-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file cngn_manager-1.0.2.tar.gz.

File metadata

  • Download URL: cngn_manager-1.0.2.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for cngn_manager-1.0.2.tar.gz
Algorithm Hash digest
SHA256 f4c6c37aa02d1c1736d445d96766dacc66a2891cab8ec1a4675a3b412a390737
MD5 6d481a325bcf30b0f00d985e0fb5e241
BLAKE2b-256 87bbff2a525ba605bb9c930cbc2dfd150c4227be57f4bee75f85910cd063e72e

See more details on using hashes here.

File details

Details for the file cngn_manager-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: cngn_manager-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for cngn_manager-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a71e60aef6afb5999f490e7ae6b71ef08d5ba53c5127e555038f43d3ef7817e3
MD5 de7d4523d016839c1e696555f4d942bf
BLAKE2b-256 9785bad02ab3b84d7820704147fb0fbe96d94195c34f1a8d22e48132077b5f6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page