New Features
-
Typed
read/writecontract namespacesAdded contract.read and contract.write namespaces for type-safe, ergonomic access to contract methods. Functions are split by state mutability: view / pure (constant call) functions are exposed under contract.read, while state-changing functions are exposed under contract.write. When an ABI is declared as const, function names and argument types are checked at compile time.
- Call as contract.read.methodName([arg0, arg1, ...], options) / contract.write.methodName([arg0, arg1, ...], options).
- The write
accountoption is a private key: its derived address owns and signs the transaction, so a write can be issued from a non-default signer — including on an instance with no default key. A value that is not a private key is rejected. Treat this value as secret. For reads, afromoption sets the caller address directly (validated as an address). - Validation errors (argument count, signer, call value, account) are surfaced as promise rejections.
- ABI functions literally named read or write remain callable via the legacy flat surface (handled through a proxy).
- Each function is additionally exposed under its full selector, e.g. contract.read['balanceOf(address)'] / contract.write['transfer(address,uint256)']. The selector form pins that exact overload, so same-arity overloads can be addressed unambiguously. Note: namespaces now enumerate each method under both its bare name and its selector, so Object.keys / for…in over contract.read / contract.write return two entries per function.
-
Added
utils.abi.encodeFunctionDataAdded utils.abi.encodeFunctionData(funcABI, args) to build smart contract calldata (function selector + encoded parameters). Validates argument count and supports TRON-specific handling of trcToken (kept in the selector, encoded as
uint256). -
Added
transactionBuilder.updateWitnessAdded transactionBuilder.updateWitness(address, url, options) to create a WitnessUpdateContract transaction that updates a witness node URL. Validates the address and the URL format / length (≤ 256).
Improvements
-
Dropped
Bufferin favor ofTextEncoder/TextDecoderReplaced Buffer
-based encoding intronweb, utils/crypto, utils/abi and utils/ethersUtils with TextEncoder / TextDecoder for better cross-environment (browser) compatibility. The conversion is byte-for-byte equivalent to the previous behavior. -
address.fromPrivateKeyaccepts0x-prefixed private keysTronWeb.address.fromPrivateKey now strips a leading 0x from the private key before deriving the address, so a private key works whether or not it carries the 0x prefix.
Changes
- Bump axios from 1.15.0 to 1.18.0.
- Bump dev dependency nyc to 18.
- Add overrides for ws (8.21.0) and serialize-javascript (7.0.5) to pin security-patched versions.
- build now runs the full build:all (esm, cjs, dist).