Validators
Zod schemas for validating Ethereum primitives.
import { Validators } from '@sceneinfrastructure/sdk'Schemas
ethAddress
Validates and transforms Ethereum addresses. Uses ox for validation.
import { Validators } from '@sceneinfrastructure/sdk'
const result = Validators.ethAddress.safeParse('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')
if (result.success) {
console.log('Valid address:', result.data)
}
// Invalid address
const invalid = Validators.ethAddress.safeParse('0xinvalid')
// invalid.success === falseethTxHash
Validates Ethereum transaction hashes (66-character hex strings).
import { Validators } from '@sceneinfrastructure/sdk'
const txHash = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
const result = Validators.ethTxHash.safeParse(txHash)
if (result.success) {
console.log('Valid transaction hash')
}hash
Validates 66-character hash strings (bytes32).
import { Validators } from '@sceneinfrastructure/sdk'
const bytes32 = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
const result = Validators.hash.safeParse(bytes32)hex
Validates and transforms hex strings with 0x prefix.
import { Validators } from '@sceneinfrastructure/sdk'
const result = Validators.hex.safeParse('0xdeadbeef')
if (result.success) {
console.log('Valid hex:', result.data) // '0xdeadbeef'
}uint256
Coerces values to bigint for uint256 fields.
import { Validators } from '@sceneinfrastructure/sdk'
// Accepts strings, numbers, or bigints
const fromString = Validators.uint256.parse('1000000')
const fromNumber = Validators.uint256.parse(1000000)
const fromBigint = Validators.uint256.parse(1000000n)
// All result in: 1000000nUsage with Zod
Combine with other Zod schemas for complex validation:
import { z } from 'zod'
import { Validators } from '@sceneinfrastructure/sdk'
const transferSchema = z.object({
from: Validators.ethAddress,
to: Validators.ethAddress,
amount: Validators.uint256,
txHash: Validators.ethTxHash.optional(),
})
const transfer = transferSchema.parse({
from: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
to: '0x1234567890123456789012345678901234567890',
amount: '1000000000000000000',
})