transpiler-solidity
raw JSON → 1.1.2 verified Fri May 01 auth: no javascript
A Node.js-based transpiler that adds GCC-like macro and helper functions to Solidity assembly code, enabling cleaner pointer arithmetic, struct attribute access, byte offsets, and data packing/unpacking directly in inline assembly blocks. Current stable version is 1.1.2. Development appears low-activity, with no recent releases after v1.1.0. It differentiates by providing C-style macros (#define TRANSPILE) that expand to optimized Solidity assembly, reducing manual storage slot calculations. Requires gcc and Node.js. Not widely adopted, and likely only useful for advanced Ethereum developers working with low-level storage optimizations.
Common errors
error Error: Cannot find module 'transpiler-solidity' ↓
cause Package not installed globally or locally.
fix
Run
npm install -g transpiler-solidity or npm install transpiler-solidity in your project. error gcc: command not found ↓
cause gcc is not installed or not in PATH.
fix
Install gcc (e.g.,
apt install gcc on Debian/Ubuntu, xcode-select --install on macOS). error SyntaxError: Unexpected token '#' ↓
cause The .sol file contains #define TRANSPILE but the transpiler hasn't been run; Solidity compiler doesn't accept #-preprocessor directives.
fix
Run
transpiler-solidity input.sol > output.sol and compile output.sol instead. Warnings
gotcha Missing #define TRANSPILE: If the source file does not contain #define TRANSPILE, the transpiler outputs the input unchanged without any macro expansion. ↓
fix Add #define TRANSPILE at the top of your .sol file before any contract definitions.
gotcha pragma solidity version must be 0.5.7 or compatible: The documentation and examples use version 0.5.7; newer Solidity versions may have incompatible assembly syntax. ↓
fix Use pragma solidity 0.5.7; or adjust the output to match your compiler version.
deprecated Package has low activity: Last release was v1.1.0 and there have been no recent updates. May not work with latest Node.js or Solidity versions. ↓
fix Consider whether this tool is still maintained; alternatives may involve hand-optimizing assembly or using other transpilers.
gotcha Requires gcc: The transpiler calls gcc for preprocessing; missing gcc will cause errors on certain macros. ↓
fix Install gcc (e.g., apt-get install gcc on Ubuntu, brew install gcc on macOS).
Install
npm install transpiler-solidity yarn add transpiler-solidity pnpm add transpiler-solidity Imports
- transpilerSolidity wrong
const transpiler = require('transpiler-solidity')correctimport transpilerSolidity from 'transpiler-solidity' - pointer wrong
import { pointer } from 'transpiler-solidity'correct// Used in .sol files with #define TRANSPILE, not a JS import - #define TRANSPILE wrong
// forgetting to add #define TRANSPILE causes no expansioncorrectPlace #define TRANSPILE at top of .sol file to enable macro processing
Quickstart
npm install -g transpiler-solidity
# Create a Solidity file with GCC-style macros
echo 'pragma solidity 0.5.7;
#define TRANSPILE
contract Ex {
struct Item { uint64 a; uint64 b; }
Item item;
function foo() public {
assembly {
let b_ptr := pointer_attr(Item, item_slot, b)
let b := sload(b_ptr)
sstore(b_ptr, add(b, 1))
}
}
}' > example.sol
transpiler-solidity example.sol > output.sol
# output.sol contains expanded assembly