Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docs #2

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.PUBLIC_PACKAGE_PUBLISH_SECRET }}
token: ${{ secrets.PUBLIC_PACKAGE_PUBLISH_SECRET }}
- uses: actions/setup-node@v4
with:
node-version: 20
Expand Down
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,48 @@
# Optimism batch decoder
Decodes the calldata of a batcher transaction and returns the L2 transactions within it

## Background
The transactions of a L2 rollup are batched together and submitted to a L1. The Batcher will submit these batches to a Batch Inbox Address on L1, which is an EOA and will save gas because no code will be executed.
`0xFF00000000000000000000000000000000000010` is the Batch Inbox Address of Optimism on Ethereum.
The calldata of each transaction to the Batch Inbox contains batches of L2 as an encoded and compressed hex string.

## Installation
`npm i @blocktorch/optimism-batch-decoder` or `yarn add @blocktorch/optimism-batch-decoder`

## Usage
```
### `decodeBatcherTransactionCalldata(calldata)`
Decodes the L2 transactions from raw calldata
- `calldata` - the calldata of the transaction by a Batcher to the Batch Inbox Address on L1.
You can get it from the transaction page on Etherscan (Input Data -> View Input As Original). For an example, check `example-data/calldata.txt`.

```javascript
import { decodeBatcherTransactionCalldata } from '@blocktorch/optimism-batch-decoder'

const batcherTransaction = await decodeBatcherTransactionCalldata(calldata)
```

- use `decodeBatcherTransactionCalldata` to decode the provided calldata.
- use `decodeBatcherTransaction` to only provide the transaction hash and provider URL. It will fetch the calldata for you and decode the same way.
### `decodeBatcherTransaction(txHash, providerUrl)`
Wrapper for `decodeBatcherTransactionCalldata`. Will fetch the calldata for you based on the transaction hash.
- `txHash` - hash of the L1 transaction to the Batch Inbox
- `providerUrl` - RPC provider URL that is used to fetch data about the transaction


### `testWithExampleData(path?)`
Test function to decode example calldata. You can provide the path to example call data, but by default it looks for `example-data/calldata.txt` in the repository.
- `path` - path to your own calldata relative to the repository root.

### `BatcherTransaction`
All of the functions will return a BatcherTransaction.
It contains a version and its Frames. [More about the batcher transaction format](https://github.com/ethereum-optimism/optimism/blob/v1.1.4/specs/derivation.md#batcher-transaction-format)

Each Frame contains [info about the Frame](https://github.com/ethereum-optimism/optimism/blob/v1.1.4/specs/derivation.md#frame-format) and its batches.

And each Batch contains a list of transactions and [info about the Batch](https://github.com/ethereum-optimism/optimism/blob/v1.1.4/specs/derivation.md#batch-format)

- use `testWithExampleData` function to decode example calldata. You can provide the path to example call data, but by default it looks for `example-data/calldata.txt` in the repo.

## Known issues
NB! SpanBatch decoding is unimplemented at the moment.

---

Made with 💛 at Blocktorch