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
to analyze Solidity source code, we translate it into TypeScript based on the Solidity AST
. Since o1js
extends TypeScript, the plan is to first generate a general TypeScript AST using SWC
, and then add specific o1js
syntax support, such as @method
, as needed. Inspired by charcoal.
- 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.
Ensure Rust and Cargo are installed:
cargo install --path .
Or clone the repository and build manually:
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.
// 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;
}
}
./target/release/transpiler \
--input ./samples/Square.sol \
--output ./target/Square.ts
import { Field, SmartContract, state, State, method } from 'o1js';
export class Square extends SmartContract {
@state(Field) num = State<Field>();
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);
}
}
This feature is under development. Stay tuned!
./target/release/compiler \
--input ./samples/Square.sol \
--output ./target/Square.bytecode
0xABEF0C10f...7F00DDE
- 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
Run tests using:
cargo test
This project is licensed under the Apache License 2.0.