@minter-network/tx-core reference
Module reference for @minter-network/tx-core: 10^18 pip integer arithmetic, canonical RLP, BIP-39/44 wallets, SecretLeakGuard, 37 transaction builders, checks, and MinterGateClient.
@minter-network/tx-core implements secp256k1 cryptography, canonical RLP serialization, 10^18 pip integer arithmetic, and a Node Gate API v2 HTTP client on native BigInt, Uint8Array, DataView, TextEncoder, and fetch.
Install the published package with npm install @minter-network/tx-core. Package on npm
Runtime support
The package requires Node.js 20.19.0 or later. The runtime check signs and decodes the same Send test vector in each of these environments.
| Runtime | Verified versions |
|---|---|
| Node.js | 20.19.0, 22.23.5, 24.22.3 |
| Bun | 1.4.4 |
| Deno | 2.9.6 |
| Chromium | 159.0.8154.6 |
Package modules
| Module | Underlying dependencies | Scope and key exports |
|---|---|---|
pip | Native BigInt | PIP_SCALE (10n ** 18n), parsePip, formatPip, divRoundBigInt, ROUNDING, estimateAmmOutPip, and estimatePairV2SwapOutPip |
bytes | Native Uint8Array | Hex/UTF-8 converters, strict Mx..., Mp..., Mt..., Mc... formatters, and [10]byte ticker encoders (encodeTicker10) |
rlp | Built-in codec | Canonical rlpEncode / rlpDecode. rlpDecode rejects trailing bytes. decodeRlpUint rejects leading 0x00 in unsigned integers. |
wallet | @scure/bip39, @scure/bip32, @noble/hashes | Mnemonic generation, m/44'/60'/0'/0/{index} derivation (deriveWalletFromMnemonic), deriveMultisigAddress, and SecretLeakGuard |
tx and tx-types | @noble/curves/secp256k1, @noble/hashes | TX_TYPE registry, 48 DEFAULT_V330_COMMISSION_TARIFFS fields, builders for all 37 active opcodes, signTx, signTxForMultisig, assembleMultisigTx, decodeRawTx |
check | @noble/curves/secp256k1, @noble/hashes | Off-chain Mc... check issuance and proof generation (issueCheck, decodeCheck, createCheckProof, verifyCheckProof) |
gate-client and verify-transfer | Native fetch | MinterGateClient (getStatus, getAddress, getNextNonce, getCoinInfo, getCoinInfoById, estimateTxCommission, sendTransaction, getTransaction, waitForTransaction) and verifyIncomingTransfer |
Public TypeScript declarations (dist/index.d.ts) ship inside @minter-network/tx-core.
10^18 pip precision and rounding (pip)
Balances, pool reserves, order volumes, and fee tariffs in Minter v3.3.0 are unsigned integers denominated in atomic pip (1 coin = 1_000_000_000_000_000_000 pip = 10^18 pip). JavaScript Number (float64, 53 bits of significand, Number.MAX_SAFE_INTEGER < 0.0091 coins in pip) truncates low-order digits and causes Insufficient funds or non-canonical integer rejections.
Client interfaces distinguish three numeric states:
- Unpriced or missing data (
nullorundefined) renders as a placeholder (-orN/A), not zero. - Mathematical zero (
0n) renders as0.00or$0.00. - Non-zero dust (
1nbelow the display unit) renders as< 0.0001or< $0.01while keeping the exact 18-decimalpipstring in a tooltip attribute.
| Calculation or field | ROUNDING mode | Protocol rationale |
|---|---|---|
| Spendable balance and full-balance transfer | FLOOR | Prevents overstating balance by 1 pip (Insufficient funds) |
Swap minimumValueToBuy (0x02, 0x17) | FLOOR | Keeps minimum output at or below integer pool output after slippage |
Swap maximumValueToSell (0x04, 0x18) | CEIL | Covers integer pool input required for an exact-output swap |
Linear USD-pip -> gasCoin fee estimate | CEIL | Prevents 1 pip fee shortfalls during tariff conversion |
| Orderbook level aggregation | CEIL (Asks) / FLOOR (Bids) | Prevents aggregated bid and ask levels from visually crossing |
| Informational fiat display estimates | HALF_UP | Symmetric rounding for display-only summaries |
parsePip accepts a decimal string using "." (underscore digit separators "_" are accepted; commas "," throw SyntaxError). Fractional parts exceeding 18 digits throw RangeError unless rounding is explicitly specified.
import {
ROUNDING,
divRoundBigInt,
estimateAmmOutPip,
estimatePairV2SwapOutPip,
formatPip,
parsePip,
} from "@minter-network/tx-core";
const sendPip = parsePip("1250.50"); // 1250500000000000000000n
const label = formatPip(sendPip, {
decimals: 2,
trimTrailingZeros: false,
groupThousands: true,
rounding: ROUNDING.FLOOR,
}); // "1,250.50"
const pureAmmOutPip = estimateAmmOutPip(
360_800_059_585_227_604_406n,
3_986_063_084_606_142_908_469_809n,
parsePip("100"),
);
const pairV2OutPip = estimatePairV2SwapOutPip(
360_800_059_585_227_604_406n,
3_986_063_084_606_142_908_469_809n,
parsePip("100"),
);
const minBuyPip = divRoundBigInt(pairV2OutPip * 995n, 1000n, ROUNDING.FLOOR);Transaction builders and envelope (tx)
The tx module exports generic buildTx(type, data, options), flat and two-argument typed builders (buildSendTx, buildSellSwapPoolTx, buildCreateTokenTx, buildCreateMultisigTx, buildRedeemCheckTx, and builders for the remaining active types, 37 in total), plus low-level encodeTxData / decodeTxData codecs (including data-only RLP helpers for inactive 0x13 PRICE_VOTE, empty list 0xc0 for 0x25 LOCK_STAKE, and uint32 dueBlock for 0x26 LOCK).
Outer envelope fields in TxEnvelopeOptions:
nonce(bigint | number): sequential account countertransaction_count + 1n(uint64).chainId(1 | 2):1for Mainnet,2for Testnet.gasPrice(number): gas price multiplier (uint32, defaults to1;RedeemCheckrequires1).gasCoin(number): numeric fee coin ID (uint32,0=BIPencodes as RLP0x80).payload(string | Uint8Array): optional UTF-8 or binary memo up to10_000bytes (+$0.0002per byte).serviceData(string | Uint8Array): optional arbitrary metadata up to128bytes (charged per byte on the same schedule aspayload).signatureType(1 | 2):1for single signature (Single),2for weighted multisig (Multisig).
Byte-level 10-field RLP rules and cross-language porting examples are covered in Test vectors and porting; full opcode schemas are listed in Transaction registry (0x01..0x26).
import {
SecretLeakGuard,
TX_TYPE,
buildSellSwapPoolTx,
decodeRawTx,
parsePip,
signTx,
} from "@minter-network/tx-core";
// Supply these inputs from your application.
declare const privateKeyBytes: Uint8Array;
const userMemo = "swap:arb-cycle-42";
SecretLeakGuard.assertSafePublicText(userMemo);
// 2-pool swap route: USDTE (1993) -> BIP (0) -> HUB (1902).
// Base 2-pool fee $0.035 + 17 payload bytes ($0.0034) = $0.0384 in USDTE equivalent.
const unsigned = buildSellSwapPoolTx(
{
coins: [1993, 0, 1902],
valueToSellPip: parsePip("250"),
minimumValueToBuyPip: parsePip("13.45"),
},
{
nonce: 42n,
chainId: 1,
gasPrice: 1,
gasCoin: 1993,
payload: userMemo,
serviceData: new Uint8Array(0),
},
);
const signed = signTx(unsigned, privateKeyBytes);
const decoded = decodeRawTx(signed.signedRawTxBytes);
console.log(decoded.type === TX_TYPE.SELL_SWAP_POOL, decoded.sender, signed.txHash);Keys, buffer wiping and SecretLeakGuard (wallet)
deriveWalletFromMnemonic(mnemonic, accountIndex, passphrase) derives keys along m/44'/60'/0'/0/{accountIndex} and wipes intermediate BIP-39 seed buffers. Zeroize wallet.privateKey.fill(0) in a finally block after signing (JavaScript strings such as privateKeyHex are immutable in memory, so pass Uint8Array keys in security-sensitive workers).
SecretLeakGuard (SecretLeakGuard.inspect and SecretLeakGuard.assertSafePublicText) scans public payload and memo inputs before broadcast and rejects the input when it detects:
- A sequence of
>= 12consecutive valid English BIP-39 mnemonic words (avoiding false positives on ordinary 2-to-3-word phrases). - A bare or
0x-prefixed 64-character hexadecimal private key, excluding publicMp...andMt...identifiers. - An unredeemed
Mc...check string.
MinterGateClient and transfer verification (gate-client)
MinterGateClient wraps Node Gate API v2 reads and transaction broadcast with AbortController timeouts and typed MinterGateError exceptions:
getStatus(),getAddress(address, delegated?), andgetNextNonce(address)read node status, account state, and the next accountnonce.getCoinInfo(symbol, height?)andgetCoinInfoById(id, height?)look up coin metadata.estimateTxCommission(signedTx)callsGET /v2/estimate_tx_commission/{0x...}(near the10_000-bytepayloadcap, the hex URL reaches ~20 KB and can exceed reverse-proxy URL limits withHTTP 414).sendTransaction(signedTx)submitsPOST /v2/send_transactionand returns mempoolCheckTxadmission.getTransaction(hash)readsGET /v2/transaction/{hash}.waitForTransaction(hash, { timeoutMs, pollMs })polls until block inclusion, including after HTTP404and400not-found responses, and checks the execution code by default.verifyIncomingTransfervalidates a committedSend (0x01)with execution code"0"or0, positive block height, case-insensitive recipient match, numericcoinId, minimumpipvalue, expectedpayloadmemo, and replay deduplication against aSetof consumedMt...hashes.
import {
MinterGateClient,
parsePip,
verifyIncomingTransfer,
} from "@minter-network/tx-core";
import type { MtHash } from "@minter-network/tx-core";
// Supply these inputs from your application.
declare const txHash: MtHash;
const gate = new MinterGateClient(
process.env.MINTER_GATE_URL ?? "https://gate.minter.network/v2",
);
const processedTxHashes = new Set<string>();
const committedTx = await gate.waitForTransaction(txHash, {
timeoutMs: 15_000,
pollMs: 1_000,
});
const verification = verifyIncomingTransfer(committedTx, {
merchantAddress: "Mx3a7b9104e82d19c64f01b5a8e9c72104d3e811f0",
expectedCoinId: 1993,
minAmountPip: parsePip("25.50"),
expectedPayload: "order:INV-2026-8841",
processedTxHashes,
});