Gleam Solc

A Gleam library for compiling Solidity contracts, providing type-safe bindings for the Solidity compiler solc with full support for modern Solidity features.

Tests Gleam JavaScript

🎯 Features

πŸš€ Quick Start

Add to your gleam.toml:

[dependencies]
solc = { git = "https://github.com/pxlvre/gleam_solc" }

Basic usage:

import gleam/option.{Some}
import solc

pub fn main() {
  // Load Solidity compiler
  use solc_wrapper <- promise.try_await(solc.load_solc("./solc-v0.8.19.js", Some("0.8.19")))
  
  // Compile a simple contract
  let source = "
pragma solidity ^0.8.0;
contract HelloWorld {
    string public message = \"Hello, World!\";
}
"
  
  case solc.compile_simple(solc_wrapper, "HelloWorld", source) {
    Ok(output) -> io.println("Compilation successful!")
    Error(err) -> io.println("Compilation failed")
  }
}

πŸ“– Documentation

πŸ—οΈ Architecture

src/
β”œβ”€β”€ solc.gleam              # Main API module (171 lines)
β”œβ”€β”€ solc/
β”‚   β”œβ”€β”€ types.gleam         # Core type definitions (175 lines)
β”‚   β”œβ”€β”€ download.gleam      # Version download functionality (99 lines)
β”‚   β”œβ”€β”€ wrapper.gleam       # WASM module wrapper (125 lines)
β”‚   └── ffi.gleam          # FFI bindings (28 lines)
β”œβ”€β”€ ffi/
β”‚   └── solc_ffi.mjs       # JavaScript FFI functions (130 lines)
└── test/
    β”œβ”€β”€ unit_test.gleam           # Basic functionality tests
    β”œβ”€β”€ integration_test.gleam     # Integration scenarios
    └── end_to_end_test.gleam     # Complete workflow tests

Total: 728 lines of production code with 30 comprehensive tests

πŸ§ͺ Testing

The library includes comprehensive test coverage:

# Run all tests
gleam test --target javascript

# Current status: 30 tests passing

Test categories:

πŸ› οΈ Development

# Setup
cd gleam_solc
gleam deps download

# Run tests
gleam test --target javascript

# Build for JavaScript
gleam build --target javascript

πŸ”— Inspiration

This project was inspired by:


Built by pxlvre.eth with ❀️ using Gleam and the Solidity compiler.

✨ Search Document