SubAccount
Defined in: packages/ledger-icp/src/account_identifier.ts:140
A subaccount in the ICP ledger is a 32-byte identifier that allows a principal (user or canister) to control multiple independent accounts under the same principal.
https://internetcomputer.org/docs/references/ledger#_accounts
Methods
Section titled “Methods”toUint8Array()
Section titled “toUint8Array()”toUint8Array():
Uint8Array
Defined in: packages/ledger-icp/src/account_identifier.ts:218
Returns the raw 32-byte Uint8Array representing this subaccount.
Returns
Section titled “Returns”Uint8Array
A 32-byte array.
fromBytes()
Section titled “fromBytes()”
staticfromBytes(bytes):SubAccount
Defined in: packages/ledger-icp/src/account_identifier.ts:150
Creates a SubAccount from a 32‑byte array.
Parameters
Section titled “Parameters”Uint8Array
A Uint8Array of exactly 32 bytes.
Returns
Section titled “Returns”SubAccount
A SubAccount instance.
Throws
Section titled “Throws”If the byte array length is not 32.
fromID()
Section titled “fromID()”
staticfromID(id):SubAccount
Defined in: packages/ledger-icp/src/account_identifier.ts:189
Generates a SubAccount from a non‑negative number.
The number is encoded into the last 8 bytes of the 32‑byte array. This is a common pattern when using numbered subaccounts like 0, 1, 2…
Parameters
Section titled “Parameters”number
A non-negative integer.
Returns
Section titled “Returns”SubAccount
A SubAccount instance.
Throws
Section titled “Throws”If the number is negative or exceeds Number.MAX_SAFE_INTEGER.
fromPrincipal()
Section titled “fromPrincipal()”
staticfromPrincipal(principal):SubAccount
Defined in: packages/ledger-icp/src/account_identifier.ts:166
Generates a SubAccount from a principal.
The principal is embedded into the beginning of a 32‑byte array.
Parameters
Section titled “Parameters”principal
Section titled “principal”Principal
A principal to encode into the subaccount.
Returns
Section titled “Returns”SubAccount
A SubAccount instance.