Config
The Config class is a singleton used to configure the initial setup of the SDK to connect to blockchain networks, sign transactions, deploy contracts, mint tokens, bridge tokens, and interact with additional features across Holograph Protocol. You only need to configure the SDK once, and the configuration will be used throughout the application.
1. Methods
getInstance() static
Bootstrap the Holograph SDK configuration with the provided data.
Params:
- holographConfig:HolographConfigrequired
Returns:
import { Config, HolographAccountFactory } from "@holographxyz/sdk";
import { Environment } from "@holographxyz/environment";
// Server-side applications
const holographConfig = Config.getInstance({
networks: {
polygon: "https://your-polygon-rpc-url.com",
avalanche: "https://your-avalanche-rpc-url.com",
},
environment: Environment.mainnet,
accounts: {
default: HolographAccountFactory.createAccountUsingPrivateKey(
process.env.PRIVATE_KEY
),
},
});
// Client-side applications
const holographConfig = Config.getInstance({
environment: Environment.mainnet,
accounts: {
default: HolographAccountFactory.createAccountUsingPrivateKey(
process.env.PRIVATE_KEY
),
},
provider: window.ethereum,
});
// NOTE: You can also add the `networks` property in the configuration object for client-side applications.
// Just keep in mind that if you pass both `networks` and `provider`, the SDK will mostly use the `networks` first and fallback to the `provider` whether the network RPC is not available.
2. HolographConfig
type HolographConfig = {
accounts?: AccountsConfig;
networks?: NetworkRpc;
environment?: Environment;
provider?: unknown;
};
accounts
- Type: { default: HolographAccount, [accountName: string]: HolographAccount }
The accounts
object is used to configure the accounts the SDK will use to sign transactions. It contains the default
and additional accounts to use with the SDK transactions.
Use the HolographAccountFactory
to create accounts using a private key, a mnemonic, or an EIP-1193 provider. For more information, check out the HolographAccountFactory class reference.
import { HolographAccountFactory } from "@holographxyz/sdk";
const accounts = {
default: HolographAccountFactory.createAccountUsingPrivateKey(
process.env.DEFAULT_ACCOUNT_PRIVATE_KEY
),
accountAbc: HolographAccountFactory.createAccountUsingPrivateKey(
process.env.ACCOUNT_ABC_PRIVATE_KEY
),
accountXyz: HolographAccountFactory.createAccountUsingPrivateKey(
process.env.ACCOUNT_XYZ_PRIVATE_KEY
),
};
networks
- Type: { [key in NetworkKey]?: string }
The networks
object is used to configure the network RPC URLs the SDK will use to connect to different blockchains. The key is the network name key and the value is the RPC URL.
const networks = {
polygon: "https://polygon-rpc-url.com",
avalanche: "https://avalanche-rpc-url.com",
};
Here is the full list of supported mainnet network keys:
ethereum
polygon
avalanche
binanceSmartChain
arbitrumOne
base
linea
mantle
optimism
zora
Here is the full list of supported testnet network keys:
ethereumTestnetSepolia
polygonTestnet
avalancheTestnet
binanceSmartChainTestnet
lineaTestnetGoerli
lineaTestnetSepolia
arbitrumTestnetSepolia
baseTestnetSepolia
mantleTestnet
mantleTestnetSepolia
optimismTestnetSepolia
seiTestnetArctic
zoraTestnetSepolia
The networks
property can be skipped as long as the .env
file contains the network RPC URLs.
POLYGON_RPC_URL = "https://polygon-rpc-url.com";
AVALANCHE_RPC_URL = "https://avalanche-rpc-url.com";
Here is the full list of supported mainnet network RPC URLs:
ETHEREUM_RPC_URL
POLYGON_RPC_URL
AVALANCHE_RPC_URL
BINANCE_SMART_CHAIN_RPC_URL
ARBITRUM_ONE_RPC_URL
BASE_RPC_URL
LINEA_RPC_URL
MANTLE_RPC_URL
OPTIMISM_RPC_URL
ZORA_RPC_URL
Here is the full list of supported testnet network RPC URLs:
ETHEREUM_TESTNET_SEPOLIA_RPC_URL
POLYGON_TESTNET_RPC_URL
AVALANCHE_TESTNET_RPC_URL
BINANCE_SMART_CHAIN_TESTNET_RPC_URL
LINEA_TESTNET_GOERLI_RPC_URL
LINEA_TESTNET_SEPOLIA_RPC_URL
ARBITRUM_TESTNET_SEPOLIA_RPC_URL
BASE_TESTNET_SEPOLIA_RPC_URL
MANTLE_TESTNET_RPC_URL
MANTLE_TESTNET_SEPOLIA_RPC_URL
OPTIMISM_TESTNET_SEPOLIA_RPC_URL
SEI_TESTNET_ARCTIC_RPC_URL
ZORA_TESTNET_SEPOLIA_RPC_URL
environment
- Type: localhost | experimental | develop | testnet | mainnetdefault: testnet
The environment
property is used to configure the environment to use with the SDK.
It is an enum with the following shape:
export enum Environment {
localhost = "localhost",
experimental = "experimental",
develop = "develop",
testnet = "testnet",
mainnet = "mainnet",
}
Make sure to import it from the @holographxyz/environment
package.
import { Environment } from "@holographxyz/environment";
const environment = Environment.mainnet;
provider
- Type: unknown
The provider
property is usually an EIP-1193 Ethereum Provider to interact with the SDK via client-side applications.
const provider = window.ethereum;