{"id":21531997,"url":"https://github.com/chainbound/fiber-ts","last_synced_at":"2025-04-10T00:28:47.790Z","repository":{"id":58788726,"uuid":"533449060","full_name":"chainbound/fiber-ts","owner":"chainbound","description":"Fiber client in Typescript","archived":false,"fork":false,"pushed_at":"2024-03-22T08:25:46.000Z","size":257,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-14T10:49:29.265Z","etag":null,"topics":["ethereum","mev","p2p"],"latest_commit_sha":null,"homepage":"https://fiber.chainbound.io","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chainbound.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-06T18:14:48.000Z","updated_at":"2023-10-27T01:29:26.000Z","dependencies_parsed_at":"2024-03-11T15:28:25.796Z","dependency_job_id":"af31d191-e977-44d5-bb23-382311856c71","html_url":"https://github.com/chainbound/fiber-ts","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainbound%2Ffiber-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainbound%2Ffiber-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainbound%2Ffiber-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainbound%2Ffiber-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chainbound","download_url":"https://codeload.github.com/chainbound/fiber-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248133748,"owners_count":21053317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ethereum","mev","p2p"],"created_at":"2024-11-24T02:18:29.122Z","updated_at":"2025-04-10T00:28:47.761Z","avatar_url":"https://github.com/chainbound.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fiber TypeScript Client\n\n[![Version](https://img.shields.io/npm/v/fiber-ts.svg)](https://www.npmjs.com/package/fiber-ts)\n\nThis package contains a JS/TS client for connecting to the Fiber Network.\n\n## Examples\n\nYou can find some examples in the [examples directory](./examples).\n\n## Usage\n\n### Installation\n\n```bash\nnpm i fiber-ts\n# or\nyarn add fiber-ts\n```\n\n### Connecting\n\n```ts\nimport { Client } from \"fiber-ts\";\n\nconst client = new Client(\"fiber.example.io\", \"YOUR_API_KEY\");\n\n// Wait up to 10 seconds for the client to connect.\nawait client.waitForReady(10);\n```\n\n### Subscriptions\n\nThe client exposes 2 subscriptions: **transactions** and **blocks**.\nThey are implemented as event emitters which you can listen to.\n\n#### Types\n\n`fiber-ts` works with `ethereumjs` and `lodestar` types internally. The types\nare re-exported for convenience.\n\n#### Transactions\n\n`fiber-ts` works with [ethereumjs](https://github.com/ethereumjs/ethereumjs-monorepo) internally,\nand transactions are implemented as `@ethereumjs/tx.TypedTransaction`.\nThis is for a couple reasons, but most importantly performance.\n\nThe transactions are returned as `Transaction(Raw)WithSender`s, which is a\nwrapper type around `@ethereumjs/tx.TypedTransaction` that includes the signer\nof the transaction.\n\nFiltering functionality is currently a work in progress. The filter object\npassed to `subscribeNewTxs` is a simple **OR** filter, so if a transaction\nmatches either to `to`, `from` or `methodid` field, it will be sent on the\nstream.\n\n```ts\nimport { Client, FilterBuilder, or, to, Types } from \"fiber-ts\";\n\nconst client = new Client(\"fiber.example.io\", \"YOUR_API_KEY\");\n\n// Wait 10 seconds for the client to connect.\nawait client.waitForReady(10);\n\nlet filter = new FilterBuilder(\n  or(\n    to(\"0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45\"),\n    to(\"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488d\")\n  )\n);\n\nconst sub = client.subscribeNewTxs(filter);\n\nsub.on(\"data\", (tx: Types.TransactionWithSender) =\u003e {\n  handleTx(tx);\n});\n```\n\nIt is also possible to subscribe to stream of raw transactions, which for every\ntransaction returns its signer and the RLP encoded data.\n\n```ts\nimport { Client, FilterBuilder, or, to, Types } from \"fiber-ts\";\n\nconst client = new Client(\"fiber.example.io\", \"YOUR_API_KEY\");\n\n// Wait 10 seconds for the client to connect.\nawait client.waitForReady(10);\n\nlet filter = new FilterBuilder(\n  or(\n    to(\"0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45\"),\n    to(\"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488d\")\n  )\n);\n\nconst sub = client.subscribeNewRawTxs(filter);\n\nsub.on(\"data\", (tx: Types.TransactionRawWithSender) =\u003e {\n  handleTx(tx);\n});\n```\n\n#### Blob transactions\n\n`fiber-ts` works with [ethereumjs](https://github.com/ethereumjs/ethereumjs-monorepo) internally,\nand transactions are implemented as `@ethereumjs/tx.BlobEIP4844Transaction`.\nThis is for a couple reasons, but most importantly performance.\n\nThe transactions are returned as `BlobTransaction(Raw)WithSender`s, which is a\nwrapper type around `@ethereumjs/tx.BlobEIP4844Transaction` that includes the signer\nof the transaction.\n\nFiltering functionality is not supported at the moment.\n\n```ts\nimport { Client, Types } from \"fiber-ts\";\n\nconst client = new Client(\"fiber.example.io\", \"YOUR_API_KEY\");\n\n// Wait 10 seconds for the client to connect.\nawait client.waitForReady(10);\n\nconst sub = client.subscribeNewBlobTxs(filter);\n\nsub.on(\"data\", (tx: Types.BlobTransactionWithSender) =\u003e {\n  handleTx(tx);\n});\n```\n\nIt is also possible to subscribe to stream of raw blob transactions, which for\nevery transaction returns its signer and the \"raw format\" `type ||\nrlp([tx_payload_body, blobs, commitments, proofs])` compatible with the\n`eth_sendRawTransaction` RPC method.\n\n```ts\nimport { Client, Types } from \"fiber-ts\";\n\nconst client = new Client(\"fiber.example.io\", \"YOUR_API_KEY\");\n\n// Wait 10 seconds for the client to connect.\nawait client.waitForReady(10);\n\nconst sub = client.subscribeNewBlobRawTxs(filter);\n\nsub.on(\"data\", (tx: Types.TransactionRawWithSender) =\u003e {\n  handleTx(tx);\n});\n```\n\n#### Execution Payloads (new blocks with transactions)\n\nPayloads have the type: `@ethereumjs/block`.\n\n```ts\nimport { Client, Types } from \"fiber-ts\";\n\nconst client = new Client(\"fiber.example.io\", \"YOUR_API_KEY\");\n\n// Wait 10 seconds for the client to connect.\nawait client.waitForReady(10);\n\nconst sub = client.subscribeNewExecutionPayloads();\n\nsub.on(\"data\", (block: Types.ExecutionPayload) =\u003e {\n  handleBlock(block);\n});\n```\n\nNOTE\n\nThe following block header fields are empty:\n\n- `transactionsTrie`\n- `withdrawalsRoot`\n- `parentBeaconBlockRoot`\n\n#### Beacon Blocks\n\nBeacon blocks have the `fiber-ts` wrapper type `SignedBeaconBlock`,\nwhich uses `@lodestar/types` internally and provides a `dataVersion`\nproperty to discriminate between different forks.\n\n```ts\nimport { Client, Types } from \"fiber-ts\";\n\nconst client = new Client(\"fiber.example.io\", \"YOUR_API_KEY\");\n\n// Wait 10 seconds for the client to connect.\nawait client.waitForReady(10);\n\nconst sub = client.subscribeNewBeaconBlocks();\n\nsub.on(\"data\", (block: Types.SignedBeaconBlock) =\u003e {\n  handleBeaconBlock(block);\n});\n```\n\nIt is also possible to subscribe to stream of raw beacon blocks, which for every\nblock returns its SSZ encoded data as `Uint8Array`.\n\n```ts\nimport { Client } from \"fiber-ts\";\n\nconst client = new Client(\"fiber.example.io\", \"YOUR_API_KEY\");\n\n// Wait 10 seconds for the client to connect.\nawait client.waitForReady(10);\n\nconst sub = client.subscribeNewRawBeaconBlocks();\n\nsub.on(\"data\", (data: Uint8Array) =\u003e {\n  handleBeaconBlock(data);\n});\n```\n\n### Sending Transactions\n\n`fiber-ts` has 4 endpoints for sending transactions:\n\n- `client.sendTransaction` for just sending a normal transaction.\n- `client.sendRawTransaction` for sending a raw transaction (signed with\n  `ethers` or `web3.js`).\n- `client.sendTransactionSequence` for sending a sequence of normal\n  transactions in a row. Please remember that the ordering is not guaranteed\n  on-chain, as the final ordering is determined by the block producer.\n- `client.sendRawTransactionSequence` for sending a sequence of raw\n  transactions (signed with ethers or `web3.js`)\n\nFor constructing transactions, we recommend using `TransactionFactory`. This\nwill automatically create a typed transaction from the given transaction data.\n\n#### `sendTransaction`\n\n```ts\nimport { Client, Types } from \"fiber-ts\";\n\nconst client = new Client(\"fiber.example.io\", \"YOUR_API_KEY\");\n\n// Wait 10 seconds for the client to connect.\nawait client.waitForReady(10);\n\nconst pk = Buffer.from(\"PRIVATE_KEY\", \"hex\");\n\n// Build an EIP1559 TypedTransaction with ethereumjs\nconst tx = Types.TransactionFactory.fromTxData({\n  chainId: 1,\n  type: 2,\n  to: \"0x...\",\n  gasLimit: 21000,\n  value: 0,\n  nonce: 21,\n  maxFeePerGas: 20 * 1e9,\n  maxPriorityFeePerGas: 2 * 1e9,\n});\n\n// Sign the transaction\nconst signed = tx.sign(pk);\n\n// Result contains the timestamp (unix microseconds) and hash of the transaction\nconst result: Types.TransactionResponse = await client.sendTransaction(signed);\n```\n\n#### `sendRawTransaction`\n\n```ts\nimport { Client } from \"fiber-ts\";\nimport { ethers } from \"ethers\";\n\nconst wallet = new ethers.Wallet(\"PRIVATE_KEY\");\n\nconst signedTx = await wallet.signTransaction({\n  chainId: 1,\n  type: 2,\n  to: \"0x...\",\n  gasLimit: 21000,\n  value: 0,\n  nonce: 21,\n  maxFeePerGas: 20 * 1e9,\n  maxPriorityFeePerGas: 2 * 1e9,\n});\n\nconst result = await client.sendRawTransaction(signedTx);\n```\n\n#### `sendTransactionSequence`\n\nThis endpoint is built to send an array of transactions to land on the same block. Ordering is not guaranteed because of Ethereum's PBS system which delegates this power to the block builders.\n\nIt takes an array of transactions as input, and makes sure these transactions are propagated in a bundle. Assuming the gas price of these transactions is the same, the backrun transaction will never arrive before the target transaction at a block producer.\n\n```ts\nimport { Client, Types } from \"fiber-ts\";\n\nconst client = new Client(\"fiber.example.io\", \"YOUR_API_KEY\");\n\n// Wait 10 seconds for the client to connect.\nawait client.waitForReady(10);\n\nconst pk = Buffer.from(\"PRIVATE_KEY\", \"hex\");\n\nconst txToBackrun = \"0xdeadbeef...\";\n\n// Build a TypedTransaction with ethereumjs\nconst tx = Types.TransactionFactory.fromTxData({\n  chainId: 1,\n  type: 2,\n  to: \"0x...\",\n  gasLimit: 21000,\n  value: 0,\n  nonce: 21,\n  maxFeePerGas: 20 * 1e9,\n  maxPriorityFeePerGas: 2 * 1e9,\n});\n\nconst signed = tx.sign(pk);\n\n// Result contains the timestamp (unix microseconds) and hash of the transaction\nconst result: Types.TransactionResponse = await client.sendTransactionSequence([\n  txToBackrun,\n  signed,\n]);\n```\n\n#### `sendRawTransactionSequence`\n\n```ts\nimport { Client } from \"fiber-ts\";\nimport { ethers } from \"ethers\";\n\nconst wallet = new ethers.Wallet(\"PRIVATE_KEY\");\n\nconst txToBackrun = \"0xdeadbeef...\";\n\nconst signedTx = await wallet.signTransaction({\n  chainId: 1,\n  type: 2,\n  to: \"0x...\",\n  gasLimit: 21000,\n  value: 0,\n  nonce: 21,\n  maxFeePerGas: 20 * 1e9,\n  maxPriorityFeePerGas: 2 * 1e9,\n});\n\nconst result = await client.sendRawTransactionSequence([txToBackrun, signedTx]);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainbound%2Ffiber-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchainbound%2Ffiber-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainbound%2Ffiber-ts/lists"}