Copy
Ask AI
import * as GasUsed from 'voltaire-effect/primitives/GasUsed'
import * as Schema from 'effect/Schema'
import { Effect } from 'effect'
// Schema
const used = Schema.decodeSync(GasUsed.BigInt)(21000n)
// Effect
const program = GasUsed.from(21000n)
// Effect.Effect<GasUsedType, GasUsedError>
// Calculate cost
const cost = Effect.runSync(GasUsed.calculateCost(21000n, 1000000000n))
// → 21000000000000n wei (21000 gwei)
Usage
Copy
Ask AI
const getTransactionCost = (gasUsed: bigint, gweiPrice: number) =>
Effect.gen(function* () {
const price = yield* GasPrice.fromGwei(gweiPrice)
return yield* GasUsed.calculateCost(gasUsed, price)
})

