Skip to content

Commit

Permalink
Create jito_jsonrpc_sdk.py (#1)
Browse files Browse the repository at this point in the history
* Create jito_jsonrpc_sdk.py
  • Loading branch information
mdr0id authored Aug 27, 2024
1 parent d2cbd9d commit 0635e43
Show file tree
Hide file tree
Showing 10 changed files with 476 additions and 2 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Python application

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest responses
pip install -e .
- name: Run tests
env:
JITO_TESTNET_URL: https://dallas.testnet.block-engine.jito.wtf/api/v1
run: pytest ./tests/test_jito_json_rpc_sdk.py
157 changes: 157 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Byte-compiled / optimized / DLL files
__pycache__/
sdk/__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Virtual environment
.env/
.venv/
env/
venv/
ENV/
env.bak/
venv.bak/

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/
docs/_static/
docs/_templates/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
spyderproject
spyderworkspace

# VS Code
.vscode/
history/

# PyCharm
.idea/
*.iml
*.iws
*.ipr
out/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Pycharm
.idea/
*.iml
*.iws
*.ipr
out/

# MacOS specific files
.DS_Store

# Windows specific files
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/

# Anaconda environments
.envs/
.conda/

# Miscellaneous
*.swp
*~
124 changes: 122 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,122 @@
# jito-py-rpc
Jito Python JSON RPC SDK
# Welcome to the Jito Python JSON RPC SDK!

[![Discord](https://img.shields.io/discord)](https://discord.gg/jito)
[![Python](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org/)


This is a minimal SDK that interfaces with the Block-Engine JSON-RPC API using [JSON-RPC 2.0](https://www.jsonrpc.org/specification) specification.

#### Jito MEV Background
For additional information on Jito MEV topics:

https://jito-labs.gitbook.io/mev

#### Jito JSON-RPC HTTP Method
For more information on the complete JSON-RPC method specification:

https://github.com/jito-labs/mev-protos/blob/master/json_rpc/http.md

## Getting Started

### Setting Up the SDK

#### Step 1: Clone the Repository
Clone the [repo](https://github.com/mdr0id/JitoJsonRpcSDK) to your local machine.

```
git clone [email protected]:mdr0id/JitoJsonRpcSDK.git
```

#### Step 2: Install Dependencies
You will need the Python `requests` module to make HTTP requests. If you don't have `requests` installed, you can install it using pip:

```
pip install requests
```

## Using the SDK
#### Step 1: Import the SDK

```
from sdk.jito_jsonrpc_sdk import JitoJsonRpcSDK
```

#### Step 2: Initialize the SDK
Depending on what network you would like to connect to, please select one of the following(e.g mainnet or testnet).

#### Step 3 (Optional): Environment Config for Authentication
If you are using authentication with UUIDs it is recommended to setup an `.envrc` like below:

```
export JITO_UUID=513f9c0c-260d-4e14-b5b4-495785548cd2
```

For instructions on setting up `direnv` please look [here](https://direnv.net/docs/installation.html)


##### Mainnet
For current list of of `mainnet` addresses, please see:

https://jito-labs.gitbook.io/mev/searcher-resources/block-engine/mainnet-addresses
```
BLOCK_ENG_URL = "https://mainnet.block-engine.jito.wtf:443/api/v1/bundles"
sdk = JitoJsonRpcSDK(BLOCK_ENG_URL)
```
##### Testnet
For current list of of `testnet` addresses, please see:

https://jito-labs.gitbook.io/mev/searcher-resources/block-engine/testnet-addresses
```
BLOCK_ENG_URL = "https://dallas.testnet.block-engine.jito.wtf/api/v1/bundles"
sdk = JitoJsonRpcSDK(BLOCK_ENG_URL)
```

#### Step 3: Call JSON-RPC Methods
You can now call JSON-RPC methods defined in the `http.md` document:

https://github.com/jito-labs/mev-protos/blob/master/json_rpc/http.md#json-rpc-api-reference

##### Example: getTipAccounts

###### Parameters
- `None`

```
sdk.get_tip_accounts()
```

##### Example: sendBundle

###### Parameters
- `<array[string]>`: `required` Fully-signed Transactions, as encoded string (base-58) upto a maximum of 5. Please note that at this point, we don't support base-64 encoded transactions

```
params = [
"4VbvoRYXFaXzDBUYfMXP1irhMZ9XRE6F1keS8GbYzKxgdpEasZtRv6GXxbygPp3yBVeSR4wN9JEauSTnVTKjuq3ktM3JpMebYpdGxZWUttJv9N2DzxBm4vhySdq2hbu1LQX7WxS2xsHG6vNwVCjP33Z2ZLP7S5dZujcan1Xq5Z2HibbbK3M3LD59QVuczyK44Fe3k27kVQ43oRH5L7KgpUS1vBoqTd9ZTzC32H62WPHJeLrQiNkmSB668FivXBAfMg13Svgiu9E",
"6HZu11s3SDBz5ytDj1tyBuoeUnwa1wPoKvq6ffivmfhTGahe3xvGpizJkofHCeDn1UgPN8sLABueKE326aGLXkn5yQyrrpuRF9q1TPZqqBMzcDvoJS1khPBprxnXcxNhMUbV78cS2R8LrCU29wjYk5b4JpVtF23ys4ZBZoNZKmPekAW9odcPVXb9HoMnWvx8xwqd7GsVB56R343vAX6HGUMoiB1WgR9jznG655WiXQTff5gPsCP3QJFTXC7iYEYtrcA3dUeZ3q4YK9ipdYZsgAS9H46i9dhDP2Zx3"
]
sdk.send_bundle(params)
```

##### Example: getBundleStatuses

###### Parameters
- `<array[string]>`: `required` An array of bundle ids to confirm, as base-58 encoded strings (up to a maximum of 5).
```
params = ["892b79ed49138bfb3aa5441f0df6e06ef34f9ee8f3976c15b323605bae0cf51d"]
sdk.get_bundle_statuses(params)
```

##### Example: sendTransaction

###### Parameters
- `[string]`: `required` Fully-signed Transaction, as encoded string.
```
params = [
"4hXTCkRzt9WyecNzV1XPgCDfGAZzQKNxLXgynz5QDuWWPSAZBZSHptvWRL3BjCvzUXRdKvHL2b7yGrRQcWyaqsaBCncVG7BFggS8w9snUts67BSh3EqKpXLUm5UMHfD7ZBe9GhARjbNQMLJ1QD3Spr6oMTBU6EhdB4RD8CP2xUxr2u3d6fos36PD98XS6oX8TQjLpsMwncs5DAMiD4nNnR8NBfyghGCWvCVifVwvA8B8TJxE1aiyiv2L429BCWfyzAme5sZW8rDb14NeCQHhZbtNqfXhcp2tAnaAT"
]
sdk.send_txn(params)
```

### Step 4: Handling Responses
The sdk RPC methods return the JSON response from the server. You can then handle the response according to your program's requirements. For an example, please see example.py when handling a bundle that was not found.
39 changes: 39 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from sdk.jito_jsonrpc_sdk import JitoJsonRpcSDK


def main():
# Initialize the SDK
# mainnet
#BLOCK_ENG_URL = "https://mainnet.block-engine.jito.wtf:443/api/v1"

# testnet
BLOCK_ENG_URL = "https://dallas.testnet.block-engine.jito.wtf/api/v1"
sdk = JitoJsonRpcSDK(BLOCK_ENG_URL)

# If you are using authentication which is not needed unless you request rate limit increase
#UUID_ENV = "JITO_UUID"
#sdk = JitoJsonRpcSDK(BLOCK_ENG_URL, UUID_ENV)

result = sdk.get_tip_accounts()
print(result)

params = [
"4VbvoRYXFaXzDBUYfMXP1irhMZ9XRE6F1keS8GbYzKxgdpEasZtRv6GXxbygPp3yBVeSR4wN9JEauSTnVTKjuq3ktM3JpMebYpdGxZWUttJv9N2DzxBm4vhySdq2hbu1LQX7WxS2xsHG6vNwVCjP33Z2ZLP7S5dZujcan1Xq5Z2HibbbK3M3LD59QVuczyK44Fe3k27kVQ43oRH5L7KgpUS1vBoqTd9ZTzC32H62WPHJeLrQiNkmSB668FivXBAfMg13Svgiu9E",
"6HZu11s3SDBz5ytDj1tyBuoeUnwa1wPoKvq6ffivmfhTGahe3xvGpizJkofHCeDn1UgPN8sLABueKE326aGLXkn5yQyrrpuRF9q1TPZqqBMzcDvoJS1khPBprxnXcxNhMUbV78cS2R8LrCU29wjYk5b4JpVtF23ys4ZBZoNZKmPekAW9odcPVXb9HoMnWvx8xwqd7GsVB56R343vAX6HGUMoiB1WgR9jznG655WiXQTff5gPsCP3QJFTXC7iYEYtrcA3dUeZ3q4YK9ipdYZsgAS9H46i9dhDP2Zx3"
]
result = sdk.send_bundle(params)
print(result)

params = ["892b79ed49138bfb3aa5441f0df6e06ef34f9ee8f3976c15b323605bae0cf51d"]
result = sdk.get_bundle_statuses(params)
print(result)

params = [
"4hXTCkRzt9WyecNzV1XPgCDfGAZzQKNxLXgynz5QDuWWPSAZBZSHptvWRL3BjCvzUXRdKvHL2b7yGrRQcWyaqsaBCncVG7BFggS8w9snUts67BSh3EqKpXLUm5UMHfD7ZBe9GhARjbNQMLJ1QD3Spr6oMTBU6EhdB4RD8CP2xUxr2u3d6fos36PD98XS6oX8TQjLpsMwncs5DAMiD4nNnR8NBfyghGCWvCVifVwvA8B8TJxE1aiyiv2L429BCWfyzAme5sZW8rDb14NeCQHhZbtNqfXhcp2tAnaAT"
]
result = sdk.send_txn(params)
print(result)


if __name__ == "__main__":
main()
Empty file added sdk/__init__.py
Empty file.
Binary file added sdk/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added sdk/__pycache__/jito_jsonrpc_sdk.cpython-310.pyc
Binary file not shown.
Loading

0 comments on commit 0635e43

Please sign in to comment.