Skip to content

Commit 24bde23

Browse files
authored
Merge 6d2d25b into 8cb08ff
2 parents 8cb08ff + 6d2d25b commit 24bde23

2 files changed

Lines changed: 9 additions & 16 deletions

File tree

packages/api/README.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,23 @@
77

88
> This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
99
10-
Typescript REST client for the [Ethereum Consensus API spec](https://github.com/ethereum/beacon-apis)
10+
Typescript REST client for the [Ethereum Consensus API](https://github.com/ethereum/beacon-apis)
1111

1212
## Usage
1313

14-
We use more typesafe approach for the API client, where all the errors are returned not thrown. This approach is more easy to document and better to handle all possible error cases.
14+
The REST client extends the native [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), it behaves very similar in terms of error and response handling. It returns the same [Response object](https://developer.mozilla.org/en-US/docs/Web/API/Response) with additional methods to simplify usage and it allows to override all [Request options](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options) if needed.
1515

1616
```typescript
17-
import {getClient, HttpError} from "@lodestar/api";
17+
import {getClient} from "@lodestar/api";
1818
import {config} from "@lodestar/config/default";
1919

2020
const api = getClient({baseUrl: "http://localhost:9596"}, {config});
2121

22-
api.beacon
23-
.getStateValidator(
24-
"head",
25-
"0x933ad9491b62059dd065b560d256d8957a8c402cc6e8d8ee7290ae11e8f7329267a8811c397529dac52ae1342ba58c95"
26-
)
27-
.then((res) => {
28-
if (res.ok) {
29-
console.log("Your balance is:", res.response.data.balance, res.ok, res.status);
30-
} else {
31-
console.error(res.status, res.error.code, res.error.message);
32-
}
33-
});
22+
const res = await api.beacon.getStateValidator({stateId: "head", validatorId: 0});
23+
24+
const validator = res.value();
25+
26+
console.log("The validator balance is: ", validator.balance);
3427
```
3528

3629
## Prerequisites

packages/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lodestar/api",
3-
"description": "A Typescript implementation of the Ethereum Consensus light client",
3+
"description": "A Typescript REST client for the Ethereum Consensus API",
44
"license": "Apache-2.0",
55
"author": "ChainSafe Systems",
66
"homepage": "https://github.com/ChainSafe/lodestar#readme",

0 commit comments

Comments
 (0)