Skip to content

Commit

Permalink
Merge pull request #173 from chainbound/chore/client/update
Browse files Browse the repository at this point in the history
chore(client): small update
  • Loading branch information
thedevbirb authored Jul 30, 2024
2 parents 990fd4c + 4b5c5ac commit d0d919d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
45 changes: 31 additions & 14 deletions bolt-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,43 @@ This is a simple CLI tool to interact with Bolt.

## Requirements

- Rust toolchain & Cargo
- [Rust toolchain & Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html) installed
- A wallet with some funds to send transactions

## How to use

1. Prepare the environment variables (either in a `.env` file, or as CLI arguments):
Bolt Client offers different ways to send commitment requests. Here's how to use them:

- `BOLT_RPC_URL` or `--rpc-url`: the URL of the Bolt RPC server (default: Chainbound's RPC)
- `BOLT_PRIVATE_KEY` or `--private-key`: the private key of the account to send transactions from
- `BOLT_NONCE_OFFSET` or `--nonce-offset`: the offset to add to the account's nonce (default: 0)
- `--blob`: bool flag to send a blob-carrying transaction (default: false)
### Use the default Bolt RPC

**Optionally**, you can use the following flags to fetch the lookahead data from the beacon chain directly
instead of relying on the RPC server:
For regular usage, you can use the default Bolt RPC server to automatically fetch the
lookahead data from the beacon chain and send the transaction to the next Bolt sidecar in line.

To do this, prepare the environment variables (either in a `.env` file, or as CLI arguments):

- `BOLT_PRIVATE_KEY` or `--private-key`: the private key of the account to send transactions from
- `--blob`: bool flag to send a blob-carrying transaction (default: false)
- `--count`: the number of transactions to send in a single request (default: 1)

Run the CLI tool:

```shell
cargo run
```

### Use your own beacon node and registry contract

If you don't want to use the default RPC server, you can send transactions manually.
To do this, you need to provide the following environment variables (either in a `.env` file, or as CLI arguments):

- `--use-registry`: bool flag to fetch data from a local node instead of the RPC_URL (default: false)
- `BOLT_REGISTRY_ADDRESS` or `--registry-address`: the address of the bolt-registry contract
- `BOLT_BEACON_CLIENT_URL` or `--beacon-client-url`: the URL of the CL node to use
- `BOLT_RPC_URL` or `--rpc-url`: the URL of an execution client (e.g. Geth)'s RPC server (default: Chainbound's RPC)
- `BOLT_NONCE_OFFSET` or `--nonce-offset`: the offset to add to the account's nonce (default: 0)
- `BOLT_REGISTRY_ADDRESS` or `--registry-address`: the address of the bolt-registry smart contract
- `BOLT_BEACON_CLIENT_URL` or `--beacon-client-url`: the URL of the beacon client's HTTP server

1. Run the CLI tool with the desired command and arguments, if any.
Run the CLI tool with the desired command and arguments, if any.

```shell
cargo run -- [options]
```
```shell
cargo run -- [options]
```
34 changes: 14 additions & 20 deletions bolt-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloy::{
eips::eip2718::Encodable2718,
hex,
network::{EthereumWallet, TransactionBuilder},
primitives::{Address, B256},
primitives::{address, Address, B256},
providers::{Provider, ProviderBuilder},
signers::local::PrivateKeySigner,
};
Expand All @@ -19,47 +19,43 @@ use registry::BoltRegistry;
mod utils;
use utils::*;

// Default Bolt RPC URL (on Helder)
pub const DEFAULT_RPC_URL: &str = "https://bolt.chainbound.io/rpc";

// Default Bolt-Registry address (on Helder)
pub const DEFAULT_REGISTRY: Address = address!("dF11D829eeC4C192774F3Ec171D822f6Cb4C14d9");

#[derive(Parser)]
struct Opts {
/// Bolt RPC URL to send requests to
#[clap(
short = 'p',
long,
default_value = "http://135.181.191.125:8015/rpc",
env = "BOLT_RPC_URL"
)]
#[clap(long, default_value = DEFAULT_RPC_URL, env = "BOLT_RPC_URL")]
rpc_url: Url,
/// Private key to sign transactions with
#[clap(short = 'k', long, env = "BOLT_PRIVATE_KEY")]
private_key: String,
/// Optional nonce offset to use for the transaction
#[clap(short, long, default_value_t = 0, env = "BOLT_NONCE_OFFSET")]
#[clap(long, default_value_t = 0, env = "BOLT_NONCE_OFFSET")]
nonce_offset: u64,
/// Flag for generating a blob tx instead of a regular tx
#[clap(long, default_value_t = false)]
blob: bool,
/// Number of transactions to send in a sequence
#[clap(short, long, default_value_t = 1)]
#[clap(long, default_value_t = 1)]
count: u64,
/// Flag for sending all "count" transactions in a single bundle
#[clap(long, default_value_t = false)]
bundle: bool,

/// Flag for using the registry to fetch the lookahead
#[clap(short, long, default_value_t = false, requires_ifs([("true", "registry_address"), ("true", "beacon_client_url")]))]
#[clap(long, default_value_t = false, requires_ifs([("true", "registry_address"), ("true", "beacon_client_url")]))]
use_registry: bool,
/// URL of the beacon client to use for fetching the lookahead
/// (only used with the "use-registry" flag)
#[clap(short = 'b', long, env = "BOLT_BEACON_CLIENT_URL")]
beacon_client_url: Option<Url>,
/// Address of the registry contract to read bolt sidecars from
/// (only used with the "use-registry" flag)
#[clap(
short,
long,
env = "BOLT_REGISTRY_ADDRESS",
default_value = "0xdF11D829eeC4C192774F3Ec171D822f6Cb4C14d9"
)]
#[clap(long, env = "BOLT_REGISTRY_ADDRESS", default_value_t = DEFAULT_REGISTRY)]
registry_address: Address,
}

Expand Down Expand Up @@ -88,12 +84,10 @@ async fn main() -> Result<()> {
Err(e) => bail!("error fetching next preconfer slot from registry: {:?}", e),
}
} else {
// TODO: remove "cbOnly=true"
let url =
opts.rpc_url.join("proposers/lookahead?activeOnly=true&futureOnly=true&cbOnly=true")?;
let url = opts.rpc_url.join("proposers/lookahead?activeOnly=true&futureOnly=true")?;
let lookahead_response = reqwest::get(url).await?.json::<Value>().await?;
if lookahead_response.as_array().unwrap_or(&vec![]).is_empty() {
bail!("no bolt proposer found in lookahead, try again later");
bail!("no bolt proposer found in lookahead, try again later 🥲");
}
let next_preconfer_slot = lookahead_response[0].get("slot").unwrap().as_u64().unwrap();
(opts.rpc_url, next_preconfer_slot)
Expand Down

0 comments on commit d0d919d

Please sign in to comment.