@metalayer/viem-chains
v0.2.10
Published
Viem Chain configurations for Chains and Rollups in the Caldera and Metalayer ecosystem.
Downloads
46
Keywords
Readme
@metalayer/viem-chains
A collection of viem Chain definitions for the rollups in the Caldera and Metalayer ecosystem.
Installation
pnpm add @metalayer/viem-chains
# or with npm
npm install @metalayer/viem-chains
# or with yarn
yarn add @metalayer/viem-chainsUsage
The Chain definitions in this package are fully compatible with viem. Import the chain you want to use in viem and create a client:
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:
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 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.
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
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:
- Solana Mainnet - 501494 which stands for SOLANA if you think of the 9 as Nine
- Solana Devnet - 5017357 which stands for SOLTEST
Utility functions
We provide 2 utility functions getSolanaConfig and isSolana
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 undefinedisSolana- given a chainId (number) or a chain (Chain), it will returntrueorfalseto 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
import { solana } from '@metalayer/viem-chains';
solana.metadata.providerIds?.relay