Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
serderovsh committed Nov 6, 2018
1 parent 6e704dc commit 332769b
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 36 deletions.
15 changes: 11 additions & 4 deletions examples/balance.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<?php
include_once '../vendor/autoload.php';

$tron = new \IEXBase\TronAPI\Tron();
$tron->setAddress('address');
$fullNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$solidityNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$eventServer = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');

try {
$tron = new \IEXBase\TronAPI\Tron($fullNode, $solidityNode, $eventServer);
} catch (\IEXBase\TronAPI\Exception\TronException $e) {
exit($e->getMessage());
}

$balance = $tron->getBalance();

echo $tron->fromTron($balance);
$tron->setAddress('address');
$balance = $tron->getBalance(null, true);
12 changes: 6 additions & 6 deletions examples/custom-nodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

$fullNode = new HttpProvider('https://api.trongrid.io');
$solidityNode = new HttpProvider('https://api.trongrid.io');
$eventServer = new HttpProvider('https://api.trongrid.io');
$privateKey = 'private_key';

//Example 1
$tron = new Tron($fullNode, $solidityNode, $privateKey);

//Example 2
$tron->setFullNode($fullNode);
$tron->setSolidityNode($solidityNode);
$tron->setPrivateKey($privateKey);
try {
$tron = new Tron($fullNode, $solidityNode, $eventServer, $privateKey);
} catch (\IEXBase\TronAPI\Exception\TronException $e) {
die($e->getMessage());
}
10 changes: 9 additions & 1 deletion examples/find-transaction.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<?php
include_once '../vendor/autoload.php';

$tron = new \IEXBase\TronAPI\Tron();
$fullNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$solidityNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$eventServer = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');

try {
$tron = new \IEXBase\TronAPI\Tron($fullNode, $solidityNode, $eventServer);
} catch (\IEXBase\TronAPI\Exception\TronException $e) {
exit($e->getMessage());
}

$detail = $tron->getTransaction('TxId');
var_dump($detail);
15 changes: 7 additions & 8 deletions examples/is-connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
include_once '../vendor/autoload.php';

$fullNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$solidityNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io:8091');
$solidityNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$eventServer = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');

$tron = new \IEXBase\TronAPI\Tron();

if($fullNode->isConnected()) {
$tron->setFullNode($fullNode);
try {
$tron = new \IEXBase\TronAPI\Tron($fullNode, $solidityNode, $eventServer);
} catch (\IEXBase\TronAPI\Exception\TronException $e) {
exit($e->getMessage());
}

if($solidityNode->isConnected()) {
$tron->setSolidityNode($solidityNode);
}
$tron->isConnected();
12 changes: 9 additions & 3 deletions examples/option-trx.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<?php
include_once '../vendor/autoload.php';

use IEXBase\TronAPI\Tron;
$fullNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$solidityNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$eventServer = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');

$tron = new Tron();
try {
$tron = new \IEXBase\TronAPI\Tron($fullNode, $solidityNode, $eventServer);
} catch (\IEXBase\TronAPI\Exception\TronException $e) {
exit($e->getMessage());
}

//option 1
$tron->sendTransaction('from','to',0.1);
Expand All @@ -12,4 +18,4 @@
$tron->send('from','to',0.1);

//option 3
$tron->sendTrx('from','to',0.1);
$tron->sendTrx('from','to',0.1);
10 changes: 0 additions & 10 deletions examples/send-transaction-password.php

This file was deleted.

13 changes: 11 additions & 2 deletions examples/send-transaction.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<?php
include_once '../vendor/autoload.php';

$tron = new \IEXBase\TronAPI\Tron();
$fullNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$solidityNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$eventServer = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');

try {
$tron = new \IEXBase\TronAPI\Tron($fullNode, $solidityNode, $eventServer);
} catch (\IEXBase\TronAPI\Exception\TronException $e) {
exit($e->getMessage());
}

$tron->setAddress('address');
$tron->setPrivateKey('privateKey');

try {
$transfer = $tron->sendTransaction('FromAddress', 'ToAddress', 1);
$transfer = $tron->send( 'ToAddress', 1);
} catch (\IEXBase\TronAPI\Exception\TronException $e) {
die($e->getMessage());
}
Expand Down
19 changes: 19 additions & 0 deletions examples/transactionBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
$fullNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$solidityNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$eventServer = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');

try {
$tron = new \IEXBase\TronAPI\Tron($fullNode, $solidityNode, $eventServer);
} catch (\IEXBase\TronAPI\Exception\TronException $e) {
exit($e->getMessage());
}


try {
$transaction = $tron->getTransactionBuilder()->sendTrx('to', 2,'fromAddress');
$signedTransaction = $tron->signTransaction($transaction);
$response = $tron->sendRawTransaction($signedTransaction);
} catch (\IEXBase\TronAPI\Exception\TronException $e) {
die($e->getMessage());
}
23 changes: 21 additions & 2 deletions src/Tron.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,20 @@ public function setManager($providers) {
* Get provider manager
*
* @return TronManager
*/
*/
public function getManager(): TronManager {
return $this->manager;
}

/**
* Get Transaction Builder
*
* @return TransactionBuilder
*/
public function getTransactionBuilder(): TransactionBuilder {
return $this->transactionBuilder;
}

/**
* Check connected provider
*
Expand Down Expand Up @@ -197,8 +206,18 @@ public function getAddress(): array
* Get customized provider data
*
* @return array
*/
*/
public function providers(): array
{
return $this->manager->getProviders();
}

/**
* Check Connection Providers
*
* @return array
*/
public function isConnected(): array
{
return $this->manager->isConnected();
}
Expand Down

0 comments on commit 332769b

Please sign in to comment.