> ## 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.

# Hardfork.toString

> Convert hardfork to canonical string name

<Card title="Try it Live" icon="play" href="https://playground.tevm.sh?example=primitives/hardfork.ts">
  Run Hardfork examples in the interactive playground
</Card>

<Tabs />

## Canonical Names

Returns canonical name (not aliases):

```typescript theme={null}
import { Hardfork } from 'tevm'

const merge = Hardfork("merge")
const paris = Hardfork("paris")  // Alias

Hardfork.toString(merge)   // "merge"
Hardfork.toString(paris)   // "merge" (canonical, not "paris")
```

### Alias Mapping

| Input Alias       | Canonical Output |
| ----------------- | ---------------- |
| paris             | merge            |
| constantinoplefix | petersburg       |

## Usage Patterns

### Display Names

Convert for user display:

```typescript theme={null}
import { Hardfork } from 'tevm'

function displayHardfork(fork: BrandedHardfork): string {
  const name = Hardfork.toString(fork)
  return name.charAt(0).toUpperCase() + name.slice(1)
}

displayHardfork(CANCUN)  // "Cancun"
displayHardfork(MERGE)   // "Merge"
```

### Logging

Log current hardfork:

```typescript theme={null}
import { Hardfork } from 'tevm'

function logHardforkInfo(fork: BrandedHardfork) {
  console.log(`Current hardfork: ${Hardfork.toString(fork)}`)
  console.log(`EIP-1559: ${fork.hasEIP1559()}`)
  console.log(`PUSH0: ${fork.hasEIP3855()}`)
  console.log(`Blobs: ${fork.hasEIP4844()}`)
}
```

### Configuration Serialization

Normalize for storage:

```typescript theme={null}
import { Hardfork } from 'tevm'

function saveConfig(fork: BrandedHardfork) {
  const config = {
    hardfork: Hardfork.toString(fork),  // Canonical name
    timestamp: Date.now()
  }

  localStorage.setItem("config", JSON.stringify(config))
}

// Load and parse
function loadConfig() {
  const data = JSON.parse(localStorage.getItem("config"))
  return Hardfork(data.hardfork)
}
```

### API Responses

Serialize for API:

```typescript theme={null}
import { Hardfork } from 'tevm'

function getNetworkInfo(fork: BrandedHardfork) {
  return {
    hardfork: Hardfork.toString(fork),
    consensus: fork.isPostMerge() ? "pos" : "pow",
    features: {
      eip1559: fork.hasEIP1559(),
      push0: fork.hasEIP3855(),
      blobs: fork.hasEIP4844()
    }
  }
}
```

### Comparison Keys

Use as map keys:

```typescript theme={null}
import { Hardfork } from 'tevm'

const featureMatrix = new Map<string, Features>()

function addHardforkFeatures(fork: BrandedHardfork, features: Features) {
  const key = Hardfork.toString(fork)
  featureMatrix.set(key, features)
}

function getHardforkFeatures(fork: BrandedHardfork): Features | undefined {
  const key = Hardfork.toString(fork)
  return featureMatrix.get(key)
}
```

## Format

**Lowercase:**

* All names lowercase
* Consistent formatting

**No Spaces:**

* Single word (no spaces)
* Examples: "cancun", "shanghai", "tangerinewhistle"

**Complete List:**

```typescript theme={null}
"frontier"
"homestead"
"dao"
"tangerinewhistle"
"spuriousdragon"
"byzantium"
"constantinople"
"petersburg"
"istanbul"
"muirglacier"
"berlin"
"london"
"arrowglacier"
"grayglacier"
"merge"
"shanghai"
"cancun"
"prague"
"osaka"
```

## Normalization

Always use `toString` for storage/comparison:

```typescript theme={null}
import { Hardfork } from 'tevm'

// Good - normalized
function saveHardfork(fork: BrandedHardfork) {
  const normalized = Hardfork.toString(fork)
  storage.set("hardfork", normalized)  // "merge" not "paris"
}

// Bad - storing alias
function saveHardforkBad(input: string) {
  storage.set("hardfork", input)  // Might be "Paris" or "MERGE"
}
```

## Inverse Operation

`fromString` is the inverse:

```typescript theme={null}
import { Hardfork } from 'tevm'

const fork = Hardfork.fromString("cancun")
const name = Hardfork.toString(fork)
const fork2 = Hardfork.fromString(name)

Hardfork.equals(fork, fork2)  // true - round trip works
```

## Performance

**Time Complexity:** O(1) - Direct return (hardforks are already strings internally)

**Typical Time:** \~20-40ns per call

## See Also

* [fromString](/primitives/hardfork/from-string) - Parse hardfork from string (inverse)
* [allNames](/primitives/hardfork/all-names) - Get all hardfork names
* [isValidName](/primitives/hardfork/is-valid-name) - Validate hardfork name
