tbc-sdk 0.7.0

Rust SDK for TuringBitChain transactions and contracts
Documentation

TBC Rust SDK

Rust SDK for constructing and signing TuringBitChain transactions and implemented contracts.

Install

[dependencies]
tbc-sdk = "0.7.0"

The Cargo package name is tbc-sdk; the Rust import name is tbc_sdk.

0.7.0 release

MultiSig supports TBC and ordinary Token across legacy FT v1–v4, intermediate TBC20 and TBC20 Standard. Builders, proposal validation, signing and finalization reject Stablecoin, LP and locked LP. This stricter asset policy is why the release increments the minor version before 1.0. Ordinary single-signature contract operations remain available. See scope and migration and designated 2/3 testnet verification.

Implemented modules

  • Base transactions, scripts, keys, sighashes, and API access
  • Random private keys, WIF import, English BIP39 mnemonics, and BIP32 xprv/xpub keys
  • FT mint, transfer, batch transfer, and merge
  • NFT collection creation, mint, batch mint, and transfer
  • StableCoin creation, mint, transfer, batch transfer, and merge
  • OrderBook buy/sell order creation, matching, and cancellation
  • TBC-native MultiSig wallet creation plus distributed TBC/FT build, sign, and finish flows for ordinary Token only: legacy FT v1–v4, intermediate TBC20 and TBC20 Standard. Legacy/modern Stablecoin, LP and locked LP are excluded from MultiSig construction/signing/finalization (token generations, surface and security model, testnet evidence)
  • PoolNFT v2 creation, liquidity, swaps, FTLP lifecycle, and query-backed explicit-context resolution (API mapping and creation authority, testnet evidence); PoolNFT v1 is not supported
  • TBC20 source/genesis mint, transfer/change, merge, address and contract controllers (API)
  • TBC20/FT source-graph validation with strict and relaxed-metadata policies, including automatic network API resolution (API)

Core primitives implement current TBC version-10 transactions, with tbc-lib-js@1.0.31 as the JavaScript reference: raw serialization/deserialization, TBC header-based txids, ForkID signing, keys/addresses, and HD wallet derivation. Transaction::txid() always uses the TBC header hash. It does not implement the JavaScript library's legacy full-raw hashing branch for transaction versions below 10. The transaction version is independent of the contract package version.

New-generation builders target tbc-contract@1.7.4: TBC20 Standard, TBC721 Standard, Stablecoin, AMM/LP, LOP, HTLC and Timelock. Existing contract modules remain available. HTLC deployments now use v2 with exactly 32-byte preimages; existing v1 outputs remain spendable. See the 1.7.4 migration and offline verification report. The 1.7.3 compatibility matrix and actual testnet evidence describes supported operations and remaining facade/indexer limitations; this is not a claim of complete JS API parity. For historical Pool/MultiSig example tests, run node scripts/setup-reference-165.js once to install the pinned reference in isolated worktrees, then run cargo test --all-targets. Stablecoin pools and deprecated PoolNFT v1 are outside the supported scope. See the Pool verification report for the parameter matrix, historical locked-LP failures, and successful testnet rechecks.

Minimal usage

use tbc_sdk::{ApiClient, Transaction};

let api = ApiClient::main();
let tx = Transaction::new();

assert_eq!(api.base_url(), "https://api.turingbitchain.io/api/tbc/");
assert!(tx.inputs.is_empty());

Wallets and HD keys

Create a standalone random private key directly from the operating system's secure random source:

use tbc_sdk::PrivateKey;

fn main() -> tbc_sdk::Result<()> {
    let private_key = PrivateKey::generate();
    let wif = private_key.to_wif();
    let restored = PrivateKey::from_wif(&wif)?;
    assert_eq!(restored.address(), private_key.address());
    Ok(())
}

Generate or restore an English BIP39 mnemonic, then derive the default TBC account path m/44'/236'/0'/1/0:

use tbc_sdk::{HdNetwork, HdPrivateKey, Mnemonic, TBC_DERIVATION_PATH};

fn main() -> tbc_sdk::Result<()> {
    let mnemonic = Mnemonic::generate(12)?;
    let restored = Mnemonic::from_phrase(&mnemonic.phrase())?;
    let root = HdPrivateKey::from_mnemonic(&restored, "", HdNetwork::Mainnet)?;
    let account = root.derive_path(TBC_DERIVATION_PATH)?;

    let xprv = account.to_xprv();
    let xpub = account.to_public().to_xpub();
    let imported_private = HdPrivateKey::from_xprv(&xprv)?;
    let imported_public = tbc_sdk::HdPublicKey::from_xpub(&xpub)?;
    assert_eq!(imported_private.address(), imported_public.address());
    Ok(())
}

HdNetwork::Mainnet serializes xprv/xpub and HdNetwork::Testnet serializes tprv/tpub. An extended public key can derive only non-hardened children; hardened derivation requires the extended private key.

Development

In 0.3.0, every supported signed builder finalizes the fee from the exact post-signature transaction size at 80 sat/KB. Signature-length changes are handled with a non-decreasing target, and a builder returns an explicit error instead of an under-target fallback if finalization cannot converge.

cargo test --all-targets

License

MIT