# Solidity Compiler & Transpiler for Mina This project aims to provide an efficient tool that can transpile smart contracts written in Solidity into Mina's contract language or directly compile them into Mina Virtual Machine bytecode/circuits, helping developers quickly deploy and verify smart contracts on the Mina blockchain. Using [`solang-parser`](https://github.com/hyperledger-solang/solang/tree/main/solang-parser) to analyze Solidity source code, we translate it into TypeScript based on the Solidity `AST`. Since [`o1js`](https://github.com/o1-labs/o1js) extends TypeScript, the plan is to first generate a general TypeScript AST using [`SWC`](https://github.com/swc-project/swc), and then add specific `o1js` syntax support, such as `@method`, as needed. Inspired by [charcoal](https://github.com/ourovoros-io/charcoal). ## Features - Converts Solidity code into Mina-compatible TypeScript smart contracts while preserving core logic. - Generates low-level bytecode or circuits executable by the Mina Virtual Machine (In Development). - High-performance command-line tool built with Rust, supporting custom input/output paths and target platforms. ## Installation ### Install via Cargo Ensure [Rust](https://www.rust-lang.org/tools/install) and Cargo are installed: ```bash cargo install --path . ``` Or clone the repository and build manually: ```bash git clone https://github.com/hummanta/sol-to-o1js.git cd sol-to-o1js cargo build --release ``` The executable will be located in the `target/release/` directory. ## Usage ### 1️⃣ Transpile Solidity Smart Contract to Mina Contract Language #### Example Solidity Contract `Square.sol` ```solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract Square { uint256 public num; constructor() { num = 3; } function update(uint256 square) public { require(square == num * num, "Square does not match current state squared"); num = square; } } ``` #### Transpilation Command ```bash ./target/release/transpiler \ --input ./samples/Square.sol \ --output ./target/Square.ts ``` #### Transpiled Mina Contract `Square.ts` ```typescript import { Field, SmartContract, state, State, method } from 'o1js'; export class Square extends SmartContract { @state(Field) num = State(); init() { super.init(); this.num.set(Field(3)); } @method async update(square: Field) { const currentState = this.num.get(); this.num.requireEquals(currentState); square.assertEquals(currentState.mul(currentState)); this.num.set(square); } } ``` ------ ### 2️⃣ TODO: Compile Solidity to Mina VM Bytecode / Circuits This feature is under development. Stay tuned! #### Expected Command ```bash ./target/release/compiler \ --input ./samples/Square.sol \ --output ./target/Square.bytecode ``` #### Expected Output ``` 0xABEF0C10f...7F00DDE ``` ------ ## Roadmap - [x] Solidity to Mina contract language transpilation - [ ] Solidity to Mina VM bytecode/circuit compilation - [ ] Support for more complex data structures and functions - [ ] Integration with automated testing tools ## Testing Run tests using: ```bash cargo test ``` ## License This project is licensed under the Apache License 2.0.