[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Type](https://evolu.dev/docs/api-reference/common/Type) › Ipv6AddressFromString

```ts
const Ipv6AddressFromString: transform(
  "Ipv6AddressFromString",
  String,
  Ipv6Address,
  {
    from: (value: string): Result<string, Ipv6AddressFromStringError> => {
      const canonical = canonicalizeIpv6Address(value);
      return canonical === undefined
        ? err({ type: "Ipv6AddressFromString", value })
        : ok(canonical);
    },
    to: (value: Ipv6Address) => value,
  },
  formatIpv6AddressFromStringError,
);
```

Defined in: [packages/common/src/Type.ts:9427](https://github.com/evoluhq/evolu/blob/bc4578a260dd15d5bbf94b83765ca05984d194cb/packages/common/src/Type.ts#L9427)

Transforms IPv6 address text into its canonical [Ipv6Address](https://evolu.dev/docs/api-reference/common/Type/variables/Ipv6Address).

Accepts the text forms of [RFC 4291 section
2.2](https://www.rfc-editor.org/rfc/rfc4291#section-2.2): eight groups of one
to four hexadecimal digits in either case, at most one `::` replacing one or
more zero groups, and an optional trailing dotted IPv4 address that follows
the [Ipv4Address](https://evolu.dev/docs/api-reference/common/Type/variables/Ipv4Address) rules. Like Ipv6Address, it rejects zone identifiers,
brackets, prefix lengths, and whitespace.

Encoding returns the canonical text, not the original spelling.

### Example

```ts
import {
  assertEqual,
  assertErr,
  assertOk,
  Ipv6AddressFromString,
} from "@evolu/common";

assertOk(
  Ipv6AddressFromString.fromUnknown("2001:0DB8:0:0:0:0:0:1"),
  "2001:db8::1",
);
assertOk(Ipv6AddressFromString.fromUnknown("::ffff:102:304"), "::ffff:1.2.3.4");

const invalid = Ipv6AddressFromString.fromUnknown("fe80::1%eth0");
assertErr(invalid, {
  type: "Ipv6AddressFromString",
  value: "fe80::1%eth0",
});
assertEqual(
  Ipv6AddressFromString.formatError(invalid.error),
  'The value "fe80::1%eth0" is not a valid IPv6 address.',
);
```