Skip to content

Commit ee2cb1f

Browse files
authored
doc: typescript syntax (#220)
Let's encourage people to use shorter, more readable, and more idiomatic Typescript syntax when getting the config values. See e.g. eslint rule https://eslint.org/docs/rules/prefer-destructuring
1 parent 127ff98 commit ee2cb1f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/config/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,23 @@ npm install --save @streamr/config
1414
### Typescript
1515
Import DATA token production Ethereum address as a variable in a Typescript project:
1616
```typescript
17+
import { Chains } from "@streamr/config"
18+
19+
const {
20+
ethereum: {
21+
id: chainId
22+
contracts: {
23+
"DATA-token": dataTokenAddress
24+
}
25+
}
26+
} = Chains.load("production")
27+
```
28+
29+
Find RPC endpoints:
30+
```typescript
1731
import * as config from "@streamr/config"
1832

1933
const chains: config.Chains = config.Chains.load("production")
20-
const contractAddress: string = chains.ethereum.contracts["DATA-token"]
21-
const chainId: number = chains.ethereum.id
2234
const httpRpcEndpoints: RPCEndpoint[] = chains.ethereum.getRPCEndpointsByProtocol(config.RPCProtocol.HTTP)
2335
const wsRpcEndpoints: RPCEndpoint[] = chains.ethereum.getRPCEndpointsByProtocol(config.RPCProtocol.WEBSOCKET)
2436
```

0 commit comments

Comments
 (0)