Skip to content

Commit

Permalink
Example scripts now read from environment variables without manual ch…
Browse files Browse the repository at this point in the history
…anges. Added Acknowledgments to the Readme.
  • Loading branch information
ZigaMr committed Oct 4, 2023
1 parent d5c062e commit 41c2cee
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 23 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ his = asyncio.run(client.get_event_history(params=params))
## Examples

All examples are located in the [```examples```](./examples) directory.
Before running the scripts, make sure to set the environment variables.

## Contributing

Expand Down Expand Up @@ -303,11 +304,15 @@ SOFTWARE.


## Acknowledgments
I would like to express my gratitude to the following individuals and organizations who have contributed to this project:
### Contributors
- Brock Smedley ([@zeroXbrock](https://github.com/zeroXbrock)) - Oversaw the project and provided valuable feedback.
- Flashbots ([@flashbots](https://www.flashbots.net/) Organization that provided the initial idea and specifications for the project.

## FAQs

## Troubleshooting
### External Libraries and Dependencies
- [aiohttp-sse-client](https://pypi.org/project/aiohttp-sse-client/) - By [Jason Hu]([email protected])
- [web3.py](https://github.com/ethereum/web3.py) - By [Ethereum Foundation](https://ethereum.org/en/)

## Contact

For questions or feedback, contact [email protected]
For questions or feedback, contact [email protected] or ask in Flashbots [Discord](https://discord.com/channels/755466764501909692/1098658519676371045)
1 change: 1 addition & 0 deletions examples/event_stream_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import datetime as dt
import os
import asyncio
from mev_share_py.client import MevShareClient
from mev_share_py.api.events import PendingTransaction
Expand Down
28 changes: 21 additions & 7 deletions examples/private_tx.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import asyncio
import os
from web3 import Web3
from mev_share_py.client import MevShareClient


# Set environment variables before running this script
try:
private_key = os.environ.get('PRIVATE_KEY')
to = os.environ.get('TO_ADDRESS')
api_url = os.environ.get('API_URL')
stream_url = os.environ.get('STREAM_URL')
sign_key = os.environ.get('SIGN_KEY')
node_url = os.environ.get('NODE_URL')
except KeyError as e:
print(f"Please set the environment variable {e}")
exit(1)



def new_tx(w3,
nonce_add=0,
private_key='0x',
Expand Down Expand Up @@ -47,19 +62,18 @@ async def loop_tx():
Set the wallet and node settings in config.json
:return:
"""
client = MevShareClient(api_url='<RPC_url>', # "https://relay-goerli.flashbots.net/",
stream_url='<SSE_url>', # "https://mev-share-goerli.flashbots.net/",
sign_key='<sign_key>', # Private key to sign the bundle
node_url='<node_url>' # Geth node url
client = MevShareClient(api_url=api_url, # "https://relay-goerli.flashbots.net/",
stream_url=stream_url, # "https://mev-share-goerli.flashbots.net/",
sign_key=sign_key, # Private key to sign the bundle
node_url=node_url # Geth node url
)
private_key = '<private_key>
to_address = '<to_address>'

while True:
# pylint: disable=redefined-outer-name
tx = new_tx(client.w3,
0,
private_key,
to_address)
to)
print(tx)
print(await client.send_transaction(
tx.rawTransaction.hex(),
Expand Down
22 changes: 16 additions & 6 deletions examples/send_bundle.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
# pylint: disable=missing-module-docstring
import asyncio
import os
from examples.private_tx import new_tx
from mev_share_py.client import MevShareClient
from mev_share_py.api.types import BundleParams
from mev_share_py.api.events import PendingTransaction


# Set environment variables before running this script
try:
private_key = os.environ.get('PRIVATE_KEY')
to = os.environ.get('TO_ADDRESS')
api_url = os.environ.get('API_URL')
stream_url = os.environ.get('STREAM_URL')
sign_key = os.environ.get('SIGN_KEY')
node_url = os.environ.get('NODE_URL')
except KeyError as e:
print(f"Please set the environment variable {e}")
exit(1)

async def build_and_send(tx: PendingTransaction, client: MevShareClient):
"""
Generate a bundle containing private tx hash and backrun signed tx.
:return:
"""
private_key = '<private_key>
to = '<to_address>'
backrun_transaction = new_tx(client.w3, 0, private_key, to) # Add raw tx here

user_tx_hash = tx.hash
Expand Down Expand Up @@ -42,10 +52,10 @@ async def build_and_send(tx: PendingTransaction, client: MevShareClient):
print(await client.send_bundle(params))

if __name__ == "__main__":
client = MevShareClient(api_url='<RPC_url>', # "https://relay-goerli.flashbots.net/",
stream_url='<SSE_url>', # "https://mev-share-goerli.flashbots.net/",
sign_key='<sign_key>', # Private key to sign the bundle
node_url='<node_url>' # Geth node url
client = MevShareClient(api_url=api_url, # "https://relay-goerli.flashbots.net/",
stream_url=stream_url, # "https://mev-share-goerli.flashbots.net/",
sign_key=sign_key, # Private key to sign the bundle
node_url=node_url # Geth node url
)

res = asyncio.run(
Expand Down
22 changes: 16 additions & 6 deletions examples/simulate_bundle.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import asyncio
import os
from mev_share_py.api.types import BundleParams
from mev_share_py.client import MevShareClient
from mev_share_py.api.events import PendingTransaction
from send_bundle import new_tx

# Set environment variables before running this script
try:
private_key = os.environ.get('PRIVATE_KEY')
to = os.environ.get('TO_ADDRESS')
api_url = os.environ.get('API_URL')
stream_url = os.environ.get('STREAM_URL')
sign_key = os.environ.get('SIGN_KEY')
node_url = os.environ.get('NODE_URL')
except KeyError as e:
print(f"Please set the environment variable {e}")
exit(1)



Expand All @@ -14,8 +26,6 @@ async def sim_private_tx_backrun(tx: PendingTransaction, client: MevShareClient)
:return: None
"""

private_key = '<private_key>'
to = '<to_address>'
backrun_transaction = new_tx(client.w3, 0, private_key, to) # Add raw tx here
backrun_signed_tx = backrun_transaction.rawTransaction.hex()
pending_tx = tx.hash
Expand Down Expand Up @@ -48,10 +58,10 @@ async def sim_private_tx_backrun(tx: PendingTransaction, client: MevShareClient)
return await client.simulate_bundle(params, sim_options)

if __name__ == "__main__":
client = MevShareClient(api_url='<RPC_url>', # "https://relay-goerli.flashbots.net/",
stream_url='<SSE_url>', # "https://mev-share-goerli.flashbots.net/",
sign_key='<sign_key>', # Private key to sign the bundle
node_url='<node_url>' # Geth node url
client = MevShareClient(api_url=api_url, # "https://relay-goerli.flashbots.net/",
stream_url=stream_url, # "https://mev-share-goerli.flashbots.net/",
sign_key=sign_key, # Private key to sign the bundle
node_url=node_url # Geth node url
)
res = asyncio.run(
client.listen_for_events('transaction', sim_private_tx_backrun),
Expand Down

0 comments on commit 41c2cee

Please sign in to comment.