PHP code example of chainup-waas / sdk

1. Go to this page and download the library: Download chainup-waas/sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chainup-waas / sdk example snippets



Chainup\Waas\Custody\WaasClient;

// Create client using Builder pattern
$client = WaasClient::newBuilder()
    ->setHost('https://openapi.chainup.com')
    ->setAppId('your-app-id')
    ->setPrivateKey('your-private-key')
    ->setPublicKey('chainup-public-key')
    ->setDebug(true)  // Optional: enable debug mode
    ->build();

// Get UserApi instance
$userApi = $client->getUserApi();

// Register user by email
$result = $userApi->registerEmailUser('[email protected]');
if ($result->isSuccess()) {
    echo "User UID: " . $result->getData()['uid'];
} else {
    echo "Error: " . $result->getMsg();
}

$accountApi = $client->getAccountApi();

// Get user balance
$result = $accountApi->getUserAccount(12345, 'BTC');
if ($result->isSuccess()) {
    $balance = $result->getData()['balance'];
    echo "Balance: {$balance} BTC";
}

$billingApi = $client->getBillingApi();

// Create withdrawal
$result = $billingApi->withdraw(
    'withdraw_001',   // request_id (unique)
    12345,            // from_uid
    '0x1234...',      // to_address
    '1.5',            // amount
    'ETH'             // symbol
);

$asyncNotifyApi = $client->getAsyncNotifyApi();

// Decrypt notification callback data
$encryptedData = $_POST['data']; // From WaaS callback
$notifyData = $asyncNotifyApi->notifyRequest($encryptedData);
if ($notifyData !== null) {
    echo "Notification type: " . $notifyData['side']; // 'deposit' or 'withdraw'
    // Process the notification
}

// Decrypt withdrawal verification request
$verifyData = $asyncNotifyApi->verifyRequest($encryptedVerifyData);

// Encrypt withdrawal verification response
$response = $asyncNotifyApi->verifyResponse(array(
    'request_id' => 'xxx',
    'status' => 1  // 1=approve, 2=reject
));


Chainup\Waas\Mpc\MpcClient;

// Create MPC client using Builder pattern
$mpcClient = MpcClient::newBuilder()
    ->setDomain('https://openapi.chainup.com')
    ->setAppId('your-app-id')
    ->setRsaPrivateKey('your-rsa-private-key')
    ->setWaasPublicKey('chainup-public-key')
    ->setSignPrivateKey('your-sign-private-key')  // For transaction signing
    ->setDebug(false)
    ->build();

// Get WalletApi instance
$walletApi = $mpcClient->getWalletApi();

// Create wallet
$result = $walletApi->createWallet(array(
    'sub_wallet_name' => 'My Wallet',
    'app_show_status' => 1
));

if ($result->isSuccess()) {
    echo "Wallet ID: " . $result->getData()['sub_wallet_id'];
} else {
    echo "Error: " . $result->getMsg();
}

$withdrawApi = $mpcClient->getWithdrawApi();

// Withdraw cryptocurrency
$result = $withdrawApi->withdraw(array(
    'request_id' => 'withdraw_' . time(),
    'sub_wallet_id' => 123456,
    'symbol' => 'USDT',
    'amount' => '10.5',
    'address_to' => '0x1234...'
));

if ($result->isSuccess()) {
    echo "Transaction ID: " . $result->getData()['txid'];
}

$web3Api = $mpcClient->getWeb3Api();

// Execute smart contract transaction
$result = $web3Api->createWeb3Trans(array(
    'request_id' => 'web3_' . time(),
    'sub_wallet_id' => 123456,
    'main_chain_symbol' => 'ETH',
    'interactive_contract' => '0xabc...',
    'trans_type' => 1,
    'amount' => '0',
    'input_data' => '0x...'
));

use chainup\waas\client\Config;
use chainup\waas\client\WaasClient;

$config = new Config();
$config->setAppid($appId);
$config->setDomain($domain);
$config->setUserPrivateKey($privateKey);
$config->setWaasPublicKey($publicKey);

$client = new WaasClient($config);
$result = $client->CreateEmailUser($email);

use Chainup\Waas\Custody\WaasClient;

$client = WaasClient::newBuilder()
    ->setHost($host)
    ->setAppId($appId)
    ->setPrivateKey($privateKey)
    ->setPublicKey($publicKey)
    ->build();

$result = $client->getUserApi()->registerEmailUser($email);
bash
git clone https://github.com/HiCoinCom/php-sdk.git
cd php-sdk
composer install