An open API service indexing awesome lists of open source software.

https://github.com/chainbound/fiber-py


https://github.com/chainbound/fiber-py

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

          

# `fiber-py`

## Installation

With pip:

```
pip install git+https://github.com/chainbound/fiber-py
```

With Poetry:

```
poetry add git+https://github.com/chainbound/fiber-py
```

## Usage

### Connecting

```python
from fiber.client import Client

client = Client('FIBER_ENDPOINT', 'YOUR_API_KEY')
try:
client.connect()
except Exception as e:
print('Error connecting', e)
```

### Subscribing to transactions

The transaction stream is supported but without any filtering for now.
This stream yields [`fiber.types.Transaction`](/fiber/types.py#L9) objects.
All the bytes fields are encoded as hexadecimal strings.

```python
try:
sub = client.subscribe_new_txs()

# Iterate over transaction stream
for tx in sub:
do_something(tx)
except Exception as e:
print("error subscribing", e)
```

> **Note**
> You can also get the RLP-encoded signed transaction with the methods `tx.to_rlp_bytes()` and `tx.to_rlp_hex()`
> to get the raw bytes or the hex string respectively.

### Subscribing to blocks

#### Execution Payload Headers

This stream yields only the new block headers as [`fiber.types.ExecutionPayloadHeader`](/fiber/types.py#L75) objects.
All the bytes fields are encoded as hexadecimal strings.

```python
try:
sub = client.subscribe_new_execution_payload_headers()

for header in sub:
do_something(header)
except Exception as e:
print("error subscribing", e)
```

#### Execution Payloads

This stream yields the new blocks as full [`fiber.types.ExecutionPayload`](/fiber/types.py#L94) objects.
All the bytes fields are encoded as hexadecimal strings.

```python
try:
sub = client.subscribe_new_execution_payloads()

for block in sub:
do_something(block)
except Exception as e:
print("error subscribing", e)
```

#### Beacon Blocks

This stream yields the blocks as seen by the Ethereum consensus layer, in the form of [`fiber.types.BeaconBlock`](/fiber/types.py#L211) objects. All the bytes fields are encoded as hexadecimal strings.

> **Note**
> Beacon blocks **do not** contain the execution payloads. To also get the execution payloads, please subscribe to the execution payload stream `subscribe_new_execution_payloads()` separately.

```python
try:
sub = client.subscribe_new_beacon_blocks()

for block in sub:
do_something(block)
except Exception as e:
print("error subscribing", e)
```