All Products
Search
Document Center

Blockchain as a Service:Solidity contract compiler

Last Updated:Mar 31, 2026

Ant Blockchain uses a customized Solidity compiler — solc-js — that is compatible with Solidity syntax prior to version 0.4.24 (excluding version 0.4.24). This page covers how to install and use solc-js, and when to switch to the solc binary compiler instead.

Important

Ant Blockchain does not support the standard Solidity compiler. Use only the BaaS-provided solc-js (alipay-solc-0.1.10.tgz). Contracts using Solidity 0.4.24 or later will not compile.

You can also compile, deploy, test, and debug contracts directly in Cloud IDE, the browser-based development environment for Ant Blockchain.

solc-js

solc-js is a cross-platform JavaScript compiler that you can use from the command line or within JavaScript code. It integrates with the JS SDK to automate contract deployment and invocation.

Limitation: solc-js supports the --bin flag but not --bin-runtime. If you need --bin-runtime output (required for contract updates), use the solc binary compiler instead.

Prerequisites

Before you begin, make sure you have:

Download and install solc-js

  1. Download the installation package: alipay-solc-0.1.10.tgz (~1.76 MB).

  2. Run the following command in the directory where you downloaded the package to install solc-js globally:

    npm i -g alipay-solc-0.1.10.tgz

After installation, solcjs is available in your terminal. Run solcjs --help to see all supported options.

CLI reference

Usage: /usr/local/bin/solcjs [options] <FILE_NAME>
OptionTypeDescription
--versionboolPrint the version number.
--binboolOutput the compiled bytecode (hex to binary). Use this for initial contract deployment.
--abiboolOutput the Application Binary Interface (ABI).
--optimizeboolEnable the bytecode optimizer.
--standard-jsonboolEnable standard JSON input/output mode.
--output-dir, -ostringWrite output files to the specified directory.
--helpboolPrint help information.
solc-js does not support --bin-runtime. To compile runtime bytecode for contract updates, use the solc binary compiler.

Compile a contract

The examples below use the following sample contract (hello.sol):

pragma solidity ^0.4.20;

contract Hello {

    string name;
    identity id; // identity is an Ant Blockchain type similar to address in standard Solidity

    constructor() public {
        name = 'Hello world!';
    }

    function hello() view public returns (identity, string) {
        return (msg.sender, name);
    }
}

Get the compiled bytecode

Run the following command to compile hello.sol and output the bytecode:

solcjs --bin hello.sol

On success, the output file hello_sol_Hello.bin appears in the current directory. If compilation fails, an error message is displayed.

Get the ABI

Run the following command to compile hello.sol and output the ABI:

solcjs --abi hello.sol

On success, the output file hello_sol_Hello.abi appears in the current directory.

Compile in JavaScript code

Use the following steps to compile a contract programmatically and get both the ABI and bytecode.

  1. Create a solcjs-test directory, run npm init inside it, and move alipay-solc-0.1.10.tgz into the directory.

  2. Install solc-js as a local dependency:

    npm i alipay-solc-0.1.10.tgz --save
  3. Create index.js with the following code. The second argument to solc.compile() activates the optimizer when set to 1.

    var solc = require('@alipay/solc')
    var input = 'contract test { function g(identity a) {} }'
    // Setting 1 as the second parameter activates the optimizer
    var output = solc.compile(input, 1)
    for (var contractName in output.contracts) {
        // Print the bytecode and ABI for each contract
        console.log(contractName + ': ' + output.contracts[contractName].bytecode)
        console.log(contractName + ': ' + output.contracts[contractName].interface)
    }
  4. Run the script:

    node index.js

    The output contains the compiled bytecode and ABI:

    :test: 6080604052348015600f57600080fd5b5060898061001e6000396000f300608060405260043610603e5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166338a1231d81146043575b600080fd5b348015604e57600080fd5b506058600435605a565b005b505600a165627a7a7230582008d3450904d4f09535ba76326aae5ecd2f61113b791d633dbb3c0799ff75b3ad0029
    :test: [{"constant":false,"inputs":[{"name":"a","type":"identity"}],"name":"g","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]

Deploy and call a contract with the JS SDK

After compiling, pass the ABI and bytecode directly to the JS SDK to deploy and invoke the contract. For details, see JS SDK Introduction.

solc binary compiler

Use solc when you need to update an existing contract. Unlike solc-js, solc supports --bin-runtime, which produces the runtime bytecode required by the SDK's contract update operation.

--bin vs --bin-runtime

FlagOutputUse for
--binFull deployment bytecode = runtime bytecode + constructor bytecodeInitial contract deployment
--bin-runtimeRuntime bytecode onlyUpdating an existing contract

For contract updates, compile with --bin-runtime:

solc --bin-runtime <your-contract.sol>

Pass the resulting bytecode to the JS SDK's update contract operation. For details, see JS SDK Introduction.

Download solc

Both versions are compatible with Solidity syntax prior to version 0.4.24 and support --bin-runtime.

VersionPlatformDownload
0.1.10macOSsolc-mac.zip
0.1.10CentOS 7.2solc-cenos7.2.zip

What's next

References