Copy
Ask AI
import * as GasPrice from 'voltaire-effect/primitives/GasPrice'
import * as Schema from 'effect/Schema'
import { Effect } from 'effect'
// Schema (wei)
const price = Schema.decodeSync(GasPrice.BigInt)(1000000000n) // 1 gwei
// Schema (gwei → wei)
const fromGwei = Schema.decodeSync(GasPrice.FromGweiSchema)(20)
// → 20000000000n wei
// Effect
const program = GasPrice.fromGwei(20)
// Effect.Effect<GasPriceType, GasPriceError>
Usage
Copy
Ask AI
const calculateCost = (gasUsed: bigint, gweiPrice: number) =>
Effect.gen(function* () {
const price = yield* GasPrice.fromGwei(gweiPrice)
return gasUsed * price // cost in wei
})

