class Eth::Solidity

Class to create {Solidity} compiler bingings for Ruby.

def compile(contract)

Returns:
  • (Array) - JSON containing the compiled contract and ABI for all contracts.

Parameters:
  • contract (String) -- path of the contract to compile.
def compile(contract)
  raise Errno::ENOENT, "Contract file not found: #{contract}" unless File.exist? contract
  flag_opt = "--optimize"
  flag_json = "--combined-json=bin,abi"
  path = File.realpath contract
  output, error, status = Open3.capture3 @compiler, flag_opt, flag_json, path
  raise SystemCallError, "Unable to run solc compiler!" if status.exitstatus === 127
  raise CompilerError, error unless status.success?
  json = JSON.parse output
  result = {}
  json["contracts"].each do |key, value|
    _file, name = key.split ":"
    result[name] = {}
    result[name]["abi"] = value["abi"]
    result[name]["bin"] = value["bin"]
  end
  return result
end

def get_compiler_path(name = "solc")

Tries to find a system executable path for the given compiler binary name.
def get_compiler_path(name = "solc")
  extensions = [""]
  extensions = ENV["PATHEXT"].split(";") unless ENV["PATHEXT"].nil?
  ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
    extensions.each do |ext|
      executable = File.join path, "#{name}#{ext}"
      return executable if File.executable? executable and !File.directory? executable
    end
  end
  return nil
end

def initialize

used to compile Solidity contracts.
Instantiates a Solidity `solc` system compiler binding that can be
def initialize
  # Currently only supports `solc`.
  solc = get_compiler_path
  raise SystemCallError, "Unable to find the solc compiler path!" if solc.nil?
  @compiler = solc
end