https://github.com/reactmore/chainshub-api-wrapper
https://github.com/reactmore/chainshub-api-wrapper
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/reactmore/chainshub-api-wrapper
- Owner: reactmore
- License: mit
- Created: 2024-07-08T19:47:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-09T07:28:09.000Z (over 1 year ago)
- Last Synced: 2025-01-26T13:29:07.574Z (about 1 year ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chainshub-api-wrapper
# Installation
```bash
composer require reactmore/chainshub-api-wrapper
```
# Coin Api Wrapper
| Coin | Status |
|---|---|
| `Tron` | OK |
| `Doge` | Not Yet |
| `BSC` | Not Yet |
| `ETC` | Not Yet |
| `LTC` | Not Yet |
| `DASH` | Not Yet |
# Calling Coin Method
$api->{CoinName}_{{MethodName}}();
ex:
```php
$api->tron_generateAddress();
$api->tron_getBalance();
$api->tron_transfer();
etc....
```
# Example Usage Coin Method
Load package
```php
load();
}
// Define Your API Key and Merchant Private Key
$apiKey = $_ENV['API_KEY'] ?? 'your-api-key-here';
$merchantPrivateKey = $_ENV['MERCHANT_PRIVATE_KEY'] ?? 'your-merchant-private-key';
// Initialize the ChainshubApi class
$api = new ChainshubApi($apiKey, $merchantPrivateKey);
```
Generate Address
```php
$api = new ChainshubApi($apiKey, $merchantPrivateKey);
// Generate a new address
try {
$generateAddressParams = ['network' => 'mainnet'];
$generateAddressResponse = $api->tron_generateAddress($generateAddressParams);
echo "Generate Address Response:\n";
print_r($generateAddressResponse);
} catch (Exception $e) {
echo "Error generating address: " . $e->getMessage() . "\n";
}
```
Check Balance
```php
$api = new ChainshubApi($apiKey, $merchantPrivateKey);
// Check balance
try {
$balanceParams = [
'network' => 'mainnet',
'address' => 'your-tron-address-here'
];
$balanceResponse = $api->tron_getBalance($balanceParams);
echo "Balance Response:\n";
print_r($balanceResponse);
} catch (Exception $e) {
echo "Error checking balance: " . $e->getMessage() . "\n";
}
```
Transfer Coin
```php
$api = new ChainshubApi($apiKey, $merchantPrivateKey);
// Transfer coins
try {
$transferParams = [
'network' => 'mainnet',
'from_address' => 'your-tron-address-here',
'amount' => 5,
'to_address' => 'destination-tron-address-here',
'private_key' => 'your-private-key-here'
];
$transferResponse = $api->tron_transfer($transferParams);
echo "Transfer Response:\n";
print_r($transferResponse);
} catch (Exception $e) {
echo "Error transferring coins: " . $e->getMessage() . "\n";
}
```
# Example Merchant Transactions
Create Invoice:
```php
// Create an invoice
try {
$invoiceParams = [
'currency' => 'bsc',
'merchant_ref' => 'INVOICE-001',
'customer_email' => 'customer@gmail.com',
'customer_name' => 'James Bond',
'pair' => 'idr',
'redirect_url' => 'https://yourwebsite.com/callback=success',
'cancel_url' => 'https://yourwebsite.com/callback=failed',
'amount' => '10000'
];
$invoiceResponse = $api->createInvoice($invoiceParams);
echo "Create Invoice Response:\n";
print_r($invoiceResponse);
} catch (Exception $e) {
echo "Error creating invoice: " . $e->getMessage() . "\n";
}
```
Handle Callback:
```php
// Handle callback
try {
$postData = file_get_contents('php://input');
$headers = getallheaders();
$callbackResponse = $api->handleCallback($postData, $headers);
echo "Callback Response:\n";
print_r($callbackResponse);
} catch (Exception $e) {
echo "Error handling callback: " . $e->getMessage() . "\n";
}
```