Skip to main content
Non-negative bigint representing gas amounts.
import { Gas, GasPrice, GasEstimate } from 'voltaire-effect'
import * as Schema from 'effect/Schema'
import { Effect } from 'effect'

// Schema
const gas = Schema.decodeSync(Gas.BigInt)(21000n)

// Effect
const program = Gas.from(21000n)
// Effect.Effect<GasType, Error>

GasPrice

Gas price in wei with gwei conversion.
// From wei
const price = Schema.decodeSync(GasPrice.BigInt)(20000000000n)

// From gwei (auto-converts to wei)
const fromGwei = Schema.decodeSync(GasPrice.FromGweiSchema)(20n)
// → 20000000000n wei

// Effect
const program = GasPrice.fromGwei(20n)

GasEstimate

Gas estimates with buffer calculations.
const program = Effect.gen(function* () {
  const estimate = yield* GasEstimate.from(65000n)
  const buffered = yield* GasEstimate.withBuffer(estimate, 20) // +20%
  const gasLimit = yield* GasEstimate.toGasLimit(buffered)
  return gasLimit // 78000n
})
Fails on negative values.