> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monad.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuring RPC to use archive data

<Warning title="This is not for validator nodes">
  Integration with the archive is designed for full nodes servicing RPC requests, **not for validator
  nodes**.
</Warning>

<Note title="Enabling call traces">
  Enabling `--trace_calls` is recommended for **RPC** nodes.
  This preserves the detailed error information necessary for call traces, e.g. `debug_traceTransaction`.
  To make this override, please run `sudo systemctl edit monad-execution` and add the `--trace_calls` CLI param
  to the `ExecStart` definition (may need a line continuation character `\`):

  ```sh theme={null}
  sudo systemctl edit monad-execution
  ```

  ```toml theme={null}
  [Service]
  Type=simple
  ExecStart=
  ExecStart=/usr/local/bin/monad \
      [... existing cli commands, see comment at the bottom of the systemctl editor ...]
      --trace_calls
  ```
</Note>

## Configuring `monad-rpc` with Archive Server backup

1. Configure an [Archive Server](/node-ops/archive-data/running-an-archive-server) that is geographically close to
   this full node.

2. Add the following vars to your `/home/monad/.env`:

   ```sh theme={null}
   # Replace <db username>, <db pwd> and <db hostname> with your values from Step (1)
   MONGO_URL="mongodb://<db username>:<db pwd>@<db hostname>:27017"
   MONGO_DB_NAME="archive-db"
   DB_HOST=<db hostname>
   DB_PWD=<db pwd>
   DB_USERNAME=<db username>
   ```

3. Verify connectivity:

   ```sh theme={null}
   source /home/monad/.env

   nc -vz $DB_HOST 27017
   mongosh "$MONGO_URL" --quiet --eval '
       try {
       db.adminCommand({ping: 1});
       const archiveDb = db.getSiblingDB("archive-db");
       const hasCollection = archiveDb.getCollectionNames().includes("block_level");
       print(hasCollection ? "OK: Collection exists" : "FAIL: Collection missing");
       quit(hasCollection ? 0 : 1);
       } catch(e) {
       print("FAIL: " + e.message);
       quit(1);
       }
   '
   ```

4. Add the following systemd override to `monad-rpc`:

   ```sh theme={null}
   sudo systemctl edit monad-rpc
   ```

   ```toml theme={null}
   [Service]
   ExecStart=
   ExecStart=/usr/local/bin/monad-rpc \
       [... existing cli commands, see comment at the bottom of the systemctl editor ...]
       --mongo-url ${MONGO_URL} \
       --mongo-db-name ${MONGO_DB_NAME} \
       --use-eth-get-logs-index
   ```

5. Reload and restart:

   ```sh theme={null}
   sudo systemctl daemon-reload
   sudo systemctl restart monad-rpc
   ```

6. Check for an early block outside local retention:

   ```sh theme={null}
   curl -X POST -H "Content-Type: application/json" --data '{
           "jsonrpc": "2.0",
           "method": "eth_getBlockByNumber",
           "params": ["0x1", false],
           "id": 1
       }'  http://localhost:8080
   ```

## Configuring `monad-rpc` with AWS backup

1. Ensure an AWS identity and credentials are on the box.

   * Run `aws configure` to setup your AWS credentials and config on the full node. This should
     generate `config` and `credentials` files under `/home/monad/.aws/`. See the
     [AWS CLI docs](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html).
   * When running in systemd, AWS permissions need to be created under `monad` user. See the
     general validator or fullnode docs for the broader instructions to run rpc, but ensure the
     `monad` user has aws credentials with access to the bucket.

2. Create an AWS IAM policy using this [user guide](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create-console.html#access_policies_create-json-editor) and the following sample json:

   ```json theme={null}
   {
       "Version": "2012-10-17",
       "Statement": [
           {
               "Effect": "Allow",
               "Action": [
                   "s3:GetObject",
                   "s3:ListBucket",
                   "s3:GetBucketRequestPayment",
                   "execute-api:Invoke"
               ],
               "Resource": [
                   "arn:aws:s3:::*/*",
                   "arn:aws:s3:::*",
                   "arn:aws:execute-api:*:*:*"
               ],
               "Condition": {
                   "StringEquals": {
                       "aws:ResourceOrgID": "o-sq9ayub2wk"
                   }
               }
           }
       ]
   }
   ```

3. To obtain a free-tier api-key, send an AWS Signature v4 signed request to `https://9df09fanz1.execute-api.us-east-2.amazonaws.com/prod/free-tier-key`

   * ex. using `awscurl` utility:

     ```bash theme={null}
     awscurl https://9df09fanz1.execute-api.us-east-2.amazonaws.com/prod/free-tier-key --region us-east-2
     ```

4. Add the following vars to your `/home/monad/.env`:

   ```sh theme={null}
   ARCHIVE_API_KEY=<key from step 3>
   # Replace with appropriate mainnet, localnet or testnet bucket
   # Below is the public testnet bucket maintained by Category Labs
   ARCHIVE_BUCKET="testnet-can-004-0-aavn9ll"
   # Below is the public mainnet bucket maintained by Category Labs
   ARCHIVE_BUCKET="mainnet-deu-010-0" # mainnet-deu-009-0 is a sibling bucket you can also use
   ```

5. Add the following systemd override to `monad-rpc`:

   ```sh theme={null}
   sudo systemctl edit monad-rpc
   ```

   ```toml theme={null}
   [Service]
   ExecStart=
   ExecStart=/usr/local/bin/monad-rpc \
       [... existing cli commands, see comment at the bottom of the systemctl editor ...]
       --s3-bucket ${ARCHIVE_BUCKET} \
       --region "us-east-2" \
       --archive-url "https://9df09fanz1.execute-api.us-east-2.amazonaws.com/prod" \
       --archive-api-key ${ARCHIVE_API_KEY}
   ```

6. Reload and restart:

   ```sh theme={null}
   sudo systemctl daemon-reload
   sudo systemctl restart monad-rpc
   ```

7. Check for an early block outside local retention:

   <Note>
     If you already have MongoDB backend enabled, this will not test anything by default. To test,
     temporarily remove the MongoDB backend, run the following and restore the MongoDB config.
   </Note>

   ```sh theme={null}
   curl -X POST -H "Content-Type: application/json" --data '{
           "jsonrpc": "2.0",
           "method": "eth_getBlockByNumber",
           "params": ["0x1", false],
           "id": 1
       }'  http://localhost:8080
   ```
