Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Thanks for your interest in contributing! All contributions are welcome.
- All examples target the **Nile testnet** by default.
- Read-only examples must run without any environment variables.
- Examples that send transactions require `TRON_PRIVATE_KEY=<hex>`.
- Use `TRON_API_KEY` for optional TronGrid API key support.
- Use `anyhow::Result<()>` as the return type of `main`.
- Keep examples focused — one concept per file.

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
[workspace.package]
version = "0.1.0"
edition = "2024"
rust-version = "1.85"
rust-version = "1.90"
authors = ["tronz contributors"]
license = "MIT OR Apache-2.0"
homepage = "https://github.com/throgxyz/examples"
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Runnable examples for the [tronz](https://github.com/throgxyz/tronz) TRON SDK.

All examples target the [Nile testnet](https://nileex.io). Read-only examples run without a private key; examples that send transactions require `TRON_PRIVATE_KEY=<hex>`.

Set `TRON_API_KEY` to use a TronGrid API key.

## Usage

```sh
Expand All @@ -14,6 +16,20 @@ cargo run -p examples-queries --example query
TRON_PRIVATE_KEY=<hex> cargo run -p examples-staking --example stake
```

## Environment Variables

| Variable | Description |
| --- | --- |
| `TRON_PRIVATE_KEY` | Funded Nile private key for write examples. |
| `TRON_API_KEY` | Optional TronGrid API key. |
| `TRON_ADDRESS` | Address to query in read examples. |
| `TRON_TO` | Recipient or target address in write examples. |
| `TRON_CONTRACT` | TRC20 or smart contract address. |
| `TRON_TX_ID` | Transaction id used by receipt/log decoding examples. |
| `TRON_AMOUNT_SUN` | TRX amount in sun for TRX transfer examples. |
| `TRON_FREEZE_SUN` | Amount to stake in staking examples. |
| `TRON_TOKEN_ID` | Numeric TRC10 token id. |

## Overview

This repository contains the following examples:
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.85"
msrv = "1.90"
4 changes: 2 additions & 2 deletions examples/contracts/examples/contract_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
//! No private key required (read-only).
//!
//! Required env:
//! TRON_CONTRACT — TRC20 contract address (e.g. USDT on mainnet)
//! TRON_CONTRACT — TRC20 contract address (e.g. test USDT on Nile)
//!
//! Optional env:
//! TRON_API_KEY — TronGrid API key
//!
//! ```bash
//! TRON_CONTRACT=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t \
//! TRON_CONTRACT=TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf \
//! cargo run -p examples-contracts --example contract_call
//! ```

Expand Down
4 changes: 2 additions & 2 deletions examples/contracts/examples/contract_dynamic_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
//! TRON_API_KEY — TronGrid API key
//!
//! ```bash
//! TRON_CONTRACT=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t \
//! TRON_ADDRESS=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t \
//! TRON_CONTRACT=TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf \
//! TRON_ADDRESS=TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf \
//! cargo run -p examples-contracts --example contract_dynamic_abi
//! ```

Expand Down
5 changes: 2 additions & 3 deletions examples/queries/examples/query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Read-only queries against the TronGrid mainnet.
//! Read-only queries against the TronGrid Nile testnet.
//!
//! No private key required.
//!
Expand All @@ -12,8 +12,7 @@

use tronz::{ProviderBuilder, TRONGRID_NILE, TronProvider, primitives::ResourceCode};

// A well-known TRON address with on-chain activity (USDT TRC20 contract on
// mainnet; also present on Nile testnet with TRX balance).
// A well-known TRON address that is present on Nile testnet with TRX balance.
const DEFAULT_ADDR: &str = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion examples/signers/examples/signer_generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn main() -> anyhow::Result<()> {
println!(" 2. Get Nile TRX from the faucet: https://nileex.io/");
println!(" (send to: {address})");
println!(
" 3. Run examples with: TRON_PRIVATE_KEY={key_hex} cargo run -p examples-signers --example transfer_trx"
" 3. Run examples with: TRON_PRIVATE_KEY={key_hex} cargo run -p examples-transfers --example transfer_trx"
);

Ok(())
Expand Down
Loading