Skip to main content

Function: readChains()

function readChains<S>(
value,
schemas,
get,
options?): ReadChain<S>[];

Defined in: packages/overcast-core/src/chain-env.ts:205

Every chain value (the contents of CHAINS_ENV) declares, each read from the env under its own chainEnvPrefix against its protocol's schema.

const chains = readChains(
process.env.OVERCAST_CHAINS ?? "solana-devnet:svm",
{ svm: SOLANA_CONFIG_SCHEMA, evm: EVM_CONFIG_SCHEMA },
(key) => process.env[key],
{ required: { svm: ["privateKey", "domain"], evm: ["privateKey", "domain"] } },
);
for (const chain of chains) {
switch (chain.protocol) {
case "svm": new SolanaFactory({ chainName: chain.name, ...chain.config, … });
case "evm": new EvmFactory({ chainName: chain.name, ...chain.config, … });
}
}

Every chain is read before anything throws, so an operator who misconfigured two chains learns about both at once.

Also rejects two chains that state the same domain: every option's terms commit to the domain, so two chains sharing one are indistinguishable to anything stored. A domain left unset is not checked — a layer fills it in later (from the chain id, or from the chain itself) — so a host that resolves those defaults should run assertUniqueDomains once it has.

Type Parameters​

Type Parameter
S extends ChainSchemas

Parameters​

ParameterType
valuestring
schemasS
get(key) => string | undefined
optionsReadChainsOptions<S>

Returns​

ReadChain<S>[]

Throws​

a plain Error when value is malformed (see parseChainSpecs), and ConfigError when any chain's config is unreadable or two chains state the same domain.