Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ cadence-codegen typescript ./contracts output.ts
cadence-codegen typescript analysis.json output.ts
```

### Generate Go Code

Generate Go code from Cadence files or JSON:

```bash
# Generate from Cadence files (outputs to cadence_generated.go)
cadence-codegen golang ./contracts

# Using the "go" alias
cadence-codegen go ./contracts

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

# Generate from previously analyzed JSON
cadence-codegen golang analysis.json output.go
```

## Features

- Analyzes Cadence files (.cdc)
Expand All @@ -92,6 +110,7 @@ cadence-codegen typescript analysis.json output.ts
- Structured JSON output
- Swift code with type-safe wrappers
- TypeScript code with FCL integration
- Go code with typed structs and helper functions
- Supports folder-based tagging for better organization
- Base64 encoding of Cadence files (optional)

Expand Down Expand Up @@ -194,6 +213,45 @@ const result = await service.getAddr(flowAddress);
const txId = await service.createCoa(amount);
```

## Generated Go Code

The generated Go code includes:

- Typed Go structs from Cadence composite types (with JSON tags)
- Base64-encoded Cadence code constants with decoder functions
- Parameter structs for typed access to transaction/script arguments
- Cadence-to-Go type mapping (`Int`/`UInt` families to native Go types, `Int128`/`Int256`/`UInt128`/`UInt256` to `*big.Int`, `UFix64`/`Fix64`/`Address` to `string`)
- Support for arrays, dictionaries, optionals, and nested types
- Tag-based grouping via comment sections

Example usage of generated Go code:

```go
package main

import (
"fmt"
cadence "path/to/cadence_generated"
)

func main() {
// Get the Cadence code for a transaction
code := cadence.TransferTokensCode()
fmt.Println(code)

// Use typed parameter struct
params := cadence.TransferTokensParams{
Amount: "10.0",
To: "0x1234567890abcdef",
}
fmt.Printf("Transfer %s to %s\n", params.Amount, params.To)

// Get the Cadence code for a script
scriptCode := cadence.GetBalanceCode()
fmt.Println(scriptCode)
}
```

## 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.
Expand Down