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.
๐ฏ Features
- Type-Safe Compilation: Leveraging Gleam's type system for safer Solidity compilation
- Multiple Inheritance Support: Full support for interfaces, abstract contracts, and implementation chains
- Comprehensive Error Handling: Detailed compilation error detection and reporting
- Modern Solidity: Support for Solidity 0.8+ with latest language features
- Promise-Based API: Async operations using JavaScript promises
- Version Management: Automatic downloading and caching of Solidity compiler versions
๐ 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
- API Documentation - Comprehensive API reference
- Usage Examples - Common patterns and use cases
- Type Definitions - Complete type system reference
๐๏ธ 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 testsTotal: 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 passingTest categories:
- Basic Tests (4) - Core functionality and type construction
- Integration Tests (18) - Real-world scenarios and complex contracts
- End-to-End Tests (8) - Complete compilation workflows
๐ ๏ธ 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:
- solc-js - Official JavaScript bindings
- Solidity Documentation - Compiler reference
Built by pxlvre.eth with โค๏ธ using Gleam and the Solidity compiler.