> For the complete documentation index, see [llms.txt](https://docs.xyxyx.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.xyxyx.pro/xyxyx-text-based-tokenization-architecture-xtbta/data-encoding.md).

# Data Encoding

### Overview

The [Xyxyx Text-Based Tokenization Architecture (XTBTA)](/xyxyx-text-based-tokenization-architecture-xtbta.md) incorporates an entirely blockchain-based framework for the generation and lifecycle management of[ Text-Based Tokens (TBTs)](/text-based-tokens-tbts.md).&#x20;

Instead of relying on IPFS or centralized servers for metadata storage and retrieval, XTBTA stores all relevant information — including the token’s visual representation — entirely within the Ethereum blockchain.

TBTs are visually rendered using SVG (Scalable Vector Graphics), encoded in Base64, and embedded in the smart contract’s metadata delivery. As a result, this ensures each token is fully self-contained, tamper-proof, and persistently accessible.

***

### Key Features

#### Base64-Encoded SVG Outputs

TBTs utilize SVG to represent token visuals in a scalable, resolution-independent manner.&#x20;

These SVG documents are programmatically generated and encoded in Base64. XTBTA proposes the encoding of each TBT's SVG output into a Base64 string that is embedded in a JSON object, which is itself Base64-encoded and returned as a `tokenURI`.&#x20;

***

#### On-Chain Data Delivery

Each TBT implements the `tokenURI()` function as defined by the ERC-721 standard. However, unlike conventional implementations that return a pointer to external JSON metadata, TBTs contracts return a fully self-contained, Base64-encoded metadata object. This object includes the encoded SVG visual and any relevant descriptive fields — delivered entirely from within the smart contract; without the need for off-chain servers.

As a result, XTBTA ensures that front-ends, indexers, and explorers can interpret and render the token without accessing any external infrastructure.

***

### Functionality

Through XTBTA, each token’s metadata is programmatically constructed and encoded directly within the smart contract. This approach ensures that all descriptive and visual elements — such as the token’s name, description, and image — are embedded on-chain in a self-contained format.&#x20;

The following example illustrates the step-by-step process through which a token’s metadata is constructed, encoded, and prepared for delivery via the `tokenURI` function:

1. **Base64-Encoded Token URI**

{% code overflow="wrap" %}

```uri
data:application/json;base64,eyJuYW1lIjogIlh5eHl4ICMxIiwgImRlc2NyaXB0aW9uIjogIiIsICJpbWFnZSI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akpsYlNJZ1ptOXVkQzFtWVcxcGJIazlJaWRCY21saGJDY3NJSE5oYm5NdGMyVnlhV1lpSUdadmJuUXRjMmw2WlQwaU1UQndlQ0krU1hOemRXVWdSR0YwWlRvZ01qQXlOUzB3TlMwd01TQWdQQzkwYzNCaGJqNDhkSE53WVc0Z2VEMGlNVEFpSUdSNVBTSXhMakpsYlNJZ1ptOXVkQzFtWVcxcGJIazlJaWRCY21saGJDY3NJSE5oYm5NdGMyVnlhV1lpSUdadmJuUXRjMmw2WlQwaU1UQndlQ0krVFdGMGRYSnBkSGtnUkdGMFpUb2dNakF5TlMwd055MHpNU0FnUEM5MGMzQmhiajQ4ZEhOd1lXNGdlRDBpTVRBaUlHUjVQU0l4TGpKbGJTSWdabTl1ZEMxbVlXMXBiSGs5SWlkQmNtbGhiQ2NzSUhOaGJuTXRjMlZ5YVdZaUlHWnZiblF0YzJsNlpUMGlNVEJ3ZUNJK1JHbHpZMjkxYm5RZ1VtRjBaVG9nTlM0eE1pVWdJRHd2ZEhOd1lXNCtQSFJ6Y0dGdUlIZzlJakV3SWlCa2VUMGlNUzR5WlcwaUlHWnZiblF0Wm1GdGFXeDVQU0luUVhKcFlXd25MQ0J6WVc1ekxYTmxjbWxtSWlCbWIyNTBMWE5wZW1VOUlqRXdjSGdpUGtaaFkyVWdWbUZzZFdVNklDUXhMREF3TUNBZ1BDOTBjM0JoYmo0OGRITndZVzRnZUQwaU1UQWlJR1I1UFNJeExqSmxiU0lnWm05dWRDMW1ZVzFwYkhrOUlpZEJjbWxoYkNjc0lITmhibk10YzJWeWFXWWlJR1p2Ym5RdGMybDZaVDBpTVRCd2VDSStVSFZ5WTJoaGMyVWdVSEpwWTJVNklDUTVPRGN1TWpBOEwzUnpjR0Z1UGp3dmRHVjRkRDQ4TDNOMlp6ND0ifQ==
```

{% endcode %}

> The `tokenURI` is composed of a Base64-encoded JSON object that contains all the metadata associated with the token.

***

2. **Base64 Decoded to JSON**

{% code overflow="wrap" %}

```json
{"name":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bj48dHNwYW4geD0iMTAiIGR5PSIxLjJlbSIgZm9udC1mYW1pbHk9IidBcmlhbCcsIHNhbnMtc2VyaWYiIGZvbnQtc2l6ZT0iMTBweCI+UHVyY2hhc2UgUHJpY2U6ICQ5ODcuMjA8L3RzcGFuPjwvdGV4dD48L3N2Zz4="}
```

{% endcode %}

> When the Base64-encoded JSON object is decoded, it reveals a JSON structure in which the `"image"` field contains another Base64-encoded string — representing an embedded SVG image.

***

3. **JSON Base64 Decoded to XML**

{% code overflow="wrap" %}

```svg
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300"><metadata>Built on Xyxyx<desc>
{
  "token_id": "TBILL-912796WQ4",
  "issuer": "J.T.",
  "instrument_type": "Treasury Bill",
  "term": "13 weeks",
  "cusip": "912796WQ4",
  "issue_date": "2025-05-01",
  "maturity_date": "2025-07-31",
  "discount_rate": "5.12%",
  "face_value_usd": 1000,
  "purchase_price_usd": 987.20,
  "timestamp": "2025-05-11T15:42:00Z"
}
</desc></metadata><rect width="100%" height="300px" fill="#ffffff" borderRadius="10px" rx="10" ry="10"></rect><text x="10" y="20" font-size="10px" fill="#000000"><tspan x="10" dy="0" font-family="'Arial', sans-serif" font-size="10px">TREASURY BILL RECORD</tspan><tspan x="10" dy="1.2em" font-family="'Arial', sans-serif" font-size="10px">----------------------------------------  </tspan><tspan x="10" dy="1.2em" font-family="'Arial', sans-serif" font-size="10px">Issuer: J.T.</tspan><tspan x="10" dy="1.2em" font-family="'Arial', sans-serif" font-size="10px">Instrument: 13-Week T-Bill  </tspan><tspan x="10" dy="1.2em" font-family="'Arial', sans-serif" font-size="10px">CUSIP: 912796WQ4  </tspan><tspan x="10" dy="1.2em" font-family="'Arial', sans-serif" font-size="10px">Issue Date: 2025-05-01  </tspan><tspan x="10" dy="1.2em" font-family="'Arial', sans-serif" font-size="10px">Maturity Date: 2025-07-31  </tspan><tspan x="10" dy="1.2em" font-family="'Arial', sans-serif" font-size="10px">Discount Rate: 5.12%  </tspan><tspan x="10" dy="1.2em" font-family="'Arial', sans-serif" font-size="10px">Face Value: $1,000  </tspan><tspan x="10" dy="1.2em" font-family="'Arial', sans-serif" font-size="10px">Purchase Price: $987.20</tspan></text></svg>
```

{% endcode %}

> Decoding the Base64 string found in the `"image"` field of the JSON metadata produces the XML markup that renders the SVG graphic associated with the token.

***

4. **SVG Output**

<figure><img src="/files/OOk4EF1R0WisgWzCFS3r" alt=""><figcaption></figcaption></figure>

> The XML code, once decoded, generates the final SVG output — a visual representation embedded in the token metadata.

***

### Fundamentals

#### Immutability

All metadata, visuals, and descriptive content related to TBTs are embedded in Ethereum’s state at the time of contract deployment or token minting. This guarantees the permanence and non-repudiation of each token’s identity and attributes.

***

#### Reliability

By eliminating external storage endpoints, XTBTA avoids common points of failure such as broken links, misconfigured servers, or expired hosting plans. The on-chain-only model substantially reduces operational risk.

***

#### Transparency

TBTs are fully observable on-chain. Developers and end users can inspect all token attributes, metadata, and rendering logic directly via smart contract interfaces — enabling frictionless auditing and trustless attesting.

***

#### Censorship Resistance

TBTs access and visibility cannot be obstructed by third-party services or centralized infrastructure providers.

***

#### Data Longevity

As long as the Ethereum network persists, all TBTs data remains accessible and verifiable, ensuring digital persistence without reliance on third-party hosting or re-indexing services.

***

#### **Auditability**

All state changes, token interactions, and logic executions are recorded immutably on-chain. This enables verifiable and reproducible audits by any third party without requiring privileged access.

***

#### **Attestability**

Users and systems can cryptographically attest to the authenticity and provenance of TBTs based solely on their on-chain presence. This trustless verification model removes reliance on off-chain registries or authorities.

***

#### **Composability**

TBTs are designed to be both immutable blockchain records and highly composable data files. Their SVG-based structure allows them to be easily accessed and integrated into other applications or systems, facilitating seamless interoperability and reuse in various contexts.

***

### **On-Chain Data Storage**

Through XTBTA, 100% of each token’s data is stored fully on-chain, ensuring immutability, transparency, and complete independence from external, off-chain data storage systems such as IPFS.

Below we provide a comparison table between on-chain vs. off-chain data storage:

| Criteria                  | On-Chain Data Storage                                   | Off-Chain Data Storage                                                                      |
| ------------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| **Immutability**          | Fully immutable once minted; embedded in Ethereum state | Content is immutable (via content hash), but links can be changed by referencing new hashes |
| **Availability**          | Guaranteed as long as the Ethereum network exists       | Requires external pinning to ensure persistent availability                                 |
| **Censorship Resistance** | Cannot be removed or blocked                            | Resistant to censorship, but depends on gateway access or node hosting                      |
| **Reliability**           | No external dependencies or servers needed              | Relies on external nodes and pinning services                                               |
| **Transparency**          | 100% transparent and queryable via smart contracts      | Metadata is viewable if hash is known, but less transparent in contract context             |
| **Performance**           | Fast read access on-chain; no external lookups          | Requires external fetch, which may introduce latency                                        |
| **Auditability**          | Fully auditable and verifiable on-chain                 | Auditable if hash is on-chain, but file contents need off-chain verification                |
| **Data Longevity**        | Data lives as long as Ethereum does                     | Data longevity depends on pinning and external upkeep                                       |
