getConnections
Action for getting all active StarkNet wallet connections.
Import
import { getConnections } from "starkweb/core";
Usage
index.ts
import { getConnections } from "starkweb/core";
import { config } from "./config";
const connections = getConnections(config);
// Access connection details
connections.forEach(connection => {
console.log("Connected accounts:", connection.accounts);
console.log("Chain ID:", connection.chainId);
console.log("Connector:", connection.connector);
});
Return Type
import { type GetConnectionsReturnType } from "starkweb/core";
Returns an array of connections, where each connection contains:
accounts
readonly [Address, ...Address[]]
Array of account addresses for each connection.
chainId
Hex
The chain ID for each connection.
connector
Connector
The connector instance used for each connection.
Example
example.ts
import { getConnections } from "starkweb/core";
import { config } from "./config";
const connections = getConnections(config);
// Check if there are any active connections
if (connections.length > 0) {
// Get the first connection
const [primaryConnection] = connections;
console.log("Primary connection:", {
accounts: primaryConnection.accounts,
chainId: primaryConnection.chainId,
});
// List all connections
connections.forEach((connection, index) => {
console.log(`Connection ${index + 1}:`, {
accounts: connection.accounts,
chainId: connection.chainId,
});
});
}