Rust-idiomatic Tron API client library.
| Features | Support | |----------|---------| | Transaction signing & broadcasting | ✓ | | Smart contract calls | ✓ | | Basic network querying | ✓ | | Staking TRX for energy and bandwidth | ✓ | | Offline transaction signing | ✓ | | Offline transaction encoding (without CreateTransaction API) | ✗ | | Voting & Proposals | ✗ |
| Crate | Description | |--------------|------------------| | heliosphere | Main crate | | heliosphere-core | Core types, nostd compatible but alloc required | | heliosphere-signer | Transaction signing utils, nostd compatible but alloc required |
```
let api = "https://api.shasta.trongrid.io";
let keypair = Keypair::fromhexkey(
std::fs::readtostring(".key")
.expect("no ./.key found")
.trim(),
)
.unwrap();
let client = RpcClient::new(api).unwrap();
let from = keypair.address();
let to: Address = "
// Fetch account balance let methodcallbalance = MethodCall { caller: &from, contract: &usdt, selector: "balanceOf(address)", parameter: ðabi::encode(&[Token::Address(from.into())]), }; let res = ðabi::decode( &[ParamType::Uint(256)], &client .querycontract(&methodcallbalance) .await .unwrap() .constantresult(0) .unwrap(), ) .unwrap()[0]; let currentbalance = match res { Token::Uint(x) => x, _ => panic!("Wrong type"), }; println!("Balance: {}", currentbalance);
// Transfer tokens let methodcall = MethodCall { caller: &from, contract: &usdt, selector: "transfer(address,uint256)", parameter: ðabi::encode(&[Token::Address(to.into()), Token::Uint(U256::from(amount))]), }; // Estimate energy usage let estimated = client.estimateenergy(&methodcall).await.unwrap(); println!("Estimated energy usage: {}", estimated); // Send tx let mut tx = client .triggercontract(&methodcall, 0, None) .await .unwrap(); keypair.signtransaction(&mut tx).unwrap(); let txid = client.broadcasttransaction(&tx).await.unwrap(); println!("Txid: {}", txid); println!("Confirming..."); client.awaitconfirmation(txid).await.unwrap(); ```
This project is licensed under the [MIT license].