Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/MultiTokenId

primitives/MultiTokenId

Classes

InvalidMultiTokenIdError

Defined in: src/primitives/MultiTokenId/errors.ts:23 Base validation error

Example

throw new ValidationError('Invalid value', {
  value: '0x123',
  expected: '20 bytes',
  code: 'VALIDATION_ERROR',
  docsPath: '/primitives/address/from-hex#error-handling',
  cause: originalError
})

Extends

Constructors

Constructor
new InvalidMultiTokenIdError(message, options?): InvalidMultiTokenIdError
Defined in: src/primitives/MultiTokenId/errors.ts:24
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
expected?
string
value?
unknown
Returns
InvalidMultiTokenIdError
Overrides
ValidationError.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
ValidationError.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
ValidationError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
ValidationError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
Inherited from
ValidationError.docsPath
expected
expected: string
Defined in: src/primitives/errors/ValidationError.ts:19
Inherited from
ValidationError.expected
value
value: unknown
Defined in: src/primitives/errors/ValidationError.ts:18
Inherited from
ValidationError.value

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
ValidationError.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
ValidationError.toJSON

MultiTokenIdError

Defined in: src/primitives/MultiTokenId/errors.ts:3 Base error for all primitive-related errors

Example

throw new PrimitiveError('Invalid primitive value', {
  code: 'INVALID_PRIMITIVE',
  context: { value: '0x123' },
  docsPath: '/primitives/overview#errors'
})

Extends

Constructors

Constructor
new MultiTokenIdError(message, options?): MultiTokenIdError
Defined in: src/primitives/MultiTokenId/errors.ts:4
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
MultiTokenIdError
Overrides
PrimitiveError.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
PrimitiveError.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
PrimitiveError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
PrimitiveError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
Inherited from
PrimitiveError.docsPath

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
PrimitiveError.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
PrimitiveError.toJSON

Type Aliases

MultiTokenIdType

MultiTokenIdType = bigint & object
Defined in: src/primitives/MultiTokenId/MultiTokenIdType.ts:10 MultiTokenId type - ERC-1155 token type identifier

Type Declaration

[brand]
readonly [brand]: "MultiTokenId"

See

Since

0.0.0

Variables

compare()

const compare: (a, b) => number = _compare
Defined in: src/primitives/MultiTokenId/index.ts:32 Compare two MultiTokenId values

Parameters

a
MultiTokenIdType First MultiTokenId
b
MultiTokenIdType Second MultiTokenId

Returns

number -1 if a < b, 0 if a === b, 1 if a > b

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const a = MultiTokenId.from(1n);
const b = MultiTokenId.from(100n);
const result = MultiTokenId.compare(a, b); // -1

constants

const constants: object
Defined in: src/primitives/MultiTokenId/index.ts:37

Type Declaration

FUNGIBLE_THRESHOLD
FUNGIBLE_THRESHOLD: bigint
Fungible token threshold (by convention) Token IDs below this are often fungible (like ERC-20) Token IDs at or above are often non-fungible (like ERC-721)
MAX
MAX: bigint
Maximum MultiTokenId value (2^256 - 1)
MIN
MIN: bigint
Minimum MultiTokenId value (0)

equals()

const equals: (a, b) => boolean = _equals
Defined in: src/primitives/MultiTokenId/index.ts:31 Check if two MultiTokenId values are equal

Parameters

a
MultiTokenIdType First MultiTokenId
b
MultiTokenIdType Second MultiTokenId

Returns

boolean true if equal

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const a = MultiTokenId.from(1n);
const b = MultiTokenId.from(1n);
const result = MultiTokenId.equals(a, b); // true

ERC1155_SELECTORS

const ERC1155_SELECTORS: object
Defined in: src/primitives/MultiTokenId/index.ts:44

Type Declaration

balanceOf
readonly balanceOf: "0x00fdd58e" = "0x00fdd58e"
balanceOfBatch
readonly balanceOfBatch: "0x4e1273f4" = "0x4e1273f4"
isApprovedForAll
readonly isApprovedForAll: "0xe985e9c5" = "0xe985e9c5"
safeBatchTransferFrom
readonly safeBatchTransferFrom: "0x2eb2c2d6" = "0x2eb2c2d6"
safeTransferFrom
readonly safeTransferFrom: "0xf242432a" = "0xf242432a"
setApprovalForAll
readonly setApprovalForAll: "0xa22cb465" = "0xa22cb465"
uri
readonly uri: "0x0e89341c" = "0x0e89341c"

from()

const from: (value) => MultiTokenIdType = _from
Defined in: src/primitives/MultiTokenId/index.ts:27 Create MultiTokenId from bigint, number, or string

Parameters

value
bigint, number, or decimal/hex string string | number | bigint

Returns

MultiTokenIdType MultiTokenId value

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Throws

If value is out of range or invalid

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const tokenId = MultiTokenId.from(1n); // Fungible token type
const nftId = MultiTokenId.from(2n ** 128n); // Non-fungible token type
const fromHex = MultiTokenId.from("0xff");

isValidFungible()

const isValidFungible: (tokenId) => boolean = _isValidFungible
Defined in: src/primitives/MultiTokenId/index.ts:33 Check if MultiTokenId is valid for fungible tokens (below threshold)

Parameters

tokenId
MultiTokenIdType MultiTokenId value to check

Returns

boolean true if likely fungible (below 2^128)

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const fungible = MultiTokenId.from(1n);
const isFungible = MultiTokenId.isValidFungible(fungible); // true
const nonFungible = MultiTokenId.from(2n ** 128n);
const notFungible = MultiTokenId.isValidFungible(nonFungible); // false

isValidNonFungible()

const isValidNonFungible: (tokenId) => boolean = _isValidNonFungible
Defined in: src/primitives/MultiTokenId/index.ts:34 Check if MultiTokenId is valid for non-fungible tokens (at or above threshold)

Parameters

tokenId
MultiTokenIdType MultiTokenId value to check

Returns

boolean true if likely non-fungible (>= 2^128)

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const nonFungible = MultiTokenId.from(2n ** 128n);
const isNFT = MultiTokenId.isValidNonFungible(nonFungible); // true
const fungible = MultiTokenId.from(1n);
const notNFT = MultiTokenId.isValidNonFungible(fungible); // false

toBigInt()

const toBigInt: (tokenId) => bigint = _toBigInt
Defined in: src/primitives/MultiTokenId/index.ts:29 Convert MultiTokenId to bigint

Parameters

tokenId
MultiTokenIdType MultiTokenId value to convert

Returns

bigint bigint value

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const tokenId = MultiTokenId.from(1n);
const bigint = MultiTokenId.toBigInt(tokenId); // 1n

toHex()

const toHex: (tokenId) => string = _toHex
Defined in: src/primitives/MultiTokenId/index.ts:30 Convert MultiTokenId to hex string

Parameters

tokenId
MultiTokenIdType MultiTokenId value to convert

Returns

string Hex string with 0x prefix

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const tokenId = MultiTokenId.from(1n);
const hex = MultiTokenId.toHex(tokenId); // "0x1"

toNumber()

const toNumber: (tokenId) => number = _toNumber
Defined in: src/primitives/MultiTokenId/index.ts:28 Convert MultiTokenId to number (unsafe for large values)

Parameters

tokenId
MultiTokenIdType MultiTokenId value to convert

Returns

number number value

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Throws

If value exceeds Number.MAX_SAFE_INTEGER

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const tokenId = MultiTokenId.from(1n);
const num = MultiTokenId.toNumber(tokenId); // 1

Functions

_compare()

_compare(a, b): number
Defined in: src/primitives/MultiTokenId/compare.js:17 Compare two MultiTokenId values

Parameters

a
MultiTokenIdType First MultiTokenId
b
MultiTokenIdType Second MultiTokenId

Returns

number -1 if a < b, 0 if a === b, 1 if a > b

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const a = MultiTokenId.from(1n);
const b = MultiTokenId.from(100n);
const result = MultiTokenId.compare(a, b); // -1

_equals()

_equals(a, b): boolean
Defined in: src/primitives/MultiTokenId/equals.js:17 Check if two MultiTokenId values are equal

Parameters

a
MultiTokenIdType First MultiTokenId
b
MultiTokenIdType Second MultiTokenId

Returns

boolean true if equal

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const a = MultiTokenId.from(1n);
const b = MultiTokenId.from(1n);
const result = MultiTokenId.equals(a, b); // true

_from()

_from(value): MultiTokenIdType
Defined in: src/primitives/MultiTokenId/from.js:20 Create MultiTokenId from bigint, number, or string

Parameters

value
bigint, number, or decimal/hex string string | number | bigint

Returns

MultiTokenIdType MultiTokenId value

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Throws

If value is out of range or invalid

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const tokenId = MultiTokenId.from(1n); // Fungible token type
const nftId = MultiTokenId.from(2n ** 128n); // Non-fungible token type
const fromHex = MultiTokenId.from("0xff");

_isValidFungible()

_isValidFungible(tokenId): boolean
Defined in: src/primitives/MultiTokenId/isValidFungible.js:19 Check if MultiTokenId is valid for fungible tokens (below threshold)

Parameters

tokenId
MultiTokenIdType MultiTokenId value to check

Returns

boolean true if likely fungible (below 2^128)

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const fungible = MultiTokenId.from(1n);
const isFungible = MultiTokenId.isValidFungible(fungible); // true
const nonFungible = MultiTokenId.from(2n ** 128n);
const notFungible = MultiTokenId.isValidFungible(nonFungible); // false

_isValidNonFungible()

_isValidNonFungible(tokenId): boolean
Defined in: src/primitives/MultiTokenId/isValidNonFungible.js:19 Check if MultiTokenId is valid for non-fungible tokens (at or above threshold)

Parameters

tokenId
MultiTokenIdType MultiTokenId value to check

Returns

boolean true if likely non-fungible (>= 2^128)

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const nonFungible = MultiTokenId.from(2n ** 128n);
const isNFT = MultiTokenId.isValidNonFungible(nonFungible); // true
const fungible = MultiTokenId.from(1n);
const notNFT = MultiTokenId.isValidNonFungible(fungible); // false

_toBigInt()

_toBigInt(tokenId): bigint
Defined in: src/primitives/MultiTokenId/toBigInt.js:15 Convert MultiTokenId to bigint

Parameters

tokenId
MultiTokenIdType MultiTokenId value to convert

Returns

bigint bigint value

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const tokenId = MultiTokenId.from(1n);
const bigint = MultiTokenId.toBigInt(tokenId); // 1n

_toHex()

_toHex(tokenId): string
Defined in: src/primitives/MultiTokenId/toHex.js:15 Convert MultiTokenId to hex string

Parameters

tokenId
MultiTokenIdType MultiTokenId value to convert

Returns

string Hex string with 0x prefix

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const tokenId = MultiTokenId.from(1n);
const hex = MultiTokenId.toHex(tokenId); // "0x1"

_toNumber()

_toNumber(tokenId): number
Defined in: src/primitives/MultiTokenId/toNumber.js:16 Convert MultiTokenId to number (unsafe for large values)

Parameters

tokenId
MultiTokenIdType MultiTokenId value to convert

Returns

number number value

See

https://voltaire.tevm.sh/primitives/multi-token-id for MultiTokenId documentation

Since

0.0.0

Throws

If value exceeds Number.MAX_SAFE_INTEGER

Example

import * as MultiTokenId from './primitives/MultiTokenId/index.js';
const tokenId = MultiTokenId.from(1n);
const num = MultiTokenId.toNumber(tokenId); // 1