Tron4Biz 1.0.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Tron4Biz --version 1.0.2
NuGet\Install-Package Tron4Biz -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tron4Biz" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tron4Biz" Version="1.0.2" />
<PackageReference Include="Tron4Biz" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tron4Biz --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Tron4Biz, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Tron4Biz@1.0.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Tron4Biz&version=1.0.2
#tool nuget:?package=Tron4Biz&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Tron4Biz
Tron4Biz 是一个用于 .NET 的 TRON 区块链 SDK,提供了一套完整的工具来与 TRON 网络进行交互,包括 HD 钱包管理、地址生成、交易构建和广播等功能。
功能特性
- HD 钱包 (BIP-39/BIP-44) - 支持助记词生成、种子派生和分层确定性钱包
- 地址管理 - TRON 地址的生成和验证 (Base58Check 编码)
- 交易服务 - 本地交易签名和通过 gRPC 广播
- 节点服务 - 支持 FullNode 和 SolidityNode 的 gRPC 客户端
- 智能合约交互 - ABI 编码支持
- 依赖注入 - 完整的 Microsoft.Extensions.DependencyInjection 集成
快速开始
1. 使用依赖注入配置
using Tron4Biz.DependencyInjection;
var services = new ServiceCollection();
services.AddTron4Biz(builder =>
{
builder.UseMainnet(); // 或 UseShasta() / UseNile()
});
var serviceProvider = services.BuildServiceProvider();
2. HD 钱包服务
var hdWalletService = serviceProvider.GetRequiredService<IHDWalletService>();
// 生成助记词
string mnemonic = hdWalletService.GenerateMnemonic();
Console.WriteLine($"助记词: {mnemonic}");
// 派生种子
byte[] seed = hdWalletService.DeriveSeed(mnemonic);
// 派生地址 (BIP-44 路径: m/44'/195'/account'/0/index)
string address = hdWalletService.DeriveAddress(seed, index: 0, account: 0);
Console.WriteLine($"地址: {address}");
// 验证地址
bool isValid = hdWalletService.ValidateAddress(address);
3. 交易服务
var transactionService = serviceProvider.GetRequiredService<ITronTransactionService>();
// 创建并签名转账交易
var result = await transactionService.CreateAndSignTransactionAsync(
fromAddress: "T...",
toAddress: "T...",
amount: 1000000, // 1 TRX = 1,000,000 SUN
privateKey: privateKeyBytes
);
// 广播交易
var broadcastResult = await transactionService.BroadcastTransactionAsync(result.SignedTransaction);
4. 节点服务
var fullNodeService = serviceProvider.GetRequiredService<IFullNodeService>();
var solidityNodeService = serviceProvider.GetRequiredService<ISolidityNodeService>();
// 获取最新区块
var block = await fullNodeService.GetNowBlockAsync();
// 查询账户信息
var account = await fullNodeService.GetAccountAsync(address);
// 查询已确认的交易 (通过 SolidityNode)
var transaction = await solidityNodeService.GetTransactionByIdAsync(txid);
项目结构
Tron4Biz/
├── Crypto/ # 加密相关功能
│ ├── HDWallet.cs # 分层确定性钱包 (BIP-32/44)
│ ├── Mnemonic.cs # 助记词 (BIP-39)
│ ├── TronAddress.cs # TRON 地址工具
│ ├── TronKey.cs # 密钥管理
│ ├── Base58.cs # Base58Check 编码
│ └── AbiEncoder.cs # ABI 编码
├── Node/ # 节点服务
│ ├── FullNodeService.cs
│ └── SolidityNodeService.cs
├── Transactions/ # 交易服务
│ ├── LocalTronTransactionService.cs
│ └── GrpcTronTransactionService.cs
├── Proto/ # gRPC/Protocol Buffers
├── Models/ # 数据模型
├── Options/ # 配置选项
└── DependencyInjection/ # DI 扩展
配置选项
services.AddTron4Biz(builder =>
{
builder.UseMainnet()
.ConfigureFullNode(options =>
{
options.Endpoint = "grpc.trongrid.io:50051";
options.ApiKey = "your-api-key"; // 可选
})
.ConfigureSolidityNode(options =>
{
options.Endpoint = "grpc.trongrid.io:50052";
});
});
许可证
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- BouncyCastle.Cryptography (>= 2.6.2)
- Google.Protobuf (>= 3.25.1)
- Grpc.Net.Client (>= 2.60.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
GitHub repositories
This package is not used by any popular GitHub repositories.