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

# Query Builder Codes

> Query onchain activity attributed to your Builder Code on Base using the SQL API—EOA transactions and ERC-4337 user operations, no custom indexer required.

[Builder Codes](https://docs.base.org/apps/builder-codes/builder-codes) are [ERC-8021](https://eip.tools/eip/8021) attribution codes that associate onchain activity with the app, wallet, or agent that drove it. CDP SQL API indexes this attribution metadata on Base so you can measure the activity tied to your code with standard SQL—no custom indexer required.

<Tip>
  Get your Builder Code by registering on [base.dev](https://base.dev/). You can find your code under **Settings** → **Builder Code**.
</Tip>

## Where Builder Code data lives

Attribution is indexed into two tables, because Base carries Builder Codes differently for regular (EOA) transactions and for smart-account (ERC-4337) user operations.

| Table                                                                                 | What it covers                   | Builder Code column                                                                  |
| ------------------------------------------------------------------------------------- | -------------------------------- | ------------------------------------------------------------------------------------ |
| [`base.transaction_attributions`](/data/sql-api/schema#base-transaction-attributions) | EOA transaction attributions     | `builder_code` (`String`) — **one row per Builder Code**                             |
| [`base.decoded_user_operations`](/data/sql-api/schema#base-decoded-user-operations)   | Decoded ERC-4337 user operations | `builder_codes` (`Array(String)`) — a single user operation can carry multiple codes |

Two things to keep in mind when querying either table:

* **Deduplicate transactions.** In `base.transaction_attributions` a transaction attributed to multiple Builder Codes appears once per code, so count `DISTINCT transaction_hash` when you want a transaction count.
* **Scope to active rows.** Both tables use an `action` column (`Int8`): `1` means the record was added to the chain and `-1` means it was removed by a re-org. Filter `action = 1` for a quick view, or aggregate with `SUM(action) > 0` if you need re-org-safe totals.

See the [schema reference](/data/sql-api/schema) for the full column list of each table.

## Access

<CardGroup cols={2}>
  <Card title="SQL Playground" icon="browser" href="https://portal.cdp.coinbase.com/entity_17c669d9-700e-5961-a976-7b1e6808307d/onchain-tools/sql-api?project=0279a200-1ec1-4a11-a3bf-0d0bbd139987&q=U0VMRUNUIHVzZXJfb3BfaGFzaCwgdHJhbnNhY3Rpb25faGFzaCwgc2VuZGVyLCBibG9ja190aW1lc3RhbXAsIHN1Y2Nlc3MKRlJPTSBiYXNlLmRlY29kZWRfdXNlcl9vcGVyYXRpb25zCldIRVJFIGhhcyhidWlsZGVyX2NvZGVzLCAneW91cl9idWlsZGVyX2NvZGUnKQogIEFORCBhY3Rpb24gPSAxCk9SREVSIEJZIGJsb2NrX3RpbWVzdGFtcCBERVNDCkxJTUlUIDEwMDs%3D">
    Try queries in your browser (no API keys needed)
  </Card>

  <Card title="REST API" icon="code" href="/data/sql-api/rest-apis">
    Programmatic access with free API keys
  </Card>
</CardGroup>

## Example queries

<Tip>
  Try these in the [SQL Playground](https://portal.cdp.coinbase.com/onchain-tools/sql-api) before integrating programmatically. Replace `your_builder_code` with your own code.
</Tip>

### EOA transactions for a Builder Code

Most recent transactions attributed to your code:

```sql theme={null}
SELECT transaction_hash, block_number, block_timestamp
FROM base.transaction_attributions
WHERE builder_code = 'your_builder_code'
  AND action = 1
ORDER BY block_timestamp DESC
LIMIT 100;
```

### User operations for a Builder Code

`builder_codes` is an array, so use `has()` to match your code within a user operation:

```sql theme={null}
SELECT user_op_hash, transaction_hash, sender, block_timestamp, success
FROM base.decoded_user_operations
WHERE has(builder_codes, 'your_builder_code')
  AND action = 1
ORDER BY block_timestamp DESC
LIMIT 100;
```

### Daily attributed transaction count

Count distinct EOA transactions per day for your code:

````sql theme={null}
SELECT
  toDate(block_timestamp) AS day,
  COUNT(DISTINCT transaction_hash) AS transactions
FROM base.transaction_attributions
WHERE builder_code = 'your_builder_code'
  AND action = 1
GROUP BY day
ORDER BY day DESC;

### Total attributed activity across EOAs and user operations

Combine both surfaces into a single count of distinct attributed transactions:

```sql
SELECT SUM(transactions) AS total_attributed_transactions
FROM (
  SELECT COUNT(DISTINCT transaction_hash) AS transactions
  FROM base.transaction_attributions
  WHERE builder_code = 'your_builder_code'
    AND action = 1

  UNION ALL

  SELECT COUNT(DISTINCT transaction_hash) AS transactions
  FROM base.decoded_user_operations
  WHERE has(builder_codes, 'your_builder_code')
    AND action = 1
);
````

## Query tips

Follow the [SQL API best practices](/data/sql-api/best-practices) when querying attribution data:

1. **Match the right column per table** — filter `builder_code = '...'` on `base.transaction_attributions` and `has(builder_codes, '...')` on `base.decoded_user_operations`.
2. **Deduplicate transactions** — a transaction attributed to multiple codes appears once per code in `base.transaction_attributions`; count `DISTINCT transaction_hash`.
3. **Scope to active records** — add `action = 1` for a quick view, or `SUM(action) > 0` in a `HAVING`/aggregate for re-org-safe totals.
4. **Bound your scan** — filter on `block_timestamp` and add a `LIMIT` while iterating to keep queries fast.

## Learn more

* [Builder Codes overview](https://docs.base.org/apps/builder-codes/builder-codes) — what Builder Codes are and how to register
* [Schema reference](/data/sql-api/schema) — full column definitions for `base.transaction_attributions` and `base.decoded_user_operations`
* [Quickstart](/data/sql-api/quickstart) — run your first SQL API query
* [Best practices](/data/sql-api/best-practices) — write fast, correct SQL API queries
