> For the complete documentation index, see [llms.txt](https://0xreisearch.gitbook.io/0xreisearch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xreisearch.gitbook.io/0xreisearch/legacy/smarterc20-legacy.md).

# SmartERC20 (legacy)

The SmartERC20 implementation is a case study for the first token that can understand and analyze itself. Beyond standard ERC20 functionality, it enables natural language interactions with its own metrics, patterns, and state.

<figure><img src="https://1127208460-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEKEZNUf1k9neYaey5Nw%2Fuploads%2FYodCRlclGsfWc9hoihBq%2FScreenshot%202024-11-21%20at%2008.41.01.png?alt=media&amp;token=192413e7-7fb9-4c8f-af33-ace70570c7ed" alt=""><figcaption></figcaption></figure>

### Core Architecture

<figure><img src="https://1127208460-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEKEZNUf1k9neYaey5Nw%2Fuploads%2FgvCvg3h4cD9xiSmA2Z39%2FScreenshot%202024-11-21%20at%2008.31.55.png?alt=media&amp;token=a18879c3-5cad-4515-a3ca-cf8fc77a7a9f" alt=""><figcaption></figcaption></figure>

### Query Flow System

Users can interact with a SmartERC20 either via blockchain explorer or via a possibly dedicated dapp.

<figure><img src="https://1127208460-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEKEZNUf1k9neYaey5Nw%2Fuploads%2FvssJ9qSncU6LcH5WOT5J%2FScreenshot%202024-11-21%20at%2008.41.52.png?alt=media&amp;token=152cdf28-fdea-4283-8118-574b0c5e96a0" alt=""><figcaption></figcaption></figure>

### Natural Language Understanding

The token processes queries through sophisticated pattern matching:

<figure><img src="https://1127208460-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEKEZNUf1k9neYaey5Nw%2Fuploads%2FIyyEblvRwI8xtVLfce5Z%2FScreenshot%202024-11-21%20at%2008.43.07.png?alt=media&amp;token=e0d3cbe6-1d31-4489-8707-37cdb153adc6" alt="" width="349"><figcaption></figcaption></figure>

### Types of Analysis

The SmartERC20 can process various types of queries:

<figure><img src="https://1127208460-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEKEZNUf1k9neYaey5Nw%2Fuploads%2Fs7292VfZy0JtLhAj60W5%2FScreenshot%202024-11-21%20at%2008.45.17.png?alt=media&amp;token=0d968bdb-78bb-4c80-9c29-acf08f968361" alt=""><figcaption></figcaption></figure>

### Oracle Integration

A SmartERC20 token can leverage the Oracle System for sophisticated analysis, simply integrating an interface in its smart contract.

<figure><img src="https://1127208460-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEKEZNUf1k9neYaey5Nw%2Fuploads%2FDNqo4Nm5H7Ljw6nTalYU%2FScreenshot%202024-11-21%20at%2008.45.49.png?alt=media&amp;token=9fa42255-5f48-4da3-b91b-b96063ff37a5" alt=""><figcaption></figcaption></figure>

### Pricing Mechanism

Query costs are calculated based on computational complexity:

<figure><img src="https://1127208460-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEKEZNUf1k9neYaey5Nw%2Fuploads%2FA7O0G0pACXPW9Zl36XdI%2FScreenshot%202024-11-21%20at%2008.46.56.png?alt=media&amp;token=74762d55-fe2e-4c8b-a974-7d475144bb94" alt=""><figcaption></figcaption></figure>

### Memory and Learning

The token maintains sophisticated pattern recognition, in order to smooth the cost for highly requested analysis / data.

<figure><img src="https://1127208460-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEKEZNUf1k9neYaey5Nw%2Fuploads%2Fs5VLVC2RXVqFgbVb6e3l%2FScreenshot%202024-11-21%20at%2008.47.50.png?alt=media&amp;token=f29c4685-0e59-4c00-b2b9-8f30c09b404c" alt="" width="375"><figcaption></figcaption></figure>

### Analysis Capabilities

The SmartERC20 enables sophisticated analysis through natural language queries. Here are some examples with their actual implementations:

### 1. Holder Analysis

<figure><img src="https://1127208460-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEKEZNUf1k9neYaey5Nw%2Fuploads%2FFARM9SQdX27lZfSYCF9O%2FScreenshot%202024-11-21%20at%2008.51.22.png?alt=media&amp;token=91fce630-e383-4961-a3b7-8985b130f32b" alt=""><figcaption></figcaption></figure>

Example Response:

```json
{
    "analysis_type": "holder_distribution",
    "metrics": {
        "concentration_index": 0.72,
        "distribution_pattern": "power_law",
        "gini_coefficient": 0.68
    },
    "holders": {
        "above_1_percent": 12,
        "total_addresses": 2854,
        "average_holding": "350.45 tokens"
    }
}
```

### 2. Profit Analysis

<figure><img src="https://1127208460-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEKEZNUf1k9neYaey5Nw%2Fuploads%2FOg7FxOt9B286vsJ202jD%2FScreenshot%202024-11-21%20at%2008.52.02.png?alt=media&amp;token=0a066597-7451-44ef-8a93-8c7e75b16cf5" alt=""><figcaption></figcaption></figure>

Example Response:

```json
{
    "analysis_type": "profit_calculation",
    "top_10_metrics": {
        "average_profit_percentage": 28.5,
        "average_holding_period": "45 days",
        "total_realized_profit": "15.23 ETH"
    },
    "comparative_metrics": {
        "vs_market_average": "+12.3%",
        "risk_adjusted_return": 1.45
    }
}
```

### 3. Distribution Analysis

<figure><img src="https://1127208460-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEKEZNUf1k9neYaey5Nw%2Fuploads%2Fcijed4jyGX8dP4Wgqg0X%2FScreenshot%202024-11-21%20at%2008.52.44.png?alt=media&amp;token=04ff4bec-2ec6-48ff-acf5-d941890eace9" alt=""><figcaption></figcaption></figure>

Example Response:

```json
{
    "analysis_type": "distribution_analysis",
    "wallet_categories": {
        "retail": "45.2%",
        "medium": "32.1%",
        "whale": "22.7%"
    },
    "movement_trends": {
        "accumulation": true,
        "recent_direction": "decentralizing",
        "velocity": "moderate"
    },
    "risk_metrics": {
        "concentration_risk": "moderate",
        "distribution_health": 7.5
    }
}
```

### 4. Historical Analysis

<figure><img src="https://1127208460-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEKEZNUf1k9neYaey5Nw%2Fuploads%2FmIECVXstFb82Z7ZvaNmO%2FScreenshot%202024-11-21%20at%2008.53.33.png?alt=media&amp;token=414f38cd-7415-49ab-b7f4-7909db18f1fa" alt=""><figcaption></figcaption></figure>

Example Response:

```json
{
    "analysis_type": "historical_analysis",
    "launch_period": {
        "first_5_blocks": {
            "total_transfers": 124,
            "unique_buyers": 67,
            "volume_trend": "exponential_growth"
        },
        "key_events": {
            "first_whale_entry": "block 3",
            "liquidity_stabilization": "block 4",
            "price_discovery": "complete by block 5"
        }
    },
    "early_patterns": {
        "buying_pressure": "high",
        "holder_behavior": "accumulation",
        "liquidity_depth": "increasing"
    }
}
```

Each analysis type requires different computational resources and thus has different pricing in ETH. The complexity of the analysis, amount of historical data needed, and depth of pattern recognition all factor into the final query cost.

These analyses can be combined and refined through natural language queries, allowing users to drill down into specific aspects or broaden their analysis scope as needed.

The responses are structured for both human readability and programmatic usage, enabling integration with other systems while maintaining accessibility for direct user interaction.

### Implementation Details

Key components of the implementation:

<figure><img src="https://1127208460-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoEKEZNUf1k9neYaey5Nw%2Fuploads%2Fsf94m5wM47OPQmrHcbI1%2FScreenshot%202024-11-21%20at%2008.54.27.png?alt=media&amp;token=870151c1-4694-40cd-b587-5687b40bb1f0" alt=""><figcaption></figcaption></figure>

### Future Capabilities

The SmartERC20 demonstrates how traditional token contracts can evolve into intelligent systems that understand their own state and patterns. Through natural language interaction and sophisticated analysis, it provides a new model for blockchain asset interaction.

This implementation serves as both a practical tool and a proof of concept, showing how the REI Framework enables new kinds of blockchain interactions.
