Skip to content

Commit

Permalink
fix: port on create client (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfrosty authored Feb 21, 2025
1 parent e3c8aff commit 7a220bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-hornets-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gill": patch
---

fix createSolanaClient to accept port numbers and set the localnet port
10 changes: 10 additions & 0 deletions packages/gill/src/core/create-solana-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,21 @@ export function createSolanaClient<TCluster extends ModifiedClusterUrl>({
throw new Error("Unsupported protocol. Only HTTP and HTTPS are supported");
}

if (rpcConfig?.port) {
urlOrMoniker.port = rpcConfig.port.toString();
}

const rpc = createSolanaRpc<TCluster>(urlOrMoniker.toString() as TCluster, rpcConfig);

if (urlOrMoniker.protocol.endsWith("s")) urlOrMoniker.protocol = "wss";
else urlOrMoniker.protocol = "ws";

if (rpcSubscriptionsConfig?.port) {
urlOrMoniker.port = rpcSubscriptionsConfig.port.toString();
} else if (urlOrMoniker.hostname == "localhost" || urlOrMoniker.hostname.startsWith("127")) {
urlOrMoniker.port = "8900";
}

const rpcSubscriptions = createSolanaRpcSubscriptions<TCluster>(
urlOrMoniker.toString() as TCluster,
rpcSubscriptionsConfig,
Expand Down
4 changes: 2 additions & 2 deletions packages/gill/src/types/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export type CreateSolanaClientArgs<
/** Full RPC URL (for a private RPC endpoint) or the Solana moniker (for a public RPC endpoint) */
urlOrMoniker: SolanaClusterMoniker | TClusterUrl | URL | ModifiedClusterUrl;
/** Configuration used to create the `rpc` client */
rpcConfig?: Parameters<typeof createSolanaRpc>[1];
rpcConfig?: Parameters<typeof createSolanaRpc>[1] & { port?: number };
/** Configuration used to create the `rpcSubscriptions` client */
rpcSubscriptionsConfig?: Parameters<typeof createSolanaRpcSubscriptions>[1];
rpcSubscriptionsConfig?: Parameters<typeof createSolanaRpcSubscriptions>[1] & { port?: number };
};

export type CreateSolanaClientResult<TClusterUrl extends ModifiedClusterUrl | string = string> = {
Expand Down

0 comments on commit 7a220bc

Please sign in to comment.