@octaflowlabs/onchain-sdk 1.3.5 → 1.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,69 +1,121 @@
1
1
  # onchain-sdk
2
2
 
3
3
  Lightweight TypeScript SDK for EVM onchain utilities. It provides helpers for
4
- balances, transaction building, broadcasting, gas estimation, and wallet
5
- derivation.
4
+ balances, transaction building, broadcasting, gas estimation, wallet derivation,
5
+ and amount formatting.
6
6
 
7
7
  ## Install
8
8
 
9
- Install with npm or yarn.
9
+ ```bash
10
+ npm install @octaflowlabs/onchain-sdk
11
+ # or
12
+ yarn add @octaflowlabs/onchain-sdk
13
+ ```
10
14
 
11
15
  ## How to use
12
16
 
13
- - Add the package to the project and import the helpers needed.
17
+ ```ts
18
+ import {
19
+ getProvider,
20
+ getBalance,
21
+ buildUnsignedTransferTx,
22
+ broadcastTransaction,
23
+ } from '@octaflowlabs/onchain-sdk'
24
+ ```
25
+
14
26
  - Provide a valid RPC URL (public or private) and the target chain ID.
15
27
  - Call the balance, transaction, or signing helpers based on your flow.
16
28
  - Handle errors at the call site and decide how often to poll or refresh.
17
29
 
18
- ## What this SDK provides
30
+ ## API reference
31
+
32
+ ### Balances
33
+
34
+ | Export | Signature | Description |
35
+ |---|---|---|
36
+ | `getBalance` | `(params: GetBalanceParams) => Promise<bigint \| undefined>` | Fetch native or ERC-20 balance for a single token on one chain. |
37
+ | `getBalances` | `(params: GetBalancesParams) => Promise<GetBalanceResult>` | Batch-fetch balances across multiple chains using Multicall3 aggregation with automatic fallback to individual calls. |
38
+
39
+ ### Transactions
40
+
41
+ | Export | Signature | Description |
42
+ |---|---|---|
43
+ | `buildBaseUnsignedTransferTx` | `(params: BuildBaseUnsignedTransferTxParams) => { to, data, value }` | Build the core `to`/`data`/`value` fields for a native or ERC-20 transfer. |
44
+ | `buildUnsignedTransferTx` | `(options: BuildUnsignedTransferTxOptions) => Promise<PrepareTransactionResult>` | Build a complete unsigned transfer transaction with gas estimation. |
45
+ | `buildMaxNativeTransferTx` | `(options: BuildMaxNativeTransferTxOptions) => Promise<string>` | Calculate the maximum sendable native amount after reserving gas. |
46
+ | `estimateGasLimitFromProvider` | `(props: EstimateGasLimitFromProviderProps) => Promise<GasEstimateResult>` | Estimate gas limit with dynamic congestion-based buffering (5–30%). |
47
+ | `estimateTransaction` | `(options: EstimateTransactionOptions) => Promise<EstimateTransactionResult>` | Estimate total transaction cost including gas reserve. |
48
+ | `prepareTransaction` | `(params: PrepareTransactionParams) => Promise<PrepareTransactionResult>` | Full transaction preparation: estimation + nonce + fee data, ready for signing. |
49
+ | `broadcastTransaction` | `(options: BroadcastTransactionOptions) => Promise<string>` | Broadcast a signed transaction and optionally wait for confirmations. Returns the tx hash. |
50
+ | `txStatus` | `(options: TxStatusOptions) => Promise<TxStatusResponse>` | Check transaction status and retrieve the receipt. |
51
+
52
+ ### Provider
19
53
 
20
- Balances
54
+ | Export | Signature | Description |
55
+ |---|---|---|
56
+ | `getProvider` | `(rpcUrl: string, chainId?: number) => JsonRpcProvider \| undefined` | Create an ethers `JsonRpcProvider` with optional static network. |
57
+ | `getDefaultRpc` | `(networkId: NetworkId) => string` | Return the default RPC URL for a registered network. |
21
58
 
22
- - Fetch native token balances for an address.
23
- - Fetch ERC-20 token balances for an address.
24
- - Fetch multiple token balances across multiple chains with multicall batching.
59
+ ### Wallet and signing
25
60
 
26
- Transactions
61
+ | Export | Signature | Description |
62
+ |---|---|---|
63
+ | `EvmWalletService` | `class` | HD wallet service: generate wallets, derive from mnemonic or private key, find next available index, sign messages, validate mnemonics. Accepts an `EntropySource` for randomness. |
64
+ | `createWallet` | `(privateKey: string, rpcUrl?: string) => Wallet` | Create an ethers `Wallet` instance from a private key. |
65
+ | `signMessage` | `(privateKey: string, message: string) => Promise<string>` | Sign an arbitrary message. |
66
+ | `signTransaction` | `(privateKey: string, tx: TransactionRequest, rpcUrl?: string) => Promise<string>` | Sign a transaction and return the serialized signed payload. |
27
67
 
28
- - Build unsigned native or ERC-20 transfer transactions.
29
- - Estimate gas limits and fee data from a provider.
30
- - Broadcast signed transactions.
31
- - Check transaction status and receipt confirmation.
68
+ ### Utilities
32
69
 
33
- Wallets and signing
70
+ | Export | Signature | Description |
71
+ |---|---|---|
72
+ | `formattedAmountForDisplay` | `(amount, decimals, options?) => string` | Locale-aware formatting with group separators, scientific notation for large numbers, and threshold display for tiny amounts. |
73
+ | `parsedAmount` | `(amount: string, decimals: number) => bigint` | Parse a human-readable amount string into its smallest-unit `bigint`. |
74
+ | `normalizeAddress` | `(address: string) => string` | Validate and checksum an Ethereum address. |
75
+ | `getShortenTransactionHashOrAddress` | `(value, first?, last?) => string` | Shorten a tx hash or address (e.g. `0xAbCd…1234`). |
76
+ | `getShortenData` | `(data, first?, last?) => string` | Shorten arbitrary hex data. |
77
+ | `transformBigInt` | `(obj: ContractTransaction) => object` | Convert all `bigint` properties to strings for JSON serialization. |
78
+ | `handleErrorMessages` | `(options: { e, message }) => void` | Log structured ethers errors with detailed context. |
34
79
 
35
- - Generate and derive EVM wallets from entropy.
36
- - Sign messages and transactions.
80
+ ### Constants
37
81
 
38
- Utilities
82
+ | Export | Description |
83
+ |---|---|
84
+ | `GAS_LIMIT_PER_TX_TYPE` | Default gas limits: native transfer (`21 000n`), ERC-20 transfer (`65 000n`), approval (`100 000n`). |
85
+ | `MULTICALL3_ADDRESS` | Canonical Multicall3 contract address. |
86
+ | `ERC20_TOKEN_CONTRACT_ABI` | Standard ERC-20 ABI (`balanceOf`, `transfer`, `approve`, `allowance`, `decimals`, etc.). |
87
+ | `NATIVE_TOKENS` | Native token metadata by chain (ETH, BNB, POL). |
39
88
 
40
- - Format and parse amounts for display.
41
- - Normalize addresses and shorten hashes.
42
- - Transform bigint values for UI use.
89
+ ### Networks registry
43
90
 
44
- ABIs and constants
91
+ The SDK ships a built-in networks registry (`NETWORKS`) covering Ethereum, BSC, Polygon, Arbitrum, and Sepolia.
45
92
 
46
- - ERC-20 ABI for balance and transfer calls.
47
- - Multicall3 ABI and address for batched reads.
48
- - Gas limit defaults per transaction type.
93
+ | Export | Description |
94
+ |---|---|
95
+ | `NETWORKS` | `Record<NetworkId, NetworkField>` full network config map. |
96
+ | `getNetworksByCategory` | `(category: NetworkCategory) => NetworkField[]` — filter by `popular`, `custom`, or `testnet`. |
49
97
 
50
- Networks registry
98
+ Each `NetworkField` entry includes `id`, `name`, `chainId`, `rpcUrl`, optional `failoverRpcUrl`, `explorerUrl`, `iconUrl`, and `symbol`.
51
99
 
52
- - The SDK includes a predefined networks registry in `src/constants/NETWORKS_REGISTRY.ts`.
53
- - Networks are grouped by `category` (for example: `popular`, `custom`).
54
- - Each network entry includes:
55
- - `id`: stable internal identifier.
56
- - `name`: human-readable network name.
57
- - `chainId`: EVM chain ID.
58
- - `rpcUrl`: primary RPC endpoint.
59
- - `failoverRpcUrl` (optional): fallback RPC endpoint.
60
- - `explorerUrl`: block explorer base URL.
61
- - `iconUrl`: network icon URL.
62
- - `symbol`: native currency symbol.
63
- - This registry is useful for network selection UIs, chain metadata lookup, and RPC fallback handling.
64
- - You can use `chainId` with SDK helpers and pass `rpcUrl` (or `failoverRpcUrl`) to provider-based calls.
100
+ ### Tokens registry
101
+
102
+ | Export | Description |
103
+ |---|---|
104
+ | `BASIC_TOKENS_BY_CHAIN` | Hardcoded ERC-20 token metadata (USDC, USDT, etc.) grouped by chain ID for Ethereum, BSC, Polygon, and Arbitrum. |
105
+
106
+ ### Types
107
+
108
+ All interfaces and type aliases are exported for consumer use:
109
+
110
+ `BroadcastTransactionOptions`, `BuildMaxNativeTransferTxOptions`, `BuildUnsignedTransferTxOptions`, `BuildBaseUnsignedTransferTxParams`, `EstimateGasLimitFromProviderProps`, `GasEstimateResult`, `EstimateTransactionOptions`, `EstimateTransactionResult`, `PrepareTransactionParams`, `PrepareTransactionResult`, `TxStatusOptions`, `TxStatusResponse`, `FormatAmountOptions`, `TransactionRequest`, `GetBalanceParams`, `GetBalancesParams`, `GetBalancesChainRequest`, `GetBalanceResult`, `ChainBalances`, `TokenBalance`, `ChainGroup`, `NetworkField`, `NetworkId`, `NetworkCategory`, `BasicTokenData`, `BasicTokenSymbol`, `ChainTokenDataMap`, `EvmGeneratedWallet`, `EvmDerivedWallet`, `EntropySource`.
65
111
 
66
112
  ## Design notes
67
113
 
68
114
  - The SDK is stateless and transport-agnostic. It expects a caller-provided RPC URL.
69
- - Caching, polling, and background jobs should be handled by the consumer app or backend.
115
+ - Multicall3 is used automatically for batched balance queries with per-call failure handling and fallback.
116
+ - Gas estimation applies dynamic congestion-aware buffering (5–30%) based on current fee data.
117
+ - Caching, polling, and background jobs should be handled by the consumer app or backend.
118
+
119
+ ## License
120
+
121
+ MIT
@@ -3,7 +3,7 @@ import ERC20_TOKEN_CONTRACT_ABI from './ABIs/ERC20_TOKEN_CONTRACT_ABI';
3
3
  export { ERC20_TOKEN_CONTRACT_ABI };
4
4
  /** constants exports */
5
5
  export { GAS_LIMIT_PER_TX_TYPE, MULTICALL3_ADDRESS } from './constants/constants';
6
- export { NETWORKS_REGISTRY, NetworkField, NetworkRegistry } from './constants/NETWORKS_REGISTRY';
6
+ export { NetworkField, NetworkRegistry, NETWORKS_REGISTRY, } from './constants/NETWORKS_REGISTRY';
7
7
  export { BASIC_TOKENS_BY_CHAIN, BasicTokenData, BasicTokenSymbol, ChainTokenDataMap, } from './constants/BASIC_TOKENS_REGISTRY';
8
8
  /** basic blockchain exports */
9
9
  export { buildBaseUnsignedTransferTx, buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import ERC20_TOKEN_CONTRACT_ABI from './ABIs/ERC20_TOKEN_CONTRACT_ABI';
3
3
  export { ERC20_TOKEN_CONTRACT_ABI };
4
4
  /** constants exports */
5
5
  export { GAS_LIMIT_PER_TX_TYPE, MULTICALL3_ADDRESS } from './constants/constants';
6
- export { NETWORKS_REGISTRY, NetworkField, NetworkRegistry } from './constants/NETWORKS_REGISTRY';
6
+ export { NetworkField, NetworkRegistry, NETWORKS_REGISTRY, } from './constants/NETWORKS_REGISTRY';
7
7
  export { BASIC_TOKENS_BY_CHAIN, BasicTokenData, BasicTokenSymbol, ChainTokenDataMap, } from './constants/BASIC_TOKENS_REGISTRY';
8
8
  /** basic blockchain exports */
9
9
  export { buildBaseUnsignedTransferTx, buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import ERC20_TOKEN_CONTRACT_ABI from './ABIs/ERC20_TOKEN_CONTRACT_ABI';
3
3
  export { ERC20_TOKEN_CONTRACT_ABI };
4
4
  /** constants exports */
5
5
  export { GAS_LIMIT_PER_TX_TYPE, MULTICALL3_ADDRESS } from './constants/constants';
6
- export { NETWORKS_REGISTRY } from './constants/NETWORKS_REGISTRY';
6
+ export { NETWORKS_REGISTRY, } from './constants/NETWORKS_REGISTRY';
7
7
  export { BASIC_TOKENS_BY_CHAIN, } from './constants/BASIC_TOKENS_REGISTRY';
8
8
  /** basic blockchain exports */
9
9
  export { buildBaseUnsignedTransferTx, buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octaflowlabs/onchain-sdk",
3
- "version": "1.3.5",
3
+ "version": "1.3.8",
4
4
  "description": "onchain methods for web3",
5
5
  "repository": "https://github.com/crisramb665/onchain-sdk.git",
6
6
  "license": "MIT",