Skip to main content
Counter tracking transactions sent from an account. Used for ordering and replay protection.
import * as Nonce from 'voltaire-effect/primitives/Nonce'
import * as Schema from 'effect/Schema'
import { Effect } from 'effect'

// Schema: bigint, number, or string
const nonce = Schema.decodeSync(Nonce.BigInt)(42n)
const fromNumber = Schema.decodeSync(Nonce.Number)(0)

// Effect
const program = Nonce.from(42n)
// Effect.Effect<NonceType, UintError>

Usage

const buildTransaction = (currentNonce: bigint) =>
  Effect.gen(function* () {
    const nonce = yield* Nonce.from(currentNonce)
    return { nonce, /* ... */ }
  })
Fails on negative values.