npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cardity

v1.0.1

Published

Cardity - A modern programming language for blockchain protocol development on Dogecoin

Readme

Cardity Core

Cardity 编程语言的核心实现,包含编译器、运行时、包管理系统和开发工具。

📋 项目描述

Cardity Core 是 Cardity 编程语言的完整实现,提供:

  • 编译器 - 将编程语言格式的 .car 文件编译为可执行格式
  • 运行时 - 执行编译后的协议
  • 包管理器 - 管理依赖和发布包
  • CLI 工具 - 命令行开发工具
  • 类型系统 - 静态类型检查
  • 事件系统 - 事件驱动架构
  • ABI 生成器 - 自动生成协议接口(支持编程语言格式和 JSON 格式)
  • 区块链部署 - 支持 Dogecoin 链上部署
  • DRC-20 代币标准 - 完整的 DRC-20 代币支持

🚀 快速开始

安装

通过 npm 安装(推荐)

# 全局安装 Cardity
npm install -g cardity

# 验证安装
cardity --version

# 查看帮助
cardity --help

从源码编译安装

# 克隆项目
git clone https://github.com/cardity-org/cardity-core.git
cd cardity-core

# 安装依赖
npm install

# 验证安装
cardity --version

创建第一个项目

# 初始化新项目
cardity init my-first-protocol

# 进入项目目录
cd my-first-protocol

# 编译协议
cardity compile src/index.car

# 生成 ABI
cardity abi src/index.car

# 运行协议
cardity run dist/index.carc

🔧 开发工具

CLI 命令

# 项目初始化
cardity init [project-name]

# 编译协议
cardity compile <file> [options]

# 运行协议
cardity run <file> [options]

# 生成 ABI
cardity abi <file> [options]

# 部署到 Dogecoin
cardity deploy <file> [options]

# 查看帮助
cardity help

DRC-20 代币操作

# 编译 DRC-20 代币
cardity drc20 compile <file>

# 部署 DRC-20 代币
cardity drc20 deploy <file> [options]

# 铸造代币
cardity drc20 mint <tick> <amount> [options]

# 转账代币
cardity drc20 transfer <tick> <to> <amount> [options]

编译器工具

# 编译编程语言格式的 .car 文件为 .carc 二进制格式
cardityc main.car --format carc

# 编译为 JSON 格式
cardityc main.car --format json

# 生成部署包
cardityc main.car -o deployed.carc

# 生成 ABI (支持编程语言格式和 JSON 格式)
cardity_abi main.car                    # 输出到标准输出
cardity_abi main.car main.abi          # 输出到文件

# 运行协议
cardity_runtime main.car set_message "Hello"

部署工具

# 验证 .carc 文件
cardity_deploy validate protocol.carc

# 查看协议信息
cardity_deploy info protocol.carc

# 部署到 Dogecoin 链
cardity_deploy deploy protocol.carc --address doge1... --private-key ...

# 创建铭文交易
cardity_deploy inscription protocol.carc --address doge1... --output inscription.txt

📝 语言特性

编程语言格式 (.car 文件)

Cardity 支持编程语言格式的 .car 文件,类似 Solidity 的语法:

protocol HelloCardinals {
  version: "1.0.0";
  owner: "doge1abc123def456";
  
  state {
    message: string = "Hello, Cardity!";
    count: int = 0;
  }
  
  event MessageUpdated {
    new_message: string;
  }
  
  method get_message() {
    return state.message;
  }
  
  method set_message(new_message) {
    state.message = new_message;
    emit MessageUpdated(new_message);
  }
  
  method increment() {
    state.count = state.count + 1;
  }
  
  method get_count() {
    return state.count;
  }
}

DRC-20 代币格式

Cardity 支持完整的 DRC-20 代币标准:

protocol MyDrc20Token {
  version: "1.0.0";
  owner: "doge1token123";
  
  // DRC-20 代币定义
  drc20 {
    tick: "MYT";
    name: "My Token";
    max_supply: "1000000";
    mint_limit: "1000";
    decimals: "18";
    deployer: "doge1token123";
  }
  
  // 状态变量
  state {
    total_supply: int = 0;
    deployed: bool = false;
  }
  
  // 部署方法
  method deploy() {
    if (!state.deployed) {
      state.deployed = true;
      emit TokenDeployed(drc20.tick, drc20.max_supply);
      return "Token deployed successfully";
    }
    return "Token already deployed";
  }
  
  // 铸造方法
  method mint(amount) {
    if (!state.deployed) {
      return "Token not deployed";
    }
    if (amount <= 0) {
      return "Invalid amount";
    }
    if (state.total_supply + amount > drc20.max_supply) {
      return "Exceeds max supply";
    }
    state.total_supply = state.total_supply + amount;
    emit TokenMinted(drc20.tick, amount, state.total_supply);
    return "Minted successfully";
  }
  
  // 转账方法
  method transfer(to_address, amount) {
    if (!state.deployed) {
      return "Token not deployed";
    }
    if (amount <= 0) {
      return "Invalid amount";
    }
    emit TokenTransferred(drc20.tick, amount, to_address);
    return "Transfer successful";
  }
  
  // 事件定义
  event TokenDeployed {
    tick: string;
    max_supply: string;
  }
  
  event TokenMinted {
    tick: string;
    amount: int;
    total_supply: int;
  }
  
  event TokenTransferred {
    tick: string;
    amount: int;
    to_address: string;
  }
}

语言特性

  • 协议定义: protocol 关键字定义协议
  • 状态变量: state 块中定义状态变量
  • 事件系统: event 关键字定义事件
  • 方法定义: method 关键字定义方法
  • 类型系统: 支持 string, int, bool 等基本类型
  • 事件发射: emit 关键字发射事件
  • DRC-20 支持: drc20 块定义代币标准
  • 代币操作: 内置 Deploy、Mint、Transfer 方法
  • ABI 生成: 自动从编程语言格式生成标准 ABI

类型系统

  • 基本类型: string, int, bool, number
  • 状态访问: state.variable_name
  • 事件发射: emit EventName(params)
  • 方法调用: 支持参数传递和返回值

ABI 生成

Cardity 的 ABI 生成器支持两种格式:

  1. 编程语言格式 - 直接解析类似 Solidity 的语法
  2. JSON 格式 - 解析标准 JSON 协议定义

生成的 ABI 包含:

  • 协议信息: 协议名和版本
  • 方法定义: 所有方法的名称和参数
  • 事件定义: 所有事件的名称和参数类型

🏗️ 区块链部署

.carc 二进制格式

Cardity Core 支持将协议编译为 .carc 二进制格式,用于 Dogecoin 链上部署:

# 编译为二进制格式
cardityc protocol.car --format carc

# 验证二进制文件
cardity_deploy validate protocol.carc

# 部署到 Dogecoin 链
cardity_deploy deploy protocol.carc --address doge1... --private-key ...

部署方式

  1. OP_RETURN 部署 - 将协议数据存储在 OP_RETURN 输出中
  2. 铭文部署 - 使用 ordinals 协议创建铭文

🔍 示例项目

基础示例

查看 examples/ 目录获取完整示例:

  • hello.car - 简单的 Hello World 协议
  • counter.car - 计数器协议
  • wallet.car - 钱包协议
  • event_demo.car - 事件系统演示
  • drc20_token.car - DRC-20 代币示例

运行示例

# 编译编程语言格式文件
cardityc examples/hello.car -o hello_deployed.carc

# 验证二进制文件
cardity_deploy validate hello_deployed.carc

# 查看协议信息
cardity_deploy info hello_deployed.carc

# 部署到 Dogecoin 链
cardity_deploy deploy hello_deployed.carc --address doge1... --private-key ...

DRC-20 代币工作流程

# 1. 创建 DRC-20 代币定义
cardity_drc20 template basic --tick MYT --name "My Token" --output my_token.car

# 2. 编译和验证代币
cardity_drc20 compile my_token.car
cardity_drc20 validate my_token.car

# 3. 生成 ABI
cardity_abi my_token.car my_token.abi

# 4. 生成部署铭文
cardity_drc20 deploy my_token.car --output deploy.json

# 5. 部署到 Dogecoin 链
cardity_deploy deploy deploy.json --address doge1... --private-key ...

# 6. 生成铸造铭文
cardity_drc20 mint MYT 1000 --output mint.json

# 7. 生成转账铭文
cardity_drc20 transfer MYT 100 doge1abc... --output transfer.json

🛠️ 开发指南

编译源码

# 安装依赖
brew install cmake nlohmann-json curl libarchive openssl

# 编译项目
mkdir build && cd build
cmake ..
make -j4

# 安装到系统
sudo make install

创建新项目

# 初始化新项目
cardity init

# 这会创建:
# - cardity.json (项目配置)
# - src/index.car (编程语言格式的协议文件)
# - README.md (项目文档)

调试

# 启用调试模式
cmake -DCMAKE_BUILD_TYPE=Debug ..
make

# 运行调试版本
./cardity_cli --debug init

# 测试编译器
./cardityc --validate src/main.car

📚 文档

🤝 贡献

欢迎贡献代码!

  1. Fork 项目
  2. 创建功能分支 (git checkout -b feature/amazing-feature)
  3. 提交更改 (git commit -m 'Add amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 打开 Pull Request

开发环境

  • C++17 - 主要开发语言
  • CMake - 构建系统
  • nlohmann/json - JSON 处理
  • libcurl - 网络请求
  • libarchive - 压缩文件处理
  • OpenSSL - 加密和哈希

📄 许可证

MIT License - 详见 LICENSE 文件

🔗 相关链接


Cardity Core - Cardity 编程语言的核心实现 🚀

最新更新: 支持 npm 包安装、完整的区块链协议开发工作流程,包括 .carc 二进制格式、Dogecoin 链上部署、DRC-20 代币标准和智能 ABI 生成器!