File size: 4,419 Bytes
49ea428
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 📄 Database Structure: `contracts` Table

This document describes the structure and purpose of the `contracts` table within the databases.  
The table stores metadata and deployment details of smart contracts.

## 📌 Table Description

Each record stored in the table has the following structure and fields, with described constraints.

| Column Name         | Type       | Constraints         | Description                                                               - |
|---------------------|------------|---------------------|-----------------------------------------------------------------------------|
| `address`           | TEXT       | PRIMARY KEY         | The unique address of the smart contract on the blockchain.                 |
| `creator`           | TEXT       | NOT NULL            | The address of the account that deployed the contract.                      |
| `creation_tx`       | TEXT       | NOT NULL            | The transaction hash that created the contract.                             |
| `creation_time`     | TIMESTAMP  | NOT NULL            | The timestamp when the contract was deployed.                               |
| `creation_block`    | INTEGER    | NOT NULL            | The block number in which the contract was created.                         |
| `name`              | TEXT       | NULLABLE            | The human-readable name of the contract, if available.                      |
| `source_code`       | TEXT       | NULLABLE            | The full Solidity source code of the contract.                              |
| `abi`               | TEXT       | NULLABLE            | The Application Binary Interface (ABI) of the contract.                     |
| `compiler_version`  | TEXT       | NULLABLE            | The Solidity compiler version used to compile the contract.                 |
| `evm_version`       | TEXT       | NULLABLE            | The targeted Ethereum Virtual Machine (EVM) version.                        |
| `optimization_used` | BOOLEAN    | NULLABLE            | Indicates whether compiler optimizations were enabled.                      |
| `runs`              | INTEGER    | NULLABLE            | Number of optimization runs used during compilation.                        |
| `constructor_args`  | TEXT       | NULLABLE            | Encoded constructor arguments passed during deployment.                     |
| `library`           | TEXT       | NULLABLE            | Linked library information, if any.                                         |
| `license`           | TEXT       | NULLABLE            | License type of the source code (e.g., MIT, GPL-3.0).                       |
| `is_proxy`          | BOOLEAN    | NULLABLE            | Flag indicating whether the contract is a proxy.                            |
| `implementation`    | TEXT       | NULLABLE            | Address of the implementation contract, if this is a proxy.                 |
| `swarm_source`      | TEXT       | NULLABLE            | Swarm hash / metadata URL pointing to the source code bundle.               |

📝 Notes:
- The **primary key** `address` ensures uniqueness for each deployed contract in the corresponding chain.
- `creation_tx`, `creation_time`, and `creation_block` stores contract’s deployment information, i.e. transaction id, timestamp, and block number.
- `source_code`, `abi`, and `compiler_version` are typically available when the contract has been verified.
- Proxy patterns are identified through `is_proxy` and `implementation`.


## 🧱 Table Definition

```sql
CREATE TABLE IF NOT EXISTS contracts (
    address TEXT PRIMARY KEY,
    creator TEXT NOT NULL,
    creation_tx TEXT NOT NULL,
    creation_time TIMESTAMP NOT NULL,
    creation_block INTEGER NOT NULL,
    name TEXT,
    source_code TEXT,
    abi TEXT,
    compiler_version TEXT,
    evm_version TEXT,
    optimization_used BOOLEAN,
    runs INTEGER,
    constructor_args TEXT,
    library TEXT,
    license TEXT,
    is_proxy BOOLEAN,
    implementation TEXT,
    swarm_source TEXT
);
```

## 🧭 Usage Example

```sql
SELECT address, name, compiler_version, source_code
FROM contracts
WHERE source_code IS NOT NULL AND source_code != ""
ORDER BY creation_block DESC
LIMIT 10;
```
This query returns the 10 most recently deployed contracts with available **source code** along with their addresses, names and compiler versions.


---
license: mit
---