Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
fourclub committed Feb 26, 2023
1 parent 1809495 commit 0d2fa40
Show file tree
Hide file tree
Showing 45 changed files with 5,085 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# User-specific stuff
.idea
# CMake
cmake-build-*/

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

examples/index.php
composer.lock
examples/index2.php
vendor/
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: php

php:
- 7.4

matrix:
fast_finish: true

cache:
directories:
- $HOME/.composer/cache

before_install:
- travis_retry composer self-update

install:
- travis_retry composer install --no-interaction --prefer-dist
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-cayman
1 change: 1 addition & 0 deletions abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"constant":false,"inputs":[{"name":"number","type":"uint256"}],"name":"fibonacciNotify","outputs":[{"name":"result","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"number","type":"uint256"}],"name":"fibonacci","outputs":[{"name":"result","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"input","type":"uint256"},{"indexed":false,"name":"result","type":"uint256"}],"name":"Notify","type":"event"}]
39 changes: 39 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "fourclub/tron-api",
"description": "PHP API for interacting with Tron (Trx)",
"license": "MIT",
"type": "library",
"homepage": "https://github.com/fourclub/tron-api",
"require": {
"php": "^7.4",
"comely-io/data-types": "^1.0",
"guzzlehttp/guzzle": "^7.0",
"iexbase/web3.php": "^2.0.1",
"kornrunner/secp256k1": "^0.1.2",
"simplito/elliptic-php": "^1.0",
"ext-json": "*",
"ext-bcmath": "*"
},

"require-dev": {
"phpunit/phpunit": "^6.0"
},
"autoload": {
"psr-4": {
"fourclub\\TronAPI\\": "src"
}
},

"autoload-dev": {
"psr-4": {
"fourclub\\TronAPI\\Test\\": "tests"
}
},

"config": {
"sort-packages": true
},

"minimum-stability": "dev",
"prefer-stable": true
}
24 changes: 24 additions & 0 deletions examples/account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
include_once '../vendor/autoload.php';

try {
$tron = new \fourclub\TronAPI\Tron();

$generateAddress = $tron->generateAddress(); // or createAddress()
$isValid = $tron->isAddress($generateAddress->getAddress());


echo 'Address hex: ' . $generateAddress->getAddress();
echo 'Address base58: ' . $generateAddress->getAddress(true);
echo 'Private key: ' . $generateAddress->getPrivateKey();
echo 'Public key: ' . $generateAddress->getPublicKey();
echo 'Is Validate: ' . $isValid;

echo 'Raw data: ' . $generateAddress->getRawData();

} catch (\fourclub\TronAPI\Exception\TronException $e) {
echo $e->getMessage();
}



13 changes: 13 additions & 0 deletions examples/amount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
include_once '../vendor/autoload.php';

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

/**
* WARNING: When sending funds, you should not specify these parameters
*
* P.S: In the process of payment are automatically converted
*/

$from = $tron->toTron(1.15); //1150000
$to = $tron->fromTron(11500000); //11.5000000
15 changes: 15 additions & 0 deletions examples/balance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
include_once '../vendor/autoload.php';

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

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

$tron->setAddress('address');
$balance = $tron->getBalance(null, true);
29 changes: 29 additions & 0 deletions examples/contract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

include_once '../vendor/autoload.php';

use fourclub\TronAPI\Tron;

try {
$fullNode = new \fourclub\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$solidityNode = new \fourclub\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$eventServer = new \fourclub\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
} catch (\fourclub\TronAPI\Exception\TronException $e) {
echo $e->getMessage();
}

try {
$tron = new Tron($fullNode, $solidityNode, $eventServer, null, true);
$contract = $tron->contract('TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'); // Tether USDT https://tronscan.org/#/token20/TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t

// Data
echo $contract->name();
echo $contract->symbol();
echo $contract->balanceOf();
echo $contract->totalSupply();
//echo $contract->transfer('to', 'amount', 'from');


} catch (\fourclub\TronAPI\Exception\TronException $e) {
echo $e->getMessage();
}
16 changes: 16 additions & 0 deletions examples/contract_balance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
$fullNode = new \fourclub\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$solidityNode = new \fourclub\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$eventServer = new \fourclub\TronAPI\Provider\HttpProvider('https://api.trongrid.io');

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

$balance = $tron->getTransactionBuilder()->contractbalance($tron->getAddress);
foreach ($balance as $key => $item) {
echo $item["name"] . " (" . $item["symbol"] . ") => " . $item["balance"] . "\n";
}

17 changes: 17 additions & 0 deletions examples/custom-nodes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
include_once '../vendor/autoload.php';

use fourclub\TronAPI\Provider\HttpProvider;
use fourclub\TronAPI\Tron;

$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
try {
$tron = new Tron($fullNode, $solidityNode, $eventServer, $privateKey);
} catch (\fourclub\TronAPI\Exception\TronException $e) {
die($e->getMessage());
}
15 changes: 15 additions & 0 deletions examples/find-transaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
include_once '../vendor/autoload.php';

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

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

$detail = $tron->getTransaction('TxId');
var_dump($detail);
10 changes: 10 additions & 0 deletions examples/hex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
include_once '../vendor/autoload.php';

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

$tron->toHex('TT67rPNwgmpeimvHUMVzFfKsjL9GZ1wGw8');
//result: 41BBC8C05F1B09839E72DB044A6AA57E2A5D414A10

$tron->fromHex('41BBC8C05F1B09839E72DB044A6AA57E2A5D414A10');
//result: TT67rPNwgmpeimvHUMVzFfKsjL9GZ1wGw8
14 changes: 14 additions & 0 deletions examples/is-connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
include_once '../vendor/autoload.php';

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

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

$tron->isConnected();
21 changes: 21 additions & 0 deletions examples/option-trx.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
include_once '../vendor/autoload.php';

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

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

//option 1
$tron->sendTransaction('to', 0.1, 'hello');

//option 2
$tron->send('to', 0.1);

//option 3
$tron->sendTrx('to', 0.1);
28 changes: 28 additions & 0 deletions examples/send-transaction USDT-TRC20.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
include_once '../vendor/autoload.php';

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

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

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

try {
$transfer = $tron->send('ToAddress', 1);
$transfer = $tron
->contract('TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t') // tether contract address
->setFeeLimit(15); // fee limit 15 trx o more AND
// send "USDT amount" to " USDT address"
$result = $transfer->transfer('address To', 'USDT amount');
} catch (\fourclub\TronAPI\Exception\TronException $e) {
die($e->getMessage());
}

var_dump($transfer);
23 changes: 23 additions & 0 deletions examples/send-transaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
include_once '../vendor/autoload.php';

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

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

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

try {
$transfer = $tron->send('ToAddress', 1);
} catch (\fourclub\TronAPI\Exception\TronException $e) {
die($e->getMessage());
}

var_dump($transfer);
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 \fourclub\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$solidityNode = new \fourclub\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$eventServer = new \fourclub\TronAPI\Provider\HttpProvider('https://api.trongrid.io');

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


try {
$transaction = $tron->getTransactionBuilder()->sendTrx('to', 2, 'fromAddress');
$signedTransaction = $tron->signTransaction($transaction);
$response = $tron->sendRawTransaction($signedTransaction);
} catch (\fourclub\TronAPI\Exception\TronException $e) {
die($e->getMessage());
}
Loading

0 comments on commit 0d2fa40

Please sign in to comment.