# Running BLAST Testnet from Source

[**Please follow these steps first if you have not done so already.**](https://docs.blastblockchain.com/developer-docs/blast-node-operators/building-a-node-from-source)

### Create a shared secret between `op-geth` and `bl-node` <a href="#get-the-data-directory" id="get-the-data-directory"></a>

1. Navigate into your `op-geth` directory and run these commands:

```sh
openssl rand -hex 32 > jwt.txt
cp jwt.txt ../blast/bl-node
```

### Scripts to start the different components

In the root of your working directory create a new directory: `scripts`.

#### # `op-geth` <a href="#op-geth" id="op-geth"></a>

2. Create a new file:<br>

   ```sh
   touch run-op-geth.sh
   ```

3. Make it executable:<br>

   ```sh
   chmod +x run-op-geth.sh
   ```

4. Insert this snippet of code into `run-op-geth.sh` and modify the path to the `op-geth` directory.

   ```
   #! /usr/bin/bash
   SEQUENCER_URL=https://goerli-sequencer.blastblockchain.com/
   cd <>
   ./build/bin/geth
   --datadir=./datadir
   --http
   --http.port=8545
   --http.addr=0.0.0.0
   --authrpc.addr=localhost
   --authrpc.jwtsecret=./jwt.txt
   --verbosity=3
   --rollup.sequencerhttp=$SEQUENCER_URL
   --nodiscover
   --syncmode=full
   --maxpeers=0
   ```

Other Sequencer URLs can be found here: Networks, Public RPC Endpoints, & APIs.

1. Run the following command to start `op-geth`:

   ```
   ./run-op-geth.sh
   ```

### `op-node` <a href="#op-node" id="op-node"></a>

1. Navigate to the `scripts` directory you created.
2. Create a new file:

   ```
   touch run-bl-node.sh
   ```
3. Make it executable:

   ```
   chmod +x run-bl-node.sh
   ```
4. Insert this snippet of code into `run-bl-node.sh`:<br>

   ```sh
   #!/usr/bin/bash

   L1URL=<< L1 RPC URL >>
   L1KIND=basic

   cd <<Path to bl-node directory>>


   ./bin/bl-node \
       --l1=$L1URL  \
       --l1.rpckind=$L1KIND \
       --l2=ws://localhost:8551 \
       --l2.jwt-secret=./jwt.txt \
       --network=$NET \
       --rpc.addr=0.0.0.0 \
       --rpc.port=8547 \
       --rollup.config=./rollup.json
       
   ```

* Change `<< L1 RPC URL >>` to your local L1 node or a service provider's URL for the L1 node (L1 Ethereum). E.g. for Infura, `https://goerli.infura.io/v3/API_KEY`.
* Set `L1KIND` to the network provider you are using (options: alchemy, quicknode, infura, parity, nethermind, debug\_geth, erigon, basic, any).

5. Run the following command to start `op-node`:

   ```
   ./run-op-node.sh
   ```

## The initial synchronization

The datadir provided by Blast is not updated continuously, so before you can use the node you need a to synchronize it.

During that process you get log messages from `bl-node`, and nothing else appears to happen.

```
INFO [06-26|13:31:20.389] Advancing bq origin                      origin=17171d..1bc69b:8300332 originBehind=false
```

That is normal - it means that `bl-node` is looking for a location in the batch queue. After a few minutes it finds it, and then it can start synchronizing.

While it is synchronizing, you can expect log messages such as these from `bl-node`:

```
INFO [06-26|14:00:59.460] Sync progress                            reason="processed safe block derived from L1" l2_finalized=ef93e6..e0f367:4067805 l2_safe=7fe3f6..900127:4068014 l2_unsafe=7fe3f6..900127:4068014 l2_time=1,673,564,096 l1_derived=6079cd..be4231:8301091
INFO [06-26|14:00:59.460] Found next batch                         epoch=8e8a03..11a6de:8301087 batch_epoch=8301087 batch_timestamp=1,673,564,098
INFO [06-26|14:00:59.461] generated attributes in payload queue    txs=1  timestamp=1,673,564,098
INFO [06-26|14:00:59.463] inserted block                           hash=e80dc4..72a759 number=4,068,015 state_root=660ced..043025 timestamp=1,673,564,098 parent=7fe3f6..900127 prev_randao=78e43d..36f07a fee_recipient=0x4200000000000000000000000000000000000011 txs=1  update_safe=true
```

And log messages such as these from `op-geth`:

```
INFO [06-26|14:02:12.974] Imported new potential chain segment     number=4,068,194 hash=a334a0..609a83 blocks=1         txs=1         mgas=0.000  elapsed=1.482ms     mgasps=0.000   age=5mo2w20h dirty=2.31MiB
INFO [06-26|14:02:12.976] Chain head was updated                   number=4,068,194 hash=a334a0..609a83 root=e80f5e..dd06f9 elapsed="188.373µs" age=5mo2w20h
INFO [06-26|14:02:12.982] Starting work on payload                 id=0x5542117d680dbd4e
```

[**#**](https://community.optimism.io/docs/developers/nodes/testnet/#how-long-will-the-synchronization-take)**How long will the synchronization take?**

To estimate how long the synchronization will take, you need to first find out how many blocks you synchronize in a minute. You can use this [Foundry (opens new window)](https://book.getfoundry.sh/)script to get an estimated sync time.

1. Navigate to your `scripts` directory
2. Create a new file:

   ```
   touch run-estimate.sh
   ```
3. Make it executable:

   ```
   chmod +x run-estimate.sh
   ```
4. Insert this snippet of code into `run-estimate.sh`:

```
#!/usr/bin/bash

export ETH_RPC_URL=http://localhost:8545
CHAIN_ID=`cast chain-id`
echo Chain ID: $CHAIN_ID
echo Please wait

if [ $CHAIN_ID -eq 238 ]; then
  L2_URL=https://rpc.blastblockchain.com
fi


if [ $CHAIN_ID -eq 23888 ]; then
  L2_URL=https://testnet-rpc.blastblockchain.com
fi


T0=`cast block-number --rpc-url $ETH_RPC_URL` ; sleep 60 ; T1=`cast block-number --rpc-url $ETH_RPC_URL`
PER_MIN=`expr $T1 - $T0`
echo Blocks per minute: $PER_MIN


if [ $PER_MIN -eq 0 ]; then
    echo Not synching
    exit;
fi

# During that minute the head of the chain progressed by thirty blocks
PROGRESS_PER_MIN=`expr $PER_MIN - 30`
echo Progress per minute: $PROGRESS_PER_MIN


# How many more blocks do we need?
HEAD=`cast block-number --rpc-url $L2_URL`
BEHIND=`expr $HEAD - $T1`
MINUTES=`expr $BEHIND / $PROGRESS_PER_MIN`
HOURS=`expr $MINUTES / 60`
echo Hours until sync completed: $HOURS

if [ $HOURS -gt 24 ] ; then
   DAYS=`expr $HOURS / 24`
   echo Days until sync complete: $DAYS
fi
```

5. Run the following command to get an estimate:

   ```
   ./run-estimate.sh
   ```

#### [#](https://community.optimism.io/docs/developers/nodes/testnet/#operations)Operations <a href="#operations" id="operations"></a>

It is best to start `op-geth` first and shut it down last.<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.blastblockchain.com/developer-docs/blast-node-operators/running-blast-testnet-from-source.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
