@openocean.finance/widget-sdk
Version:
OpenOcean Any-to-Any Cross-Chain-Swap SDK
54 lines • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUTXOPublicClient = void 0;
const core_1 = require("@bigmi/core");
const viem_1 = require("viem");
const config_js_1 = require("../../config.js");
const rpc_js_1 = require("../rpc.js");
const publicClients = {};
const getUTXOPublicClient = async (chainId) => {
if (!publicClients[chainId]) {
const urls = await (0, rpc_js_1.getRpcUrls)(chainId);
const fallbackTransports = urls.map((url) => (0, viem_1.http)(url));
const _chain = await config_js_1.config.getChainById(chainId);
const chain = {
..._chain,
..._chain.metamask,
name: _chain.metamask.chainName,
rpcUrls: {
default: { http: _chain.metamask.rpcUrls },
public: { http: _chain.metamask.rpcUrls },
},
};
const client = (0, viem_1.createClient)({
chain,
rpcSchema: (0, viem_1.rpcSchema)(),
transport: (0, viem_1.fallback)([
(0, core_1.utxo)('https://api.blockchair.com', {
key: 'blockchair',
includeChainToURL: true,
}),
(0, core_1.utxo)('https://api.blockcypher.com/v1/btc/main', {
key: 'blockcypher',
}),
(0, core_1.utxo)('https://mempool.space/api', {
key: 'mempool',
}),
(0, core_1.utxo)('https://rpc.ankr.com/http/btc_blockbook/api/v2', {
key: 'ankr',
}),
...fallbackTransports,
]),
pollingInterval: 10_000,
})
.extend(core_1.UTXOActions)
.extend(core_1.UTXOAPIActions);
publicClients[chainId] = client;
}
if (!publicClients[chainId]) {
throw new Error(`Unable to configure provider for chain ${chainId}`);
}
return publicClients[chainId];
};
exports.getUTXOPublicClient = getUTXOPublicClient;
//# sourceMappingURL=getUTXOPublicClient.js.map