
Company News
Andrew Becherer Joins Socket as Chief Information Security Officer
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.
JavaScript bindings for the Purity compiler.
Purity is a fork of Solidity with 32-byte native addressing and other modifications targeting next-generation EVM-compatible virtual machines.
purc-js is derived from solc-js and provides the same API surface, with naming and defaults updated for Purity.
npm install purc
If this package is installed globally (npm install -g purc), a command-line tool called purcjs will be available.
purcjs --help
To compile a contract that imports other contracts via relative paths:
purcjs --bin --include-path node_modules/ --base-path . MainContract.sol
Use --base-path to specify the root of your source tree and --include-path for external code directories (e.g. libraries installed with a package manager).
There are two ways to use purc:
The high-level API consists of a single method, compile, which expects the Compiler Standard Input and Output JSON.
It also accepts an optional set of callback functions, including import and smtSolver callbacks.
var purc = require('purc');
var input = {
language: 'Purity',
sources: {
'test.sol': {
content: 'pragma purity >=0.1.0; contract C { function f() public pure returns (uint) { return 42; } }'
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
};
var output = JSON.parse(purc.compile(JSON.stringify(input)));
for (var contractName in output.contracts['test.sol']) {
console.log(
contractName +
': ' +
output.contracts['test.sol'][contractName].evm.bytecode.object
);
}
Note:
"Solidity"is also accepted as thelanguagevalue for backward compatibility.
var purc = require('purc');
var input = {
language: 'Purity',
sources: {
'test.sol': {
content: 'import "lib.sol"; contract C { function f() public { L.f(); } }'
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
};
function findImports(path) {
if (path === 'lib.sol')
return {
contents:
'library L { function f() internal returns (uint) { return 7; } }'
};
else return { error: 'File not found' };
}
var output = JSON.parse(
purc.compile(JSON.stringify(input), { import: findImports })
);
for (var contractName in output.contracts['test.sol']) {
console.log(
contractName +
': ' +
output.contracts['test.sol'][contractName].evm.bytecode.object
);
}
The low-level API is available for compatibility with older compiler binaries:
purc.lowlevel.compileSinglepurc.lowlevel.compileMultipurc.lowlevel.compileCallbackpurc.lowlevel.compileStandardNote: These low-level functions remain for compatibility reasons but have been superseded by compile().
You can load the compiler binary manually and use setupMethods to create the wrapper:
var purc = require('purc');
var compiler = purc.setupMethods(require('/path/to/purjson.js'));
The linker module (require('purc/linker')) offers helpers for linking library addresses into bytecode:
var linker = require('purc/linker');
bytecode = linker.linkBytecode(bytecode, { 'lib.sol:MyLibrary': '0x1234...' });
You can also find link references in unlinked bytecode:
var linkReferences = linker.findLinkReferences(bytecode);
The abi module (require('purc/abi')) can translate ABI output from older compiler versions to the latest standard:
var abi = require('purc/abi');
var outputABI = abi.update('0.3.6', inputABI);
var translate = require('purc/translate');
var output = translate.prettyPrintLegacyAssemblyJSON(assemblyJSON, sourceCode);
language in Standard JSON is "Purity" (though "Solidity" is accepted for backward compatibility)purc instead of solcpurcjs instead of solcjs0.1.0require('solc') with require('purc')language: 'Solidity' to language: 'Purity' in Standard JSON inputs (optional — both are accepted)solcjs CLI commands with purcjspragma solidity to pragma purity in .sol source files (optional — both are accepted)The only supported way to use purc in a web browser is through a web worker:
import wrapper from 'purc/wrapper';
self.addEventListener('message', () => {
const compiler = wrapper(self.Module);
self.postMessage({
version: compiler.version()
});
}, false);
MIT — see LICENSE.
This project is derived from solc-js, originally created by the Ethereum community.
FAQs
Purity compiler JavaScript bindings
We found that @qevm/purc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.

Company News
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.

Security News
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.