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

primitives/TokenId

Classes

InvalidTokenIdError

Defined in: src/primitives/TokenId/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 InvalidTokenIdError(message, options?): InvalidTokenIdError
Defined in: src/primitives/TokenId/errors.ts:24
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
expected?
string
value?
unknown
Returns
InvalidTokenIdError
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

TokenIdError

Defined in: src/primitives/TokenId/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 TokenIdError(message, options?): TokenIdError
Defined in: src/primitives/TokenId/errors.ts:4
Parameters
message
string
options?
cause?
Error
code?
string
context?
Record<string, unknown>
docsPath?
string
Returns
TokenIdError
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

TokenIdType

TokenIdType = bigint & object
Defined in: src/primitives/TokenId/TokenIdType.ts:10 TokenId type - ERC-721 NFT token identifier

Type Declaration

[brand]
readonly [brand]: "TokenId"

See

Since

0.0.0

Variables

compare()

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

Parameters

a
TokenIdType First TokenId
b
TokenIdType Second TokenId

Returns

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

See

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

Since

0.0.0

Example

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

constants

const constants: object
Defined in: src/primitives/TokenId/index.ts:26

Type Declaration

MAX
MAX: bigint
Maximum TokenId value (2^256 - 1)
MIN
MIN: bigint
Minimum TokenId value (0)

equals()

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

Parameters

a
TokenIdType First TokenId
b
TokenIdType Second TokenId

Returns

boolean true if equal

See

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

Since

0.0.0

Example

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

ERC721_SELECTORS

const ERC721_SELECTORS: object
Defined in: src/primitives/TokenId/index.ts:32

Type Declaration

approve
readonly approve: "0x095ea7b3" = "0x095ea7b3"
balanceOf
readonly balanceOf: "0x70a08231" = "0x70a08231"
getApproved
readonly getApproved: "0x081812fc" = "0x081812fc"
isApprovedForAll
readonly isApprovedForAll: "0xe985e9c5" = "0xe985e9c5"
ownerOf
readonly ownerOf: "0x6352211e" = "0x6352211e"
safeTransferFrom
readonly safeTransferFrom: "0x42842e0e" = "0x42842e0e"
setApprovalForAll
readonly setApprovalForAll: "0xa22cb465" = "0xa22cb465"
transferFrom
readonly transferFrom: "0x23b872dd" = "0x23b872dd"

from()

const from: (value) => TokenIdType = _from
Defined in: src/primitives/TokenId/index.ts:17 Create TokenId from bigint, number, or string

Parameters

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

Returns

TokenIdType TokenId value

See

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

Since

0.0.0

Throws

If value is out of range or invalid

Example

import * as TokenId from './primitives/TokenId/index.js';
const tokenId = TokenId.from(42n);
const fromNumber = TokenId.from(100);
const fromHex = TokenId.from("0xff");

isValid()

const isValid: (tokenId) => boolean = _isValid
Defined in: src/primitives/TokenId/index.ts:23 Check if TokenId is valid (non-zero)

Parameters

tokenId
TokenIdType TokenId value to check

Returns

boolean true if valid (non-zero)

See

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

Since

0.0.0

Example

import * as TokenId from './primitives/TokenId/index.js';
const tokenId = TokenId.from(42n);
const valid = TokenId.isValid(tokenId); // true
const zero = TokenId.from(0n);
const invalid = TokenId.isValid(zero); // false

toBigInt()

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

Parameters

tokenId
TokenIdType TokenId value to convert

Returns

bigint bigint value

See

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

Since

0.0.0

Example

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

toHex()

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

Parameters

tokenId
TokenIdType TokenId value to convert

Returns

string Hex string with 0x prefix

See

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

Since

0.0.0

Example

import * as TokenId from './primitives/TokenId/index.js';
const tokenId = TokenId.from(42n);
const hex = TokenId.toHex(tokenId); // "0x2a"

toNumber()

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

Parameters

tokenId
TokenIdType TokenId value to convert

Returns

number number value

See

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

Since

0.0.0

Throws

If value exceeds Number.MAX_SAFE_INTEGER

Example

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

Functions

_compare()

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

Parameters

a
TokenIdType First TokenId
b
TokenIdType Second TokenId

Returns

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

See

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

Since

0.0.0

Example

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

_equals()

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

Parameters

a
TokenIdType First TokenId
b
TokenIdType Second TokenId

Returns

boolean true if equal

See

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

Since

0.0.0

Example

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

_from()

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

Parameters

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

Returns

TokenIdType TokenId value

See

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

Since

0.0.0

Throws

If value is out of range or invalid

Example

import * as TokenId from './primitives/TokenId/index.js';
const tokenId = TokenId.from(42n);
const fromNumber = TokenId.from(100);
const fromHex = TokenId.from("0xff");

_isValid()

_isValid(tokenId): boolean
Defined in: src/primitives/TokenId/isValid.js:17 Check if TokenId is valid (non-zero)

Parameters

tokenId
TokenIdType TokenId value to check

Returns

boolean true if valid (non-zero)

See

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

Since

0.0.0

Example

import * as TokenId from './primitives/TokenId/index.js';
const tokenId = TokenId.from(42n);
const valid = TokenId.isValid(tokenId); // true
const zero = TokenId.from(0n);
const invalid = TokenId.isValid(zero); // false

_toBigInt()

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

Parameters

tokenId
TokenIdType TokenId value to convert

Returns

bigint bigint value

See

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

Since

0.0.0

Example

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

_toHex()

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

Parameters

tokenId
TokenIdType TokenId value to convert

Returns

string Hex string with 0x prefix

See

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

Since

0.0.0

Example

import * as TokenId from './primitives/TokenId/index.js';
const tokenId = TokenId.from(42n);
const hex = TokenId.toHex(tokenId); // "0x2a"

_toNumber()

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

Parameters

tokenId
TokenIdType TokenId value to convert

Returns

number number value

See

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

Since

0.0.0

Throws

If value exceeds Number.MAX_SAFE_INTEGER

Example

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