UNPKG

@ckb-ccc/core

Version:

Core of CCC - CKBer's Codebase

41 lines (40 loc) 1.35 kB
import WebSocket from "isomorphic-ws"; import { TESTNET_SCRIPTS } from "./clientPublicTestnet.advanced.js"; import { ScriptInfo } from "./clientTypes.js"; import { ClientJsonRpc } from "./jsonRpc/index.js"; /** * @public */ export class ClientPublicTestnet extends ClientJsonRpc { constructor(config) { const hasWebSocket = typeof WebSocket !== "undefined"; super(config?.url ?? (hasWebSocket ? "wss://testnet.ckb.dev/ws" : "https://testnet.ckb.dev/"), { ...config, fallbacks: config?.fallbacks ?? (hasWebSocket ? [ "wss://testnet.ckb.dev/ws", "https://testnet.ckb.dev/", "https://testnet.ckbapp.dev/", ] : ["https://testnet.ckb.dev/", "https://testnet.ckbapp.dev/"]), }); this.config = config; } get scripts() { return this.config?.scripts ?? TESTNET_SCRIPTS; } get addressPrefix() { return "ckt"; } async getKnownScript(script) { const found = this.scripts[script]; if (!found) { throw new Error(`No script information was found for ${script} on ${this.addressPrefix}`); } return ScriptInfo.from(found); } }