Skip to main content
4-byte identifier from keccak256 hash of function signature. Identifies which function to call.
import { Selector } from 'voltaire-effect/primitives'
import * as Schema from 'effect/Schema'
import { Effect } from 'effect'

// Schema
const selector = Schema.decodeSync(Selector.Hex)('0xa9059cbb')

// Effect: from hex
const program = Selector.from('0xa9059cbb')
// Effect.Effect<SelectorType, SelectorError>

// From function signature (hashes with keccak256)
const fromSig = Selector.fromSignature('transfer(address,uint256)')
// → 0xa9059cbb

Functions

FunctionDescription
from(hex)From hex string or bytes
fromSignature(sig)Hash function signature
toHex(sel)To hex string
equals(a, b)Compare selectors
const program = Effect.gen(function* () {
  const a = yield* Selector.from('0xa9059cbb')
  const b = yield* Selector.fromSignature('transfer(address,uint256)')
  return yield* Selector.equals(a, b) // true
})