UNPKG

@massalabs/wallet-provider

Version:
40 lines 1.25 kB
import { CHAIN_ID, JsonRPCClient, NetworkName, PublicApiUrl, } from '@massalabs/massa-web3'; import { MASSA_STATION_URL } from '../MassaStationWallet'; import { getRequest } from '../RequestHandler'; import { isStandalone } from './standalone'; // Use client singleton to benefit from caching let client; // Use rpcUrl to check if node has changed let rpcUrl; export async function networkInfos() { if (isStandalone()) { rpcUrl = PublicApiUrl.Buildnet; client = new JsonRPCClient(rpcUrl); return { name: NetworkName.Buildnet, url: rpcUrl, chainId: CHAIN_ID.Buildnet, minimalFee: await client.getMinimalFee(), }; } const { result } = await getRequest(`${MASSA_STATION_URL}massa/node`); const url = result.url; if (!client || rpcUrl !== url) { client = new JsonRPCClient(url); rpcUrl = url; } return { name: result.network, url, chainId: BigInt(result.chainId), minimalFee: await client.getMinimalFee(), }; } export async function getClient() { if (!client) { // this initialize client await networkInfos(); } return client; } //# sourceMappingURL=network.js.map