solc

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: MIT Imports: 24 Imported by: 0

README

go-solc: Go Bindings for the Solidity Compiler

Go Reference Go Report Card

go-solc provides an easy way to compile Solidity contracts from Go.

go get github.com/lmittmann/go-solc

Getting Started

go-solc automatically downloads the specified version of the Solidity compiler from https://binaries.soliditylang.org and caches it at .solc/bin/.

Example test:

// contract_test.go
func TestContract(t *testing.T) {
    c := solc.New("0.8.21")
    contract, err := c.Compile("src", "Test",
        solc.WithOptimizer(&solc.Optimizer{Enabled: true, Runs: 999999}),
    )
    // ...
}

Example directory structure:

workspace/
├── .solc/
│   └── bin/ # cached solc binaries
│       └── solc_v0.8.21
├── src/
│   └── test.sol
├── contract_test.go
├── go.mod
└── go.sum

[!WARNING]

This package is pre-1.0. There might be breaking changes between minor versions.

Documentation

Overview

Package solc provides bindings for the Solidity compiler.

Index

Constants

This section is empty.

Variables

View Source
var SolcVersions []SolcVersion

SolcVersions is a list of all available solc versions.

Functions

func NewConsole

func NewConsole(tb testing.TB) *tracing.Hooks

NewConsole returns a [vm.tracing.Hooks] that logs calls of console.sol to the given testing.TB.

To use console logging in your Solidity contract, import "console.sol".

Types

type Compiler

type Compiler struct {
	// contains filtered or unexported fields
}

func New

func New(version SolcVersion) *Compiler

func (*Compiler) Compile

func (c *Compiler) Compile(dir, contract string, opts ...Option) (*Contract, error)

Compile all contracts in the given directory and return the contract code of the contract with the given name.

func (*Compiler) MustCompile

func (c *Compiler) MustCompile(dir, contract string, opts ...Option) *Contract

MustCompile is like Compiler.Compile but panics on error.

type Contract

type Contract struct {
	Runtime     []byte // The runtime bytecode of the contract.
	Constructor []byte // The constructor bytecode of the contract.
	Code        []byte // Deprecated: The bytecode of the contract after deployment.
	DeployCode  []byte // Deprecated: The bytecode to deploy the contract.
}

Contract represents a compiled contract.

type EVMVersion

type EVMVersion string

EVMVersion represents the EVM version to compile for.

const (
	EVMVersionPrague     EVMVersion = "prague"
	EVMVersionCancun     EVMVersion = "cancun"
	EVMVersionShanghai   EVMVersion = "shanghai"
	EVMVersionParis      EVMVersion = "paris"
	EVMVersionLondon     EVMVersion = "london"
	EVMVersionBerlin     EVMVersion = "berlin"
	EVMVersionIstanbul   EVMVersion = "istanbul"
	EVMVersionPetersburg EVMVersion = "petersburg"
	EVMVersionByzantium  EVMVersion = "byzantium"
)

type Optimizer

type Optimizer struct {
	Enabled bool   `json:"enabled"`
	Runs    uint64 `json:"runs"`
}

type Option

type Option func(*Settings)

An Option configures the compilation Settings.

func WithEVMVersion

func WithEVMVersion(evmVersion EVMVersion) Option

WithEVMVersion configures the compilation Settings to set the given EVM version.

func WithOptimizer

func WithOptimizer(o *Optimizer) Option

WithOptimizer configures the compilation Settings to set the given Optimizer.

func WithViaIR

func WithViaIR(enabled bool) Option

WithViaIR configures the compilation Settings to set viaIR to the given parameter "enabled".

type Settings

type Settings struct {
	Remappings      []string                       `json:"remappings,omitempty"`
	Optimizer       *Optimizer                     `json:"optimizer"`
	ViaIR           bool                           `json:"viaIR,omitempty"`
	EVMVersion      EVMVersion                     `json:"evmVersion"`
	OutputSelection map[string]map[string][]string `json:"outputSelection"`
	// contains filtered or unexported fields
}

Settings for the compilation.

type SolcVersion added in v0.3.0

type SolcVersion string

SolcVersion represents a solc version.

const (
	SolcVersion0_5_0  SolcVersion = "0.5.0"
	SolcVersion0_5_1  SolcVersion = "0.5.1"
	SolcVersion0_5_2  SolcVersion = "0.5.2"
	SolcVersion0_5_3  SolcVersion = "0.5.3"
	SolcVersion0_5_4  SolcVersion = "0.5.4"
	SolcVersion0_5_5  SolcVersion = "0.5.5"
	SolcVersion0_5_6  SolcVersion = "0.5.6"
	SolcVersion0_5_7  SolcVersion = "0.5.7"
	SolcVersion0_5_8  SolcVersion = "0.5.8"
	SolcVersion0_5_9  SolcVersion = "0.5.9"
	SolcVersion0_5_10 SolcVersion = "0.5.10"
	SolcVersion0_5_11 SolcVersion = "0.5.11"
	SolcVersion0_5_12 SolcVersion = "0.5.12"
	SolcVersion0_5_13 SolcVersion = "0.5.13"
	SolcVersion0_5_14 SolcVersion = "0.5.14"
	SolcVersion0_5_15 SolcVersion = "0.5.15"
	SolcVersion0_5_16 SolcVersion = "0.5.16"
	SolcVersion0_5_17 SolcVersion = "0.5.17"
	SolcVersion0_6_0  SolcVersion = "0.6.0"
	SolcVersion0_6_1  SolcVersion = "0.6.1"
	SolcVersion0_6_2  SolcVersion = "0.6.2"
	SolcVersion0_6_3  SolcVersion = "0.6.3"
	SolcVersion0_6_4  SolcVersion = "0.6.4"
	SolcVersion0_6_5  SolcVersion = "0.6.5"
	SolcVersion0_6_6  SolcVersion = "0.6.6"
	SolcVersion0_6_7  SolcVersion = "0.6.7"
	SolcVersion0_6_8  SolcVersion = "0.6.8"
	SolcVersion0_6_9  SolcVersion = "0.6.9"
	SolcVersion0_6_10 SolcVersion = "0.6.10"
	SolcVersion0_6_11 SolcVersion = "0.6.11"
	SolcVersion0_6_12 SolcVersion = "0.6.12"
	SolcVersion0_7_0  SolcVersion = "0.7.0"
	SolcVersion0_7_1  SolcVersion = "0.7.1"
	SolcVersion0_7_2  SolcVersion = "0.7.2"
	SolcVersion0_7_3  SolcVersion = "0.7.3"
	SolcVersion0_7_4  SolcVersion = "0.7.4"
	SolcVersion0_7_5  SolcVersion = "0.7.5"
	SolcVersion0_7_6  SolcVersion = "0.7.6"
	SolcVersion0_8_0  SolcVersion = "0.8.0"
	SolcVersion0_8_1  SolcVersion = "0.8.1"
	SolcVersion0_8_2  SolcVersion = "0.8.2"
	SolcVersion0_8_3  SolcVersion = "0.8.3"
	SolcVersion0_8_4  SolcVersion = "0.8.4"
	SolcVersion0_8_5  SolcVersion = "0.8.5"
	SolcVersion0_8_6  SolcVersion = "0.8.6"
	SolcVersion0_8_7  SolcVersion = "0.8.7"
	SolcVersion0_8_8  SolcVersion = "0.8.8"
	SolcVersion0_8_9  SolcVersion = "0.8.9"
	SolcVersion0_8_10 SolcVersion = "0.8.10"
	SolcVersion0_8_11 SolcVersion = "0.8.11"
	SolcVersion0_8_12 SolcVersion = "0.8.12"
	SolcVersion0_8_13 SolcVersion = "0.8.13"
	SolcVersion0_8_14 SolcVersion = "0.8.14"
	SolcVersion0_8_15 SolcVersion = "0.8.15"
	SolcVersion0_8_16 SolcVersion = "0.8.16"
	SolcVersion0_8_17 SolcVersion = "0.8.17"
	SolcVersion0_8_18 SolcVersion = "0.8.18"
	SolcVersion0_8_19 SolcVersion = "0.8.19"
	SolcVersion0_8_20 SolcVersion = "0.8.20"
	SolcVersion0_8_21 SolcVersion = "0.8.21"
	SolcVersion0_8_22 SolcVersion = "0.8.22"
	SolcVersion0_8_23 SolcVersion = "0.8.23"
	SolcVersion0_8_24 SolcVersion = "0.8.24"
	SolcVersion0_8_25 SolcVersion = "0.8.25"
	SolcVersion0_8_26 SolcVersion = "0.8.26"
	SolcVersion0_8_27 SolcVersion = "0.8.27"
	SolcVersion0_8_28 SolcVersion = "0.8.28"

	// Latest version of solc.
	SolcVersionLatest = SolcVersion0_8_28
)

func (SolcVersion) Cmp added in v0.3.0

func (v SolcVersion) Cmp(other SolcVersion) int

Compare returns -1, 0, or +1 depending on whether v < other, v == other, or v > other

func (SolcVersion) String added in v0.3.0

func (v SolcVersion) String() string

Directories

Path Synopsis
internal
console
Code generated by go generate; DO NOT EDIT.
Code generated by go generate; DO NOT EDIT.
mod

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL