manojx / tron-bundle
A Symfony bundle to interact with Tron Blockchain and Wallets.
Installs: 76
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Type:symfony-bundle
Requires
- php: ^7.4 || ^8.0
- kornrunner/keccak: ^1.1
- simplito/elliptic-php: ^1.0
- symfony/framework-bundle: ^5.4 || ^6.1 || ^7.0
- symfony/http-client: ^5.4 || ^6.1 || ^7.0
- web3p/web3.php: ^0.3.2
Requires (Dev)
- phpunit/phpunit: ^9.6 || ^10.5 || ^11.3
This package is auto-updated.
Last update: 2025-03-29 01:09:19 UTC
README
A Symfony bundle that makes it easy to interact with the Tron Blockchain. It allows you to manage wallets, create and sign transactions, broadcast them to the network, and handle tasks like generating and validating addresses. This bundle simplifies working with Tron in Symfony applications.
Features
- Create and manage Tron wallets
- Sign transactions and broadcast them to the Tron network
- Create new Tron addresses and validate them
- Easy integration with Symfony applications
Installation
To install the Tron bundle, use Composer:
composer require manojx/tron-bundle
Requirements
- PHP
^7.4 || ^8.0
- Symfony
^5.4 || ^6.1 || ^7.0
- simplito/elliptic-php
^1.0
- kornrunner/keccak
^1.1
Configuration
You can configure the Tron node endpoint in your Symfony configuration:
# config/packages/tron.yaml tron: default_network: shasta networks: mainnet: fullNode: host: 'https://api.trongrid.io' api_key: 'api-key' solidityNode: host: 'https://api.trongrid.io' api_key: 'api-key' explorer: host: 'https://tronscan.org' api_key: 'api-key' shasta: fullNode: host: 'https://api.shasta.trongrid.io' api_key: 'api-key' explorer: host: 'https://shastapi.tronscan.org' nile: fullNode: host: 'https://api.nileex.io' api_key: 'api-key' explorer: host: 'https://nile.tronscan.org'
Usage
Creating a Tron Wallet
You can use the Tron service to create a new wallet or access an existing wallet.
use ManojX\TronBundle\TronInterface; class WalletService { private TronInterface $tron; public function __construct(TronInterface $tron) { $this->tron = $tron; } public function createWallet() { $wallet = $this->tron->getWallet(); $address = $wallet->createNewAddress(); echo 'Address: ' . $address->getAddress(); echo 'Private Key: ' . $address->getPrivateKey(); } }
Sending TRX
You can initialize a transaction and send TRX using the wallet's private key.
use ManojX\TronBundle\TronInterface; class TransactionService { private TronInterface $tron; public function __construct(TronInterface $tron) { $this->tron = $tron; } public function sendTrx() { $wallet = $this->tron->getWallet('your-private-key'); $transaction = $wallet->initTransaction(); $transaction->setTo('receiver-tron-address'); $transaction->setAmount(1); // Amount in TRX $signedTransaction = $transaction->createAndSign(); $node = $this->tron->getNode(); $response = $node->broadcastTransaction($signedTransaction); return $response; } }
USDT & Contract Interaction
You can interact with USDT and other smart contracts on the Tron network.
USDT Contract Address: TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs (Shasta Testnet)
use ManojX\TronBundle\TronInterface; class TransactionService { private TronInterface $tron; public function __construct(TronInterface $tron) { $this->tron = $tron; } public function sendUsdt() { $wallet = $this->tron->getWallet('your-private-key'); $usdt = $wallet->getUsdt(); $transaction = $usdt->transfer('to-address', 1); $signedTransaction = $wallet->signTransaction($transaction['data']); $response = $node->broadcastTransaction($signedTransaction); return $response; } }
For additional usage examples, please refer to the examples
directory.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue on GitHub.