url.js 942 B

12345678910111213141516171819202122232425262728293031
  1. // To connect to a public cluster, set `export LIVE=1` in your
  2. // environment. By default, `LIVE=1` will connect to the devnet cluster.
  3. import {clusterApiUrl, Cluster} from '@solana/web3.js';
  4. import dotenv from 'dotenv';
  5. function chooseCluster(): Cluster | undefined {
  6. dotenv.config();
  7. if (!process.env.LIVE) return;
  8. switch (process.env.CLUSTER) {
  9. case 'devnet':
  10. case 'testnet':
  11. case 'mainnet-beta': {
  12. return process.env.CLUSTER;
  13. }
  14. }
  15. throw 'Unknown cluster "' + process.env.CLUSTER + '", check the .env file';
  16. }
  17. export const cluster = chooseCluster();
  18. export const url =
  19. process.env.RPC_URL ||
  20. (process.env.LIVE ? clusterApiUrl(cluster, false) : 'http://localhost:8899');
  21. export const urlTls =
  22. process.env.RPC_URL ||
  23. (process.env.LIVE ? clusterApiUrl(cluster, true) : 'http://localhost:8899');
  24. export let walletUrl =
  25. process.env.WALLET_URL || 'https://solana-example-webwallet.herokuapp.com/';