Skip to main content
import * as RuntimeCode from 'voltaire-effect/primitives/RuntimeCode'
import * as Schema from 'effect/Schema'
import { Effect } from 'effect'

// Schema decode
const code = Schema.decodeSync(RuntimeCode.Hex)('0x6080604052...')

// Effect constructors
const fromHex = RuntimeCode.fromHex('0x6080604052...')
const fromAny = RuntimeCode.from(bytecodeBytes)

const runtime = Effect.runSync(fromHex)

Type

type RuntimeCodeType = Uint8Array & { readonly __brand: 'RuntimeCode' }

API

FunctionType
SchemaSchema<RuntimeCodeType, string | Uint8Array>
from(input: string | Uint8Array) => Effect<RuntimeCodeType, RuntimeCodeError>
fromHex(hex: string) => Effect<RuntimeCodeType, RuntimeCodeError>

Error Handling

const result = await Effect.runPromiseExit(RuntimeCode.fromHex('invalid'))
if (result._tag === 'Failure') console.error('Invalid bytecode')