承接 manojx/tron-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

manojx/tron-bundle

Composer 安装命令:

composer require manojx/tron-bundle

包简介

A Symfony bundle to interact with Tron Blockchain and Wallets.

README 文档

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.

统计信息

  • 总下载量: 76
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固