diff --git a/ADVANCED.md b/ADVANCED.md index a10c53d..5689034 100644 --- a/ADVANCED.md +++ b/ADVANCED.md @@ -23,4 +23,25 @@ const orion = new Orion({ }, }, }); + +const orionUnit = orion.getUnit("bsc"); +// OR +const orionUnit = orion.getUnit(SupportedChainId.BSC); +// OR +const orionUnit = new OrionUnit({ + chainId: SupportedChainId.BSC, + nodeJsonRpc: "https://bsc-dataseed.binance.org/", + services: { + orionBlockchain: { + http: "https://orion-bsc-api.orionprotocol.io", + }, + orionAggregator: { + http: "https://orion-bsc-api.orionprotocol.io/backend", + ws: "https://orion-bsc-api.orionprotocol.io/v1", + }, + priceFeed: { + api: "https://orion-bsc-api.orionprotocol.io/price-feed", + }, + }, +}); ``` diff --git a/package.json b/package.json index 12192fe..4ee6a10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.17.0-rc.0", + "version": "0.17.0-rc.1", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/Orion/index.ts b/src/Orion/index.ts index f433acb..8b31b48 100644 --- a/src/Orion/index.ts +++ b/src/Orion/index.ts @@ -108,9 +108,18 @@ export default class Orion { return Object.entries(this.units).map(([, unit]) => unit); } - getUnit(networkCode: string) { - const unit = this.unitsArray.find((unit) => unit.networkCode === networkCode); - if (!unit) throw new Error(`Invalid network code: ${networkCode}. Available network codes: ${this.unitsArray.map((unit) => unit.networkCode).join(', ')}`); + getUnit(chainId: SupportedChainId): OrionUnit; + + getUnit(networkCode: string): OrionUnit; + + getUnit(networkCodeOrChainId: string): OrionUnit { + let unit: OrionUnit | undefined; + if (isValidChainId(networkCodeOrChainId)) { + unit = this.units[networkCodeOrChainId]; + } else { + unit = this.unitsArray.find((unit) => unit.networkCode === networkCodeOrChainId); + } + if (!unit) throw new Error(`Invalid network code: ${networkCodeOrChainId}. Available network codes: ${this.unitsArray.map((unit) => unit.networkCode).join(', ')}`); return unit; }