mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-25 23:27:41 +03:00
Better docs
This commit is contained in:
21
ADVANCED.md
21
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",
|
||||
},
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user