Target Specific


The Solana target requires Solana v1.8.1.

Solana has the following differences to Ethereum Solidity:

  • The address type is 32 bytes, not 20 bytes. This is what Solana calls an “account”
  • An address literal has to be specified using the address"36VtvSbE6jVGGQytYWSaDPG7uZphaxEjpJHUUpuUbq4D" syntax
  • There is no ecrecover() builtin function, but there is a signatureVerify() function which can check ed25519 signatures.
  • Solana has no concept of gas, so there is no gas functions
  • Solana balance is stored in a uint64, so msg.value, address .balance, .transfer() and .send() all use uint64 rather than uint256.

This is how to build your Solidity for Solana:

solang --target solana flipper.sol -v

This will produce two files called flipper.abi and The first is an ethereum style abi file and the latter being the ELF BPF shared object which can be deployed on Solana. For each contract, an abi file will be created; a single is created which contains the code all the contracts provided on the command line.

npm install @solana/solidity

Now run the following javascript by saving it to flipper.js and running it with node flipper.js.

const { Connection, LAMPORTS_PER_SOL, Keypair } = require('@solana/web3.js');
const { Contract, Program } = require('@solana/solidity');
const { readFileSync } = require('fs');

const FLIPPER_ABI = JSON.parse(readFileSync('./flipper.abi', 'utf8'));
const PROGRAM_SO = readFileSync('./');

(async function () {
    console.log('Connecting to your local Solana node ...');
    const connection = new Connection('http://localhost:8899', 'confirmed');

    const payer = Keypair.generate();

    console.log('Airdropping SOL to a new wallet ...');
    const signature = await connection.requestAirdrop(payer.publicKey, LAMPORTS_PER_SOL);
    await connection.confirmTransaction(signature, 'confirmed');

    const program = Keypair.generate();
    const storage = Keypair.generate();

    const contract = new Contract(connection, program.publicKey, storage.publicKey, FLIPPER_ABI, payer);

    await contract.load(program, PROGRAM_SO);

    console.log('Program deployment finished, deploying the flipper contract ...');

    await contract.deploy('flipper', [true], program, storage, 17);

    const res = await contract.functions.get();
    console.log('state: ' + res.result);

    await contract.functions.flip();

    const res2 = await contract.functions.get();
    console.log('state: ' + res2.result);

The contract can be used via the @solana/solidity npm package. This package has documentation and there are some examples. There is also solang’s integration tests.

Parity Substrate

Solang works with Parity Substrate 2.0 or later.

The Parity Substrate has the following differences to Ethereum Solidity:

  • The address type is 32 bytes, not 20 bytes. This is what Substrate calls an “account”
  • An address literal has to be specified using the address"5GBWmgdFAMqm8ZgAHGobqDqX6tjLxJhv53ygjNtaaAn3sjeZ" syntax
  • ABI encoding and decoding is done using the SCALE encoding
  • Multiple constructors are allowed, and can be overloaded
  • There is no ecrecover() builtin function, or any other function to recover or verify cryptographic signatures at runtime
  • Only functions called via rpc may return values; when calling a function in a transaction, the return values cannot be accessed
  • An assert(), require(), or revert() executes the wasm unreachable instruction. The reason code is lost

There is an solidity example which can be found in the examples directory. Write this to flipper.sol and run:

solang --target substrate flipper.sol

Now you should have a file called flipper.contract. The file contains both the ABI and contract wasm. It can be used directly in the Polkadot UI, as if the contract was written in ink!.

Hyperledger Burrow (ewasm)

The ewasm specification is not finalized yet. There is no create2 or chainid call, and the keccak256 precompile contract has not been finalized yet.

In Burrow, Solang is used transparently by the burrow deploy tool if it is given the --wasm argument. When building and deploying a Solidity contract, rather than running the solc compiler, it will run the solang compiler and deploy it as a wasm contract.

This is documented in the burrow documentation.

ewasm has been tested with Hyperledger Burrow. Please use the latest master version of burrow, as ewasm support is still maturing in Burrow.

Some language features have not been fully implemented yet on ewasm:

  • Contract storage variables types string, bytes and function types are not implemented