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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@outblock/cadence-codegen

v0.0.9

Published

A tool for analyzing Cadence smart contracts and generating code

Readme

Cadence Codegen

A tool for analyzing Cadence smart contracts and generating code. It extracts transaction and script information, including parameters, imports, and return types.

Installation

Using npm (Recommended)

# Global installation
npm install -g @outblock/cadence-codegen

# Or use in a project
npm install @outblock/cadence-codegen
npx cadence-codegen --help

Using Homebrew

brew tap outblock/tap
brew install cadence-codegen

Update Homebrew

brew update && brew upgrade cadence-codegen

Using Go

go install github.com/outblock/cadence-codegen@latest

Usage

Analyze Cadence Files

Analyze Cadence files and generate a JSON report:

# Analyze a directory of Cadence files
cadence-codegen analyze ./contracts

# Analyze with custom output path
cadence-codegen analyze ./contracts output.json

# Analyze without base64 encoding
cadence-codegen analyze ./contracts --base64=false

Generate Swift Code

Generate Swift code from Cadence files or JSON:

# Generate from Cadence files (outputs to CadenceGen.swift)
cadence-codegen swift ./contracts

# Generate from Cadence files with custom output path
cadence-codegen swift ./contracts output.swift

# Generate from previously analyzed JSON
cadence-codegen swift analysis.json output.swift

Generate TypeScript Code

Generate TypeScript code from Cadence files or JSON:

# Generate from Cadence files (outputs to cadence.generated.ts)
cadence-codegen typescript ./contracts

# Generate from Cadence files with custom output path
cadence-codegen typescript ./contracts output.ts

# Generate from previously analyzed JSON
cadence-codegen typescript analysis.json output.ts

Features

  • Analyzes Cadence files (.cdc)
  • Extracts:
    • Transaction parameters and types
    • Script parameters and return types
    • Import statements
    • Struct definitions
  • Generates:
    • Structured JSON output
    • Swift code with type-safe wrappers
    • TypeScript code with FCL integration
  • Supports folder-based tagging for better organization
  • Base64 encoding of Cadence files (optional)

JSON Output Format

{
  "transactions": {
    "filename.cdc": {
      "fileName": "filename.cdc",
      "type": "transaction",
      "parameters": [
        {
          "name": "amount",
          "typeStr": "UFix64",
          "optional": false
        }
      ],
      "imports": [
        {
          "contract": "FungibleToken",
          "address": "0xFungibleToken"
        }
      ],
      "tag": "TokenTransfer"
    }
  },
  "scripts": {
    // Similar structure for scripts
  },
  "structs": {
    // Struct definitions
  }
}

Generated Swift Code

The generated Swift code includes:

  • Type-safe enums for transactions and scripts
    • Separate enums for each folder (e.g., CadenceGen.EVM for files in the EVM folder)
    • Main CadenceGen enum for files in the root directory
  • Struct definitions with proper Swift types
  • Automatic Flow SDK integration
  • Support for async/await
  • Error handling

Example usage of generated Swift code:

// Execute a script from the EVM folder
let result: String? = try await flow.query(CadenceGen.EVM.getAddr(flowAddress: address))

// Execute a script from the root directory
let result: String? = try await flow.query(CadenceGen.getAddr(flowAddress: address))

// Send a transaction
let txId = try await flow.sendTx(
    CadenceGen.EVM.createCoa(amount: amount),
    singers: [signer]
) {
    // Transaction build options
}

Generated TypeScript Code

The generated TypeScript code includes:

  • Type-safe functions for transactions and scripts
  • FCL (Flow Client Library) integration
  • Support for request and response interceptors
  • Automatic type conversion from Cadence to TypeScript
  • Support for async/await
  • Struct definitions with proper TypeScript interfaces

Example usage of generated TypeScript code:

import { CadenceService } from "./cadence.generated";

const service = new CadenceService();

// Add interceptors for request/response processing
service.useRequestInterceptor((config) => {
  console.log("Request config:", config);
  return config;
});

service.useResponseInterceptor((config, response) => {
  console.log("Response:", response);
  return { config, response };
});

// Execute a script
const result = await service.getAddr(flowAddress);

// Send a transaction
const txId = await service.createCoa(amount);

NPM Integration

When installed via npm, the tool automatically downloads the appropriate binary for your platform (macOS, Linux, Windows) during installation. This provides a seamless experience for JavaScript/TypeScript developers who want to integrate Cadence code generation into their build processes.

Use in package.json scripts

{
  "scripts": {
    "codegen": "cadence-codegen typescript ./cadence output.ts",
    "build": "npm run codegen && tsc"
  }
}

Use programmatically

const { execSync } = require('child_process');

// Generate TypeScript code
execSync('cadence-codegen typescript ./contracts generated.ts');

// Or analyze contracts
const analysis = execSync('cadence-codegen analyze ./contracts', { encoding: 'utf8' });
console.log(JSON.parse(analysis));

License

MIT License