npm package: @metalayer/viem-chains
Description: Viem Chain configurations for Chains and Rollups in the Caldera and Metalayer ecosystem.
Author: Constellation Labs
Latest version: 0.2.10
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

# @metalayer/viem-chains

A collection of [viem](https://github.com/wagmi-dev/viem) `Chain` definitions for the rollups in the Caldera and Metalayer ecosystem.

## Installation

```bash
pnpm add @metalayer/viem-chains
# or with npm
npm install @metalayer/viem-chains
# or with yarn
yarn add @metalayer/viem-chains
```

## Usage

The Chain definitions in this package are fully compatible with viem. Import the chain you want to use in viem and create a client:

```typescript
import { createPublicClient, http } from 'viem';
import { apechain } from '@metalayer/viem-chains';

const client = createPublicClient({
  chain: apechain,
  transport: http(),
});
```

### Recommended Chains

For mainnet and testnet integrations with Caldera's Metalayer, use the following:

```typescript
import { METALAYER_MAINNETS, METALAYER_TESTNETS } from '@metalayer/viem-chains';
```

These provide comprehensive configurations for mainnet and testnet environments.

## CalderaMetadata
We include a [metadata object in our Chains](./src/types.ts) to append some additional information.

In order to access this metadata we provide a type guard function `hasCalderaMetadata` that
validates that the metadata key is present in the chain and type casts the object.

```typescript
import { apechain, hasCalderaMetadata } from '@metalayer/viem-chains';

if (hasCalderaMetadata(apechain)) {
  return apechain.metadata.stack;
}
```

## Solana Support
This package also includes viem style Chain definitions for Solana and SolanaDevnet

```typescript
import { solana, solanaDevnet } from '@metalayer/viem-chains';
```

### Solana IDs
Because Solana doesn't have the concept of a chain id, different providers use their own ids to refer to the network.

In our case the ids are the following:
1. Solana Mainnet - **501494** which stands for SOLANA if you think of the 9 as **N**ine
2. Solana Devnet - **5017357** which stands for SOLTEST

### Utility functions
We provide 2 utility functions `getSolanaConfig` and `isSolana`

```typescript
import { getSolanaConfig, isSolana } from '@metalayer/viem-chains';

function getSolanaConfig(chainId: number): CalderaChain | undefined;
function isSolana(chain: Chain | number): boolean;
```

* `getSolanaConfig` - given a chainId (number), it will return solana, solanaDevnet or undefined
* `isSolana` - given a chainId (number) or a chain (Chain), it will return `true` or `false`
to indicate if the input represents a Solana chain. 

### Provider Ids
As mentioned above, each provider defines their own IDs to refer to Solana.
The solana objects also provide an optional `providerIds` object inside the `metadata`
to return the known IDs that other providers use to identify chains.

At this time we only define `relay`, but in the future we might include other providers like `coingecko`, `across`, `eco`, etc

```typescript
import { solana } from '@metalayer/viem-chains';

solana.metadata.providerIds?.relay
```