Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/store
/.cargo
/dist
cluster.txt
.env
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ script:
- npm run build:program-c
- npm run build:program-rust
- npm run test:program-rust
- npm run cluster:local
- npm run cluster:localnet
- npm run start
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ $ npm run cluster:devnet

To point back to the local cluster:
```bash
$ npm run cluster:local
$ npm run cluster:localnet
```

## Expand your skills with advanced examples
Expand Down
2 changes: 2 additions & 0 deletions cluster-devnet.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LIVE=1
CLUSTER=devnet
2 changes: 2 additions & 0 deletions cluster-mainnet-beta.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LIVE=1
CLUSTER=mainnet-beta
2 changes: 2 additions & 0 deletions cluster-testnet.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LIVE=1
CLUSTER=testnet
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"build:program-rust": "./src/program-rust/do.sh build && npm run clean:store",
"clean:program-rust": "./src/program-rust/do.sh clean && rm -rf ./dist && npm run clean:store",
"test:program-rust": "./src/program-rust/do.sh test",
"cluster:local": "npm run clean:store && rm -f cluster.txt",
"cluster:devnet": "npm run clean:store && echo devnet > cluster.txt",
"cluster:testnet": "npm run clean:store && echo testnet > cluster.txt",
"cluster:mainnet-beta": "npm run clean:store && echo mainnet-beta > cluster.txt",
"cluster:localnet": "npm run clean:store && rm -f .env",
"cluster:devnet": "npm run clean:store && cp cluster-devnet.env .env",
"cluster:testnet": "npm run clean:store && cp cluster-testnet.env .env",
"cluster:mainnet-beta": "npm run clean:store && cp cluster-mainnet-beta.env .env",
"localnet:update": "solana-localnet update",
"localnet:up": "set -x; solana-localnet down; set -e; solana-localnet up",
"localnet:down": "solana-localnet down",
Expand Down Expand Up @@ -57,6 +57,7 @@
"body-parser": "^1.18.3",
"buffer-layout": "^1.2.0",
"css-loader": "^3.1.0",
"dotenv": "8.2.0",
"eslint": "^6.1.0",
"eslint-loader": "^4.0.0",
"eslint-plugin-import": "^2.13.0",
Expand Down
33 changes: 11 additions & 22 deletions url.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,30 @@
// environment. By default, `LIVE=1` will connect to the devnet cluster.

import {clusterApiUrl, Cluster} from '@solana/web3.js';
import fs from 'mz/fs';
import dotenv from 'dotenv';

function chooseCluster(): Cluster | undefined {
let cluster;
if (process.env.LIVE) {
cluster = process.env.CLUSTER;
} else if (fs.existsSync('cluster.txt')) {
cluster = fs
.readFileSync('cluster.txt')
.toString()
.replace(/(\r\n|\n|\r| )/gm, '');
}

if (cluster) {
switch (cluster) {
case 'devnet':
case 'testnet':
case 'mainnet-beta': {
return cluster;
}
default:
throw 'Unknown cluster: ' + cluster;
dotenv.config();
if (!process.env.LIVE) return;
switch (process.env.CLUSTER) {
case 'devnet':
case 'testnet':
case 'mainnet-beta': {
return process.env.CLUSTER;
}
}
throw 'Unknown cluster "' + process.env.CLUSTER + '", check the .env file';
}

export const cluster = chooseCluster();

export const url =
process.env.RPC_URL ||
(cluster ? clusterApiUrl(cluster, false) : 'http://localhost:8899');
(process.env.LIVE ? clusterApiUrl(cluster, false) : 'http://localhost:8899');

export const urlTls =
process.env.RPC_URL ||
(cluster ? clusterApiUrl(cluster, true) : 'http://localhost:8899');
(process.env.LIVE ? clusterApiUrl(cluster, true) : 'http://localhost:8899');

export let walletUrl =
process.env.WALLET_URL || 'https://solana-example-webwallet.herokuapp.com/';