cngn-java-library is a Java library for interacting with the cNGN API. It provides a simple interface for various operations such as checking balance, swapping between chains, depositing for redemption, creating virtual accounts, generating wallet addresses, and more.
- Installation
- Usage
- Networks
- Available Methods
- Testing
- Error Handling
- Types
- Security
- Contributing
- Support
- License
To install cngn-java-library and its dependencies:
Add the following dependency to your pom.xml
if using Maven:
<dependency>
<groupId>com.cngn</groupId>
<artifactId>cngn-java-library</artifactId>
<version>1.0.0</version>
</dependency>
Or in your build.gradle
if using Gradle:
implementation 'com.cngn:cngn-java-library:1.0.0'
First, import the necessary classes:
import com.cngn.CNGNManager;
import com.cngn.WalletManager;
import com.cngn.models.Secrets;
import com.cngn.models.SwapParams;
import com.cngn.models.DepositParams;
import com.cngn.models.MintParams;
import com.cngn.models.WhiteListAddressParams;
import com.cngn.enums.Network;
import org.json.JSONObject;
import org.json.JSONArray;
Then, create an instance of CNGNManager
with your secrets:
Secrets secrets = new Secrets(
"your-api-key",
"your-private-key",
"your-encryption-key"
);
CNGNManager manager = new CNGNManager(secrets);
// Example: Get balance
JSONArray balance = manager.getBalance();
System.out.println(balance);
The library supports multiple blockchain networks, grouped by their underlying chain technology:
Network.BSC
- Binance Smart Chain MainnetNetwork.ATC
- Asset ChainNetwork.ETH
- Ethereum MainnetNetwork.MATIC
- Polygon (Previously Matic)Network.base
- Base
Network.XBN
- XBN Chain
Network.TRX
- Tron Mainnet
Usage example with different chain types:
// For EVM chain operations (BSC, ATC, ETH, MATIC)
SwapParams evmSwapParams = new SwapParams(
100, // amount
"0x1234...", // EVM-compatible address
Network.BSC // Network.base, Network.ATC, Network.ETH, Network.MATIC
);
// For Bantu (XBN) operations
SwapParams xbnSwapParams = new SwapParams(
100, // amount
"G....", // Stellar-compatible address
Network.XBN
);
// For Tron operations
SwapParams tronSwapParams = new SwapParams(
100, // amount
"T....", // Tron address format
Network.TRX
);
JSONArray balance = manager.getBalance();
System.out.println(balance);
TransactionParams transactionParams = new TransactionParams(
1, //page
2 //limit
);
System.out.println("Fetch Transaction History : " + cngnManager.getTransactionHistory(transactionParams));
SwapParams swapParams = new SwapParams(
100, // amount
"0x1234...", // address
Network.BSC // network
);
JSONObject swapResult = manager.swapBetweenChains(swapParams);
System.out.println(swapResult);
CreateVirtualParams mintParams = new CreateVirtualParams(
"korapay", //provider
"123" //bankCode
);
JSONObject virtualAccount = manager.createVirtualAccount(mintParams);
System.out.println(virtualAccount);
RedeemAssetParams redeemAssetParams = new RedeemAssetParams(
1000, //amount
"123", //bankCode
"1234567890", //accountNumber
true //saveDetails
);
System.out.println("Redeem Assets : " + cngnManger.redeemAssets(redeemAssetParams));
UpdateExternalAccountParams updateExternalAccountParams = new UpdateExternalAccountParams();
updateExternalAccountParams.addWalletAddress("bscAddress", "0xB4............");
updateExternalAccountParams.updateBankDetails( "Test Bank",
"Example account",
"1234567890");
System.out.println("Update External Accounts " + cngnManager.updateExternalAccounts(updateExternalAccountParams));
IWithdrawParams withdrawParams = new IWithdrawParams(
1000, //amount
"0x789...", //address
Network.BSC, //network
true //shouldSaveAddress
);
System.out.println("Withdraw : " + cngnManager.withdraw(withdrawParams));
System.out.println("Withdraw : " + cngnManager.verifyWithdrawalReference(
"123-456-789-789405" //Transaction Reference
));
System.out.println("Get Banks : " + cngnManger.getBanks());
The generateWalletAddress
method creates a new wallet address for any supported network. Each network type returns addresses in its native format.
// EVM Chains (returns 0x-prefixed addresses)
JSONObject bscWallet = WalletManager.generateWalletAddress(Network.BSC); // BSC address
JSONObject ethWallet = WalletManager.generateWalletAddress(Network.ETH); // Ethereum address
JSONObject maticWallet = WalletManager.generateWalletAddress(Network.MATIC); // Polygon address
JSONObject atcWallet = WalletManager.generateWalletAddress(Network.ATC); // Asset Chain address
// Bantu/Stellar-based Chain (returns G-prefixed addresses)
JSONObject xbnWallet = WalletManager.generateWalletAddress(Network.XBN); // XBN address
// Tron Chain (returns T-prefixed addresses)
JSONObject tronWallet = WalletManager.generateWalletAddress(Network.TRX); // Tron address
The response format for each generated wallet:
public class WalletResponse {
private String address; // The public address for the wallet
private Network network; // The network this wallet is for
private String mnemonic; // 12-word recovery phrase
private String privateKey; // Private key for the wallet
}
Example response:
// EVM wallet response
{
"address": "0x71C7656EC7ab88b098defB751B7401B5f6d8976F",
"network": "ETH",
"mnemonic": "width craft decide...",
"privateKey": "0x..."
}
// XBN wallet response
{
"address": "GBXYZABC...",
"network": "XBN",
"mnemonic": "width craft decide...",
"privateKey": "S..."
}
// Tron wallet response
{
"address": "TRxYZABC...",
"network": "TRX",
"mnemonic": "width craft decide...",
"privateKey": "..."
}
Note: Each network type has its own address format:
- EVM chains (BSC, ETH, MATIC, ATC):
0x
-prefixed addresses - Bantu/XBN:
G
-prefixed addresses (Stellar format) - Tron:
T
-prefixed addresses
This project uses JUnit for testing. To run the tests, follow these steps:
-
Run the test command:
mvn test
This will run all tests in the
src/test/java
directory.
The tests are located in the src/test/java
directory. They cover various aspects of the CNGNManager and WalletManager classes, including:
- API calls for different endpoints (GET and POST requests)
- Encryption and decryption of data
- Error handling for various scenarios
- Wallet address generation for different networks
The library uses a custom error handling mechanism. All API errors are caught and thrown as CNGNException
objects with descriptive messages.
The library includes Java classes and interfaces for all parameters and return types. All models are defined in the com.cngn.models
package for easy reference and maintenance.
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.
If you have any questions or need help using the library, please open an issue in the GitHub repository.