Data
Parse and manipulate Cardano data types for smart contract development
MeshJS provides comprehensive utilities for working with Cardano data. Use these tools to construct datums, redeemers, and other on-chain data structures in multiple formats.
Overview
Cardano smart contracts require data in specific formats. MeshJS supports three data representation formats:
| Format | Best For | Description |
|---|---|---|
| Mesh Data | Quick prototyping | Simple JavaScript primitives with minimal wrappers |
| JSON Data | Web3 applications | Strong type validation for frontend-backend communication |
| CBOR | Interoperability | Raw binary format for cross-library compatibility |
Quick Start
Install the MeshJS SDK:
npm install @meshsdk/coreChoose your preferred data format:
// Mesh Data format - simple and quick
import { mConStr0, mConStr1 } from "@meshsdk/core";
const datum = mConStr0(["owner-key-hash", 1000000n]);
// JSON Data format - validated types
import { conStr0, byteString, integer } from "@meshsdk/core";
const datum = conStr0([byteString("owner-key-hash"), integer(1000000)]);Browse Data APIs
Data Overview
Learn about the basics, and how Mesh handles Cardano data
Mesh Data
Parse and manipulate data with Mesh Data type
JSON Data
Parse and manipulate data with JSON
Value
Manipulate Value Easily
When to Use Each Format
Use Mesh Data When
- You need to quickly prototype smart contract interactions
- You want minimal boilerplate code
- You are comfortable with JavaScript primitives
Use JSON Data When
- You need strong input validation
- You are building production web applications
- You want type safety for complex data structures
Use CBOR When
- You are integrating with other serialization libraries
- You need the raw binary representation
- You are working with data from external sources
Related
- Utilities - Serialize and deserialize data
- Transaction Builder - Use data in transactions
- Smart Contracts - Apply data to contract interactions