solc

package module
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: MIT Imports: 17 Imported by: 0

README

solc: Go Bindings for the Solidity Compiler

Go Reference Go Report Card

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

go get github.com/lmittmann/solc

Getting Started

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

Example test:

// contract_test.go
func TestContract(t *testing.T) {
    c := &solc.Compiler{Version: "0.8.18"}
    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.18
├── 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

This section is empty.

Functions

This section is empty.

Types

type Compiler

type Compiler struct {
	Version string // Solc version
	// contains filtered or unexported fields
}

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 {
	Code       []byte // The bytecode of the contract after deployment.
	DeployCode []byte // 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 (
	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.

Directories

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

Jump to

Keyboard shortcuts

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