-
Notifications
You must be signed in to change notification settings - Fork 5
/
connection.ts
21 lines (19 loc) · 704 Bytes
/
connection.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import type { Cluster } from "@solana/web3.js";
import { Connection } from "@solana/web3.js";
const networkURLs: { [key in Cluster | "mainnet" | "localnet"]: string } = {
["mainnet-beta"]:
process.env.MAINNET_PRIMARY ?? "https://solana-api.projectserum.com",
mainnet: process.env.MAINNET_PRIMARY ?? "https://solana-api.projectserum.com",
devnet: "https://api.devnet.solana.com/",
testnet: "https://api.testnet.solana.com/",
localnet: "http://localhost:8899/",
};
export const connectionFor = (
cluster: Cluster | "mainnet" | "localnet",
defaultCluster = "mainnet"
) => {
return new Connection(
process.env.RPC_URL || networkURLs[cluster || defaultCluster],
"recent"
);
};