PHP code example of reinaldomendes / changelly-json-rpc

1. Go to this page and download the library: Download reinaldomendes/changelly-json-rpc 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/ */

    

reinaldomendes / changelly-json-rpc example snippets


use Rbm\Changelly\JsonRpc\Factory as ApiFactory;
$apiFactory = new ApiFactory();
$factoryOptions = [];
$api = $apiFactory->factory($factoryOptions);


$btcAddressHash = "1TARXpabecedehdjdhsjwhduerr";
$id = "ONE_IDENTIFIER";
$params = [  
];
$response = $api->getCurrencies($id,$params); // {'id':'ONE_IDENTIFIER',....}
//or
$response = $api->getCurrencies($params);// {'id':'Rbm_xxxxxx',....}


$btcAddressHash = "1TARXpabecedehdjdhsjwhduerr";
$id = "ONE_IDENTIFIER";
$params = [
    "from" => "ltc",
    "to" => "btc",
    "address" => $btcAddressHash,
    "extraId" => null,
    "amount" => 1
];

$response = $api->createTransaction($id,$params);

      use Rbm\Changelly\JsonRpc\Factory as ApiFactory;
      $apiFactory = new ApiFactory();
      $apiFactory->factory([
        'config' => 'env' // Rbm\Changelly\JsonRpc\Config\Env - this is the default behavior
      ]);      
   

   namespace MyOwnConfig{
     use Rbm\Changelly\JsonRpc\Contracts\Config as ConfigContract;
     class config implements ConfigContract{
       public function getApiKey(){
         //... do something
         return $myApiKey;
       }
       public function getApiSecret(){
         //... do something
         return $myApiSecret;
       }
     }
   }
   ////
   ////

   use Rbm\Changelly\JsonRpc\Factory as ApiFactory;
   $apiFactory = new ApiFactory();
   $apiFactory->factory([
     'config' => MyOwnConfig\Config::class
   ]);      

  use Rbm\Changelly\JsonRpc\Factory as ApiFactory;
  $apiFactory = new ApiFactory();
  $apiFactory->factory([
    'driver' => 'v2' // Rbm\Changelly\JsonRpc\Driver\V2 - this is the default behavior
  ]);      
bash
 export CHANGELLY_API_KEY='myapikey';
 export CHANGELLY_API_SECRET='myscret';