> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# primitives/GasUsed

> Auto-generated API documentation

[**@tevm/voltaire**](../index.mdx)

***

[@tevm/voltaire](../index.mdx) / primitives/GasUsed

# primitives/GasUsed

## Type Aliases

### GasUsedType

> **GasUsedType** = `bigint` & `object`

Defined in: [src/primitives/GasUsed/GasUsedType.ts:8](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/GasUsedType.ts#L8)

Branded GasUsed type - actual gas consumed by transaction
Found in transaction receipts (receipt.gasUsed)
Range: 21000 (minimum transfer) to block gas limit (30M typical)

#### Type Declaration

##### \[brand]

> `readonly` **\[brand]**: `"GasUsed"`

## Variables

### GasUsed

> `const` **GasUsed**: `object`

Defined in: [src/primitives/GasUsed/index.ts:54](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/index.ts#L54)

#### Type Declaration

##### calculateCost()

> **calculateCost**: (`gasUsed`, `gasPrice`) => `bigint`

###### Parameters

###### gasUsed

`string` | `number` | `bigint`

###### gasPrice

`bigint`

###### Returns

`bigint`

##### compare()

> **compare**: (`value1`, `value2`) => `number`

###### Parameters

###### value1

`string` | `number` | `bigint`

###### value2

`string` | `number` | `bigint`

###### Returns

`number`

##### equals()

> **equals**: (`value1`, `value2`) => `boolean`

###### Parameters

###### value1

`string` | `number` | `bigint`

###### value2

`string` | `number` | `bigint`

###### Returns

`boolean`

##### from()

> **from**: (`value`) => [`GasUsedType`](#gasusedtype)

Create GasUsed from number, bigint, or string

###### Parameters

###### value

Gas used value

`string` | `number` | `bigint`

###### Returns

[`GasUsedType`](#gasusedtype)

Branded gas used

###### Throws

If value is negative

###### Example

```typescript theme={null}
const gasUsed = GasUsed.from(51234n);
const fromReceipt = GasUsed.from(receipt.gasUsed);
```

##### toBigInt()

> **toBigInt**: (`value`) => `bigint`

###### Parameters

###### value

`string` | `number` | `bigint`

###### Returns

`bigint`

##### toHex()

> **toHex**: (`value`) => `string`

###### Parameters

###### value

`string` | `number` | `bigint`

###### Returns

`string`

##### toNumber()

> **toNumber**: (`value`) => `number`

###### Parameters

###### value

`string` | `number` | `bigint`

###### Returns

`number`

## Functions

### \_calculateCost()

> **\_calculateCost**(`this`, `gasPrice`): `bigint`

Defined in: [src/primitives/GasUsed/calculateCost.js:15](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/calculateCost.js#L15)

Calculate transaction cost in Wei (gasUsed \* gasPrice)

#### Parameters

##### this

[`GasUsedType`](#gasusedtype)

##### gasPrice

`bigint`

Gas price in Wei

#### Returns

`bigint`

Transaction cost in Wei

#### Example

```typescript theme={null}
const gasUsed = GasUsed.from(51234n);
const gasPrice = 20_000_000_000n; // 20 gwei
GasUsed._calculateCost.call(gasUsed, gasPrice); // 1024680000000000n Wei
```

***

### \_compare()

> **\_compare**(`this`, `other`): `number`

Defined in: [src/primitives/GasUsed/compare.js:15](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/compare.js#L15)

Compare two GasUsed values

#### Parameters

##### this

[`GasUsedType`](#gasusedtype)

##### other

[`GasUsedType`](#gasusedtype)

Other gas used value

#### Returns

`number`

-1 if this \< other, 0 if equal, 1 if this > other

#### Example

```typescript theme={null}
const a = GasUsed.from(21000n);
const b = GasUsed.from(51234n);
GasUsed._compare.call(a, b); // -1
```

***

### \_equals()

> **\_equals**(`this`, `other`): `boolean`

Defined in: [src/primitives/GasUsed/equals.js:15](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/equals.js#L15)

Check if two GasUsed values are equal

#### Parameters

##### this

[`GasUsedType`](#gasusedtype)

##### other

[`GasUsedType`](#gasusedtype)

Other gas used value

#### Returns

`boolean`

True if equal

#### Example

```typescript theme={null}
const a = GasUsed.from(51234n);
const b = GasUsed.from(51234n);
GasUsed._equals.call(a, b); // true
```

***

### \_toBigInt()

> **\_toBigInt**(`this`): `bigint`

Defined in: [src/primitives/GasUsed/toBigInt.js:13](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/toBigInt.js#L13)

Convert GasUsed to bigint (identity, for compatibility)

#### Parameters

##### this

[`GasUsedType`](#gasusedtype)

#### Returns

`bigint`

Gas used as bigint

#### Example

```typescript theme={null}
const gasUsed = GasUsed.from(51234n);
GasUsed.toBigInt(gasUsed); // 51234n
```

***

### \_toHex()

> **\_toHex**(`this`): `string`

Defined in: [src/primitives/GasUsed/toHex.js:13](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/toHex.js#L13)

Convert GasUsed to hex string

#### Parameters

##### this

[`GasUsedType`](#gasusedtype)

#### Returns

`string`

Gas used as hex string (0x prefixed)

#### Example

```typescript theme={null}
const gasUsed = GasUsed.from(51234n);
GasUsed.toHex(gasUsed); // "0xc822"
```

***

### \_toNumber()

> **\_toNumber**(`this`): `number`

Defined in: [src/primitives/GasUsed/toNumber.js:13](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/toNumber.js#L13)

Convert GasUsed to number

#### Parameters

##### this

[`GasUsedType`](#gasusedtype)

#### Returns

`number`

Gas used as number

#### Example

```typescript theme={null}
const gasUsed = GasUsed.from(51234n);
GasUsed.toNumber(gasUsed); // 51234
```

***

### calculateCost()

> **calculateCost**(`gasUsed`, `gasPrice`): `bigint`

Defined in: [src/primitives/GasUsed/index.ts:43](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/index.ts#L43)

#### Parameters

##### gasUsed

`string` | `number` | `bigint`

##### gasPrice

`bigint`

#### Returns

`bigint`

***

### compare()

> **compare**(`value1`, `value2`): `number`

Defined in: [src/primitives/GasUsed/index.ts:36](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/index.ts#L36)

#### Parameters

##### value1

`string` | `number` | `bigint`

##### value2

`string` | `number` | `bigint`

#### Returns

`number`

***

### equals()

> **equals**(`value1`, `value2`): `boolean`

Defined in: [src/primitives/GasUsed/index.ts:29](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/index.ts#L29)

#### Parameters

##### value1

`string` | `number` | `bigint`

##### value2

`string` | `number` | `bigint`

#### Returns

`boolean`

***

### from()

> **from**(`value`): [`GasUsedType`](#gasusedtype)

Defined in: [src/primitives/GasUsed/from.js:16](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/from.js#L16)

Create GasUsed from number, bigint, or string

#### Parameters

##### value

Gas used value

`string` | `number` | `bigint`

#### Returns

[`GasUsedType`](#gasusedtype)

Branded gas used

#### Throws

If value is negative

#### Example

```typescript theme={null}
const gasUsed = GasUsed.from(51234n);
const fromReceipt = GasUsed.from(receipt.gasUsed);
```

***

### toBigInt()

> **toBigInt**(`value`): `bigint`

Defined in: [src/primitives/GasUsed/index.ts:21](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/index.ts#L21)

#### Parameters

##### value

`string` | `number` | `bigint`

#### Returns

`bigint`

***

### toHex()

> **toHex**(`value`): `string`

Defined in: [src/primitives/GasUsed/index.ts:25](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/index.ts#L25)

#### Parameters

##### value

`string` | `number` | `bigint`

#### Returns

`string`

***

### toNumber()

> **toNumber**(`value`): `number`

Defined in: [src/primitives/GasUsed/index.ts:17](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/GasUsed/index.ts#L17)

#### Parameters

##### value

`string` | `number` | `bigint`

#### Returns

`number`
