solc

package module
Version: v0.0.0-...-8792f0b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2020 License: MIT Imports: 6 Imported by: 0

README

Solc-Go

Golang bindings for the Solidity compiler.

Uses the Emscripten compiled Solidity found in the solc-bin repository.

Example usage

Example:

package main

import (
    "github.com/nmvalera/solc-go"
)

func main() {
    compiler := Solc6_2_0()

    input := &solc.Input{
		Language: "Solidity",
		Sources:  map[string]solc.SourceIn{
            "One.sol": SourceIn{Content: "pragma solidity ^0.6.2; contract One { function one() public pure returns (uint) { return 1; } }"},
        },
		Settings: solc.Settings{
			Optimizer: solc.Optimizer{
				Enabled: true,
				Runs:    200,
			},
			EVMVersion: "byzantium",
			OutputSelection: map[string]map[string][]string{
				"*": map[string][]string{
					"*": []string{
						"abi",
						"evm.bytecode.object",
						"evm.bytecode.sourceMap",
						"evm.deployedBytecode.object",
						"evm.deployedBytecode.sourceMap",
						"evm.methodIdentifiers",
					},
					"": []string{
						"ast",
					},
				},
			},
		},
    }
    
    output, _ := compiler.Compile(input)

    fmt.Printf("Bytecode: %v", output.Contracts["One.sol"]["One"].EVM.Bytecode.Object)
}

Documentation

Index

Constants

View Source
const SOLC_BIN_DIR = "./solc-bin"

Variables

This section is empty.

Functions

This section is empty.

Types

type Bytecode

type Bytecode struct {
	Object         string                                `json:"object,omitempty"`
	Opcodes        string                                `json:"opcodes,omitempty"`
	SourceMap      string                                `json:"sourceMap,omitempty"`
	LinkReferences map[string]map[string][]LinkReference `json:"linkReferences,omitempty"`
}

type Contract

type Contract struct {
	ABI      []json.RawMessage `json:"abi,omitempty"`
	Metadata string            `json:"metadata,omitempty"`
	UserDoc  json.RawMessage   `json:"userdoc,omitempty"`
	DevDoc   json.RawMessage   `json:"devdoc,omitempty"`
	IR       string            `json:"ir,omitempty"`
	// StorageLayout StorageLayout     `json:"storageLayout,omitempty"`
	EVM   EVM   `json:"evm,omitempty"`
	EWASM EWASM `json:"ewasm,omitempty"`
}

type EVM

type EVM struct {
	Assembly          string                       `json:"assembly,omitempty"`
	LegacyAssembly    json.RawMessage              `json:"legacyAssembly,omitempty"`
	Bytecode          Bytecode                     `json:"bytecode,omitempty"`
	DeployedBytecode  Bytecode                     `json:"deployedBytecode,omitempty"`
	MethodIdentifiers map[string]string            `json:"methodIdentifiers,omitempty"`
	GasEstimates      map[string]map[string]string `json:"gasEstimates,omitempty"`
}

type EWASM

type EWASM struct {
	Wast string `json:"wast,omitempty"`
	Wasm string `json:"wasm,omitempty"`
}

type Error

type Error struct {
	SourceLocation   SourceLocation `json:"sourceLocation,omitempty"`
	Type             string         `json:"type,omitempty"`
	Component        string         `json:"component,omitempty"`
	Severity         string         `json:"severity,omitempty"`
	Message          string         `json:"message,omitempty"`
	FormattedMessage string         `json:"formattedMessage,omitempty"`
}

type Input

type Input struct {
	Language string              `json:"language,omitempty"`
	Sources  map[string]SourceIn `json:"sources,omitempty"`
	Settings Settings            `json:"settings,omitempty"`
}

type LinkReference

type LinkReference struct {
	Start int `json:"start,omitempty"`
	End   int `json:"end,omitempty"`
}

type Optimizer

type Optimizer struct {
	Enabled bool `json:"enabled,omitempty"`
	Runs    int  `json:"runs,omitempty"`
}

type Output

type Output struct {
	Errors    []Error                        `json:"errors,omitempty"`
	Sources   map[string]SourceOut           `json:"sources,omitempty"`
	Contracts map[string]map[string]Contract `json:"contracts,omitempty"`
}

type Settings

type Settings struct {
	Remappings      []string                       `json:"remappings,omitempty"`
	Optimizer       Optimizer                      `json:"optimizer,omitempty"`
	EVMVersion      string                         `json:"evmVersion,omitempty"`
	OutputSelection map[string]map[string][]string `json:"outputSelection,omitempty"`
}

type Solc

type Solc interface {
	License() string
	Version() string
	Compile(input *Input) (*Output, error)
	Close()
}

func New

func New(soljsonjs string) (Solc, error)

New creates a new Solc binding using the underlying soljonjs emscripten binary

func NewFromFile

func NewFromFile(file string) (Solc, error)

func Solc5_9_0

func Solc5_9_0() Solc

func Solc6_2_0

func Solc6_2_0() Solc

type SourceIn

type SourceIn struct {
	Keccak256 string `json:"keccak256,omitempty"`
	Content   string `json:"content,omitempty"`
}

type SourceLocation

type SourceLocation struct {
	File  string `json:"file,omitempty"`
	Start int    `json:"start,omitempty"`
	End   int    `json:"end,omitempty"`
}

type SourceOut

type SourceOut struct {
	ID        int             `json:"id,omitempty"`
	AST       json.RawMessage `json:"ast,omitempty"`
	LegacyAST json.RawMessage `json:"legacyAST,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL