# compile

Compiles Solidity or Vyper source through the configured external service and normalizes one row per returned contract artifact. It performs network I/O and sends the supplied source to that service.

Canonical HTML: <https://determica.com/docs/functions/compile>

- Kind: table function
- Category: [Development and bytecode](/docs/category/development-and-bytecode.md)
- Tags: Api, Development

Compiles Solidity or Vyper source through the configured external service and normalizes one row per returned contract artifact. It performs network I/O and sends the supplied source to that service.

## Overload 1: compile(VARCHAR, VARCHAR)

```sql
compile(VARCHAR, VARCHAR)
```

Compiles smart contract source with explicit language selection.

- Kind: table
- Execution context: External Service
- Behavior: External Compilation
- Execution modes: External Service
- Input shape: Positional And Named
- Planning contract: Bind Time Request
- Cardinality: One Per Service Artifact
- Determinism: External State
- Return shape: Table
- Schema stability: Artifact Dependent
- Stability: Stable
- Side effects: network_io, source_disclosure

### Requirements

- configured_compile_service
- requested_compiler

### Risks

- service_unavailable
- rate_limit
- compiler_drift
- source_disclosure
- output_omission

### Inputs

- `source` (VARCHAR; positional or named) — Solidity or Vyper source text.
- `language` (VARCHAR; optional; positional or named; default: 'solidity') — Supported values are `solidity` and `vyper`.
- `evm_version` (VARCHAR; optional; named) — Target revision forwarded to either compile endpoint; for example `cancun`.
- `compiler_version` (VARCHAR; optional; named) — Overrides `compiler` when both are supplied. Forwarded for Solidity but not Vyper.
- `optimizer` (BOOLEAN; optional; named; default: true) — Named Solidity setting. Current service-side `options.settings` merging can override it.
- `optimizer_runs` (BIGINT; optional; named; default: 200) — Named Solidity optimizer run count. Current service-side `options.settings` merging can override it.
- `via_ir` (BOOLEAN; optional; named; default: false) — Named Solidity setting. Current service-side `options.settings` merging can override it.
- `metadata_hash` (VARCHAR; optional; named) — Solidity metadata bytecode hash mode such as `none`, `ipfs`, or `bzzr1`.
- `compiler` (VARCHAR; optional; named) — Compiler selection forwarded for Solidity. The current Vyper request does not forward this field.
- `warnings_as_errors` (BOOLEAN; optional; named; default: false) — Ask the service to promote Solidity warnings to request errors.
- `append_cbor` (BOOLEAN; optional; named) — Optional Solidity metadata setting. When omitted, no `append_cbor` field is sent and the backend/compiler default remains in force.
- `output` (VARCHAR; optional; named; default: 'default') — Overrides `output_selection` when both are supplied.
- `output_selection` (VARCHAR; optional; named; default: 'default') — Service output selection such as `default`, `opcodes`, or `abi,bin,bin-runtime`.
- `options` (JSON; optional; named) — Overrides positional options. In the current service, `options.settings` is merged after named settings and `options.sources` replaces the single `<stdin>` source set.

### Result columns

Compiled contract artifacts

Returns one row per normalized service artifact. Row order follows the service object and is not canonical. Outputs omitted by output selection are NULL; compiler errors normally throw rather than returning `success = false`. Unlinked placeholders are not valid BYTES, so link libraries before expecting bytecode or hash columns.

- `success` (BOOLEAN) — Whether this artifact compiled successfully
- `name` (VARCHAR) — Contract name
- `source_unit` (VARCHAR) — Compiler source unit path
- `fully_qualified_name` (VARCHAR) — Source-unit-qualified contract name
- `language` (VARCHAR) — Source language
- `compiler` (VARCHAR) — Compiler executable family
- `compiler_version` (VARCHAR) — Exact compiler version string
- `evm_version` (VARCHAR) — Target EVM version
- `optimizer` (BOOLEAN) — Whether optimizer was enabled
- `optimizer_runs` (BIGINT) — Optimizer runs setting
- `compiler_settings` (JSON) — Effective compiler settings
- `abi` (JSON) — Compiled contract ABI
- `bin` (BYTES) — Creation bytecode without constructor arguments
- `bin_runtime` (BYTES) — Compiler deployed-bytecode template; unresolved links or immutables can differ from final onchain code
- `source_hash` (BYTES32) — Keccak-256 of the exact SQL source string; not a full multi-source commitment when options.sources is used
- `artifact_hash` (BYTES32) — Current Determica compile-artifact v1 digest
- `creation_code_hash` (BYTES32) — Keccak-256 of raw bin without constructor arguments
- `runtime_code_hash` (BYTES32) — Keccak-256 of bin_runtime, not fetched account code
- `metadata` (JSON) — Compiler metadata
- `userdoc` (JSON) — NatSpec user documentation
- `devdoc` (JSON) — NatSpec developer documentation
- `storage_layout` (JSON) — Storage layout
- `transient_storage_layout` (JSON) — Transient storage layout
- `method_identifiers` (JSON) — Function selector map
- `link_references` (JSON) — Library link references
- `immutable_references` (JSON) — Immutable variable bytecode references
- `source_map` (VARCHAR) — Creation bytecode source map
- `source_map_runtime` (VARCHAR) — Runtime bytecode source map
- `opcodes` (VARCHAR) — Creation bytecode opcodes
- `opcodes_runtime` (VARCHAR) — Runtime bytecode opcodes
- `gas_estimates` (JSON) — Compiler gas estimates
- `generated_sources` (JSON) — Generated creation-code sources
- `generated_sources_runtime` (JSON) — Generated runtime-code sources
- `diagnostics` (JSON) — Compiler diagnostics
- `raw_artifact` (JSON) — Per-contract service artifact, not the top-level HTTP response

Compiled contract artifacts. Returns one row per normalized service artifact. Row order follows the service object and is not canonical. Outputs omitted by output selection are NULL; compiler errors normally throw rather than returning `success = false`. Unlinked placeholders are not valid BYTES, so link libraries before expecting bytecode or hash columns.

### Examples

_Local SQL · Skipped External Service_

```sql
-- Compile Solidity; read the value() selector and source hash
SELECT
  fully_qualified_name,
  json_extract_string(method_identifiers, '$."value()"') AS value_selector,
  concat('0x', lower(hex(source_hash))) AS source_hash
FROM compile(
'// SPDX-License-Identifier: MIT
pragma solidity 0.8.35;
contract ConstructorValue {
    uint256 public value;
    constructor(uint256 value_) { value = value_; }
}
',
  'solidity',
  compiler_version := '0.8.35',
  optimizer := true,
  optimizer_runs := 200,
  evm_version := 'cancun',
  via_ir := false,
  warnings_as_errors := true,
  metadata_hash := 'none',
  append_cbor := false
);
-- => [{"fully_qualified_name":"<stdin>:ConstructorValue","value_selector":"3fa4f245","source_hash":"0xee9a6f021cdc9c8d8fea96975a53bfc954d83bb28e3c67b1d3e598ecfbf6612d"}]
```

## Overload 2: compile(VARCHAR)

```sql
compile(VARCHAR)
```

Compiles Solidity source code by default and returns normalized contract artifacts.

- Kind: table
- Execution context: External Service
- Behavior: External Compilation
- Execution modes: External Service
- Input shape: Positional And Named
- Planning contract: Bind Time Request
- Cardinality: One Per Service Artifact
- Determinism: External State
- Return shape: Table
- Schema stability: Artifact Dependent
- Stability: Stable
- Side effects: network_io, source_disclosure

### Requirements

- configured_compile_service
- requested_compiler

### Risks

- service_unavailable
- rate_limit
- compiler_drift
- source_disclosure
- output_omission

### Inputs

- `source` (VARCHAR; positional or named) — Solidity source sent to the configured external compile service.
- `evm_version` (VARCHAR; optional; named) — Target revision forwarded to either compile endpoint; for example `cancun`.
- `compiler_version` (VARCHAR; optional; named) — Overrides `compiler` when both are supplied. Forwarded for Solidity but not Vyper.
- `optimizer` (BOOLEAN; optional; named; default: true) — Named Solidity setting. Current service-side `options.settings` merging can override it.
- `optimizer_runs` (BIGINT; optional; named; default: 200) — Named Solidity optimizer run count. Current service-side `options.settings` merging can override it.
- `language` (VARCHAR; optional; named; default: 'solidity') — Case-insensitive `solidity` or `vyper`. Overrides positional language.
- `via_ir` (BOOLEAN; optional; named; default: false) — Named Solidity setting. Current service-side `options.settings` merging can override it.
- `metadata_hash` (VARCHAR; optional; named) — Solidity metadata bytecode hash mode such as `none`, `ipfs`, or `bzzr1`.
- `compiler` (VARCHAR; optional; named) — Compiler selection forwarded for Solidity. The current Vyper request does not forward this field.
- `warnings_as_errors` (BOOLEAN; optional; named; default: false) — Ask the service to promote Solidity warnings to request errors.
- `append_cbor` (BOOLEAN; optional; named) — Optional Solidity metadata setting. When omitted, no `append_cbor` field is sent and the backend/compiler default remains in force.
- `output` (VARCHAR; optional; named; default: 'default') — Overrides `output_selection` when both are supplied.
- `output_selection` (VARCHAR; optional; named; default: 'default') — Service output selection such as `default`, `opcodes`, or `abi,bin,bin-runtime`.
- `options` (JSON; optional; named) — Overrides positional options. In the current service, `options.settings` is merged after named settings and `options.sources` replaces the single `<stdin>` source set.

### Result columns

Compiled contract artifacts

Returns one row per normalized service artifact. Row order follows the service object and is not canonical. Outputs omitted by output selection are NULL; compiler errors normally throw rather than returning `success = false`. Unlinked placeholders are not valid BYTES, so link libraries before expecting bytecode or hash columns.

- `success` (BOOLEAN) — Whether this artifact compiled successfully
- `name` (VARCHAR) — Contract name
- `source_unit` (VARCHAR) — Compiler source unit path
- `fully_qualified_name` (VARCHAR) — Source-unit-qualified contract name
- `language` (VARCHAR) — Source language
- `compiler` (VARCHAR) — Compiler executable family
- `compiler_version` (VARCHAR) — Exact compiler version string
- `evm_version` (VARCHAR) — Target EVM version
- `optimizer` (BOOLEAN) — Whether optimizer was enabled
- `optimizer_runs` (BIGINT) — Optimizer runs setting
- `compiler_settings` (JSON) — Effective compiler settings
- `abi` (JSON) — Compiled contract ABI
- `bin` (BYTES) — Creation bytecode without constructor arguments
- `bin_runtime` (BYTES) — Compiler deployed-bytecode template; unresolved links or immutables can differ from final onchain code
- `source_hash` (BYTES32) — Keccak-256 of the exact SQL source string; not a full multi-source commitment when options.sources is used
- `artifact_hash` (BYTES32) — Current Determica compile-artifact v1 digest
- `creation_code_hash` (BYTES32) — Keccak-256 of raw bin without constructor arguments
- `runtime_code_hash` (BYTES32) — Keccak-256 of bin_runtime, not fetched account code
- `metadata` (JSON) — Compiler metadata
- `userdoc` (JSON) — NatSpec user documentation
- `devdoc` (JSON) — NatSpec developer documentation
- `storage_layout` (JSON) — Storage layout
- `transient_storage_layout` (JSON) — Transient storage layout
- `method_identifiers` (JSON) — Function selector map
- `link_references` (JSON) — Library link references
- `immutable_references` (JSON) — Immutable variable bytecode references
- `source_map` (VARCHAR) — Creation bytecode source map
- `source_map_runtime` (VARCHAR) — Runtime bytecode source map
- `opcodes` (VARCHAR) — Creation bytecode opcodes
- `opcodes_runtime` (VARCHAR) — Runtime bytecode opcodes
- `gas_estimates` (JSON) — Compiler gas estimates
- `generated_sources` (JSON) — Generated creation-code sources
- `generated_sources_runtime` (JSON) — Generated runtime-code sources
- `diagnostics` (JSON) — Compiler diagnostics
- `raw_artifact` (JSON) — Per-contract service artifact, not the top-level HTTP response

Compiled contract artifacts. Returns one row per normalized service artifact. Row order follows the service object and is not canonical. Outputs omitted by output selection are NULL; compiler errors normally throw rather than returning `success = false`. Unlinked placeholders are not valid BYTES, so link libraries before expecting bytecode or hash columns.

### Examples

_Local SQL · Skipped External Service_

```sql
-- Compile with pinned compiler settings and check the code hashes
WITH artifact AS (
  SELECT *
  FROM compile(
'// SPDX-License-Identifier: MIT
pragma solidity 0.8.35;
contract ConstructorValue {
    uint256 public value;
    constructor(uint256 value_) { value = value_; }
}
'::VARCHAR,
    compiler_version := '0.8.35',
    optimizer := true,
    optimizer_runs := 200,
    evm_version := 'cancun',
    via_ir := false,
    warnings_as_errors := true,
    metadata_hash := 'none',
    append_cbor := false
  )
)
SELECT
  concat('0x', lower(hex(creation_code_hash))) AS creation_code_hash,
  concat('0x', lower(hex(runtime_code_hash))) AS runtime_code_hash,
  creation_code_hash = keccak256(bin) AS creation_hash_matches,
  runtime_code_hash = keccak256(bin_runtime) AS runtime_hash_matches
FROM artifact;
-- => [{"creation_code_hash":"0xb2fc248ee82883b2b704cc6afece267ec9a4b455c0b86cc7aa195ba203228073","runtime_code_hash":"0x2afe39d222c1f56d8437884a4a024cc85fbbb04db2e09fb133c8b0f6525ef33f","creation_hash_matches":"true","runtime_hash_matches":"true"}]
```

## Overload 3: compile(VARCHAR, VARCHAR, JSON)

```sql
compile(VARCHAR, VARCHAR, JSON)
```

Compiles smart contract source with explicit language and advanced JSON compiler options.

- Kind: table
- Execution context: External Service
- Behavior: External Compilation
- Execution modes: External Service
- Input shape: Positional And Named
- Planning contract: Bind Time Request
- Cardinality: One Per Service Artifact
- Determinism: External State
- Return shape: Table
- Schema stability: Artifact Dependent
- Stability: Stable
- Side effects: network_io, source_disclosure

### Requirements

- configured_compile_service
- requested_compiler

### Risks

- service_unavailable
- rate_limit
- compiler_drift
- source_disclosure
- output_omission

### Inputs

- `source` (VARCHAR; positional or named) — Solidity or Vyper source text.
- `language` (VARCHAR; optional; positional or named; default: 'solidity') — Supported values are `solidity` and `vyper`.
- `options` (JSON; positional or named) — Advanced JSON compiler options. Named `options` overrides this positional value.
- `evm_version` (VARCHAR; optional; named) — Target revision forwarded to either compile endpoint; for example `cancun`.
- `compiler_version` (VARCHAR; optional; named) — Overrides `compiler` when both are supplied. Forwarded for Solidity but not Vyper.
- `optimizer` (BOOLEAN; optional; named; default: true) — Named Solidity setting. Current service-side `options.settings` merging can override it.
- `optimizer_runs` (BIGINT; optional; named; default: 200) — Named Solidity optimizer run count. Current service-side `options.settings` merging can override it.
- `via_ir` (BOOLEAN; optional; named; default: false) — Named Solidity setting. Current service-side `options.settings` merging can override it.
- `metadata_hash` (VARCHAR; optional; named) — Solidity metadata bytecode hash mode such as `none`, `ipfs`, or `bzzr1`.
- `compiler` (VARCHAR; optional; named) — Compiler selection forwarded for Solidity. The current Vyper request does not forward this field.
- `warnings_as_errors` (BOOLEAN; optional; named; default: false) — Ask the service to promote Solidity warnings to request errors.
- `append_cbor` (BOOLEAN; optional; named) — Optional Solidity metadata setting. When omitted, no `append_cbor` field is sent and the backend/compiler default remains in force.
- `output` (VARCHAR; optional; named; default: 'default') — Overrides `output_selection` when both are supplied.
- `output_selection` (VARCHAR; optional; named; default: 'default') — Service output selection such as `default`, `opcodes`, or `abi,bin,bin-runtime`.

### Result columns

Compiled contract artifacts

Returns one row per normalized service artifact. Row order follows the service object and is not canonical. Outputs omitted by output selection are NULL; compiler errors normally throw rather than returning `success = false`. Unlinked placeholders are not valid BYTES, so link libraries before expecting bytecode or hash columns.

- `success` (BOOLEAN) — Whether this artifact compiled successfully
- `name` (VARCHAR) — Contract name
- `source_unit` (VARCHAR) — Compiler source unit path
- `fully_qualified_name` (VARCHAR) — Source-unit-qualified contract name
- `language` (VARCHAR) — Source language
- `compiler` (VARCHAR) — Compiler executable family
- `compiler_version` (VARCHAR) — Exact compiler version string
- `evm_version` (VARCHAR) — Target EVM version
- `optimizer` (BOOLEAN) — Whether optimizer was enabled
- `optimizer_runs` (BIGINT) — Optimizer runs setting
- `compiler_settings` (JSON) — Effective compiler settings
- `abi` (JSON) — Compiled contract ABI
- `bin` (BYTES) — Creation bytecode without constructor arguments
- `bin_runtime` (BYTES) — Compiler deployed-bytecode template; unresolved links or immutables can differ from final onchain code
- `source_hash` (BYTES32) — Keccak-256 of the exact SQL source string; not a full multi-source commitment when options.sources is used
- `artifact_hash` (BYTES32) — Current Determica compile-artifact v1 digest
- `creation_code_hash` (BYTES32) — Keccak-256 of raw bin without constructor arguments
- `runtime_code_hash` (BYTES32) — Keccak-256 of bin_runtime, not fetched account code
- `metadata` (JSON) — Compiler metadata
- `userdoc` (JSON) — NatSpec user documentation
- `devdoc` (JSON) — NatSpec developer documentation
- `storage_layout` (JSON) — Storage layout
- `transient_storage_layout` (JSON) — Transient storage layout
- `method_identifiers` (JSON) — Function selector map
- `link_references` (JSON) — Library link references
- `immutable_references` (JSON) — Immutable variable bytecode references
- `source_map` (VARCHAR) — Creation bytecode source map
- `source_map_runtime` (VARCHAR) — Runtime bytecode source map
- `opcodes` (VARCHAR) — Creation bytecode opcodes
- `opcodes_runtime` (VARCHAR) — Runtime bytecode opcodes
- `gas_estimates` (JSON) — Compiler gas estimates
- `generated_sources` (JSON) — Generated creation-code sources
- `generated_sources_runtime` (JSON) — Generated runtime-code sources
- `diagnostics` (JSON) — Compiler diagnostics
- `raw_artifact` (JSON) — Per-contract service artifact, not the top-level HTTP response

Compiled contract artifacts. Returns one row per normalized service artifact. Row order follows the service object and is not canonical. Outputs omitted by output selection are NULL; compiler errors normally throw rather than returning `success = false`. Unlinked placeholders are not valid BYTES, so link libraries before expecting bytecode or hash columns.

### Examples

_Local SQL · Skipped External Service_

```sql
-- Compile with JSON options that omit metadata and layouts
SELECT
  length(bin) AS creation_bytes,
  length(bin_runtime) AS runtime_bytes,
  metadata IS NULL AS metadata_omitted,
  storage_layout IS NULL AS storage_layout_omitted,
  transient_storage_layout IS NULL AS transient_layout_omitted
FROM compile(
'// SPDX-License-Identifier: MIT
pragma solidity 0.8.35;
contract ConstructorValue {
    uint256 public value;
    constructor(uint256 value_) { value = value_; }
}
',
  'solidity',
  '{"settings":{"optimizer":{"enabled":true,"runs":200},"evmVersion":"cancun","viaIR":false,"metadata":{"bytecodeHash":"none","appendCBOR":false}}}'::JSON,
  compiler_version := '0.8.35',
  warnings_as_errors := true,
  output := 'abi,bin,bin-runtime'
);
-- => [{"creation_bytes":147,"runtime_bytes":67,"metadata_omitted":"true","storage_layout_omitted":"true","transient_layout_omitted":"true"}]
```

## Overload 4: compile()

```sql
compile()
```

Compiles smart contract source provided through named parameters and returns normalized contract artifacts.

- Kind: table
- Execution context: External Service
- Behavior: External Compilation
- Execution modes: External Service
- Input shape: Positional And Named
- Planning contract: Bind Time Request
- Cardinality: One Per Service Artifact
- Determinism: External State
- Return shape: Table
- Schema stability: Artifact Dependent
- Stability: Stable
- Side effects: network_io, source_disclosure

### Requirements

- configured_compile_service
- requested_compiler

### Risks

- service_unavailable
- rate_limit
- compiler_drift
- source_disclosure
- output_omission

### Inputs

- `source` (VARCHAR; optional; named) — Solidity or Vyper source sent to the configured service. Overrides positional source; whitespace is preserved for `source_hash`.
- `evm_version` (VARCHAR; optional; named) — Target revision forwarded to either compile endpoint; for example `cancun`.
- `compiler_version` (VARCHAR; optional; named) — Overrides `compiler` when both are supplied. Forwarded for Solidity but not Vyper.
- `optimizer` (BOOLEAN; optional; named; default: true) — Named Solidity setting. Current service-side `options.settings` merging can override it.
- `optimizer_runs` (BIGINT; optional; named; default: 200) — Named Solidity optimizer run count. Current service-side `options.settings` merging can override it.
- `language` (VARCHAR; optional; named; default: 'solidity') — Case-insensitive `solidity` or `vyper`. Overrides positional language.
- `via_ir` (BOOLEAN; optional; named; default: false) — Named Solidity setting. Current service-side `options.settings` merging can override it.
- `metadata_hash` (VARCHAR; optional; named) — Solidity metadata bytecode hash mode such as `none`, `ipfs`, or `bzzr1`.
- `compiler` (VARCHAR; optional; named) — Compiler selection forwarded for Solidity. The current Vyper request does not forward this field.
- `warnings_as_errors` (BOOLEAN; optional; named; default: false) — Ask the service to promote Solidity warnings to request errors.
- `append_cbor` (BOOLEAN; optional; named) — Optional Solidity metadata setting. When omitted, no `append_cbor` field is sent and the backend/compiler default remains in force.
- `output` (VARCHAR; optional; named; default: 'default') — Overrides `output_selection` when both are supplied.
- `output_selection` (VARCHAR; optional; named; default: 'default') — Service output selection such as `default`, `opcodes`, or `abi,bin,bin-runtime`.
- `options` (JSON; optional; named) — Overrides positional options. In the current service, `options.settings` is merged after named settings and `options.sources` replaces the single `<stdin>` source set.

### Result columns

Compiled contract artifacts

Returns one row per normalized service artifact. Row order follows the service object and is not canonical. Outputs omitted by output selection are NULL; compiler errors normally throw rather than returning `success = false`. Unlinked placeholders are not valid BYTES, so link libraries before expecting bytecode or hash columns.

- `success` (BOOLEAN) — Whether this artifact compiled successfully
- `name` (VARCHAR) — Contract name
- `source_unit` (VARCHAR) — Compiler source unit path
- `fully_qualified_name` (VARCHAR) — Source-unit-qualified contract name
- `language` (VARCHAR) — Source language
- `compiler` (VARCHAR) — Compiler executable family
- `compiler_version` (VARCHAR) — Exact compiler version string
- `evm_version` (VARCHAR) — Target EVM version
- `optimizer` (BOOLEAN) — Whether optimizer was enabled
- `optimizer_runs` (BIGINT) — Optimizer runs setting
- `compiler_settings` (JSON) — Effective compiler settings
- `abi` (JSON) — Compiled contract ABI
- `bin` (BYTES) — Creation bytecode without constructor arguments
- `bin_runtime` (BYTES) — Compiler deployed-bytecode template; unresolved links or immutables can differ from final onchain code
- `source_hash` (BYTES32) — Keccak-256 of the exact SQL source string; not a full multi-source commitment when options.sources is used
- `artifact_hash` (BYTES32) — Current Determica compile-artifact v1 digest
- `creation_code_hash` (BYTES32) — Keccak-256 of raw bin without constructor arguments
- `runtime_code_hash` (BYTES32) — Keccak-256 of bin_runtime, not fetched account code
- `metadata` (JSON) — Compiler metadata
- `userdoc` (JSON) — NatSpec user documentation
- `devdoc` (JSON) — NatSpec developer documentation
- `storage_layout` (JSON) — Storage layout
- `transient_storage_layout` (JSON) — Transient storage layout
- `method_identifiers` (JSON) — Function selector map
- `link_references` (JSON) — Library link references
- `immutable_references` (JSON) — Immutable variable bytecode references
- `source_map` (VARCHAR) — Creation bytecode source map
- `source_map_runtime` (VARCHAR) — Runtime bytecode source map
- `opcodes` (VARCHAR) — Creation bytecode opcodes
- `opcodes_runtime` (VARCHAR) — Runtime bytecode opcodes
- `gas_estimates` (JSON) — Compiler gas estimates
- `generated_sources` (JSON) — Generated creation-code sources
- `generated_sources_runtime` (JSON) — Generated runtime-code sources
- `diagnostics` (JSON) — Compiler diagnostics
- `raw_artifact` (JSON) — Per-contract service artifact, not the top-level HTTP response

Compiled contract artifacts. Returns one row per normalized service artifact. Row order follows the service object and is not canonical. Outputs omitted by output selection are NULL; compiler errors normally throw rather than returning `success = false`. Unlinked placeholders are not valid BYTES, so link libraries before expecting bytecode or hash columns.

### Examples

_Local SQL · Skipped External Service_

```sql
-- Compile through named parameters and read back the compiler settings
SELECT
  compiler,
  compiler_version,
  evm_version,
  optimizer,
  optimizer_runs,
  length(bin) AS creation_bytes,
  length(bin_runtime) AS runtime_bytes
FROM compile(
  source := '// SPDX-License-Identifier: MIT
pragma solidity 0.8.35;
contract ConstructorValue {
    uint256 public value;
    constructor(uint256 value_) { value = value_; }
}
',
  language := 'solidity',
  compiler := 'ignored-by-compiler-version',
  compiler_version := '0.8.35',
  optimizer := true,
  optimizer_runs := 200,
  evm_version := 'cancun',
  via_ir := false,
  warnings_as_errors := true,
  metadata_hash := 'none',
  append_cbor := false,
  output_selection := 'default'
);
-- => [{"compiler":"solc","compiler_version":"0.8.35+commit.47b9dedd.Linux.g++","evm_version":"cancun","optimizer":"true","optimizer_runs":200,"creation_bytes":147,"runtime_bytes":67}]
```

## Guidance

### Precedence and effective settings

Defaults are Solidity, optimizer enabled with 200 runs, `via_ir = false`, `warnings_as_errors = false`, and output selection `default`. Named `source`, `language`, and `options` override positional values; `compiler_version` overrides `compiler`; `output` overrides `output_selection`.

- Omitting `append_cbor` does not send false.
- The current service merges `options.settings` after named settings, so it can change effective optimizer, EVM, IR, metadata, or output settings.
- The current service replaces `<stdin>` with `options.sources` when supplied.
- Solidity compiler selection is forwarded. Vyper selection is not; inspect returned `compiler_version`.

### External service boundary

The default client uses `DETERMICA_API_URL` when configured and otherwise the hosted Determica EVM endpoint. Source code is posted to that service; this function is not necessarily local.

- Availability, latency, retries, rate limits, source disclosure, backend/compiler drift, and output-selection changes affect the call.
- Errors include missing source, unsupported language, malformed options JSON, unavailable compilers, promoted diagnostics, HTTP failures, empty or malformed responses, and responses without contract data.

### Artifact meaning and limits

`bin` is creation bytecode without constructor arguments. `bin_runtime` is the compiler's deployed-bytecode template; immutable references and unresolved links can make final onchain code differ.

- `creation_code_hash` hashes raw `bin`; `runtime_code_hash` hashes `bin_runtime`, not deployed account code.
- `source_hash` hashes the exact SQL source string including whitespace and is not a complete commitment when `options.sources` replaces it.
- `artifact_hash` is the Determica v1 Keccak digest over the ordered concatenation of language, compiler fields, fully qualified name, source hash, compiler settings, ABI, creation bytecode, runtime bytecode, and metadata. It does not cover every return column or the compiler executable.
- `raw_artifact` is per-contract service JSON.
- Compilation is not a security audit, deployment simulation, verification proof, or transaction builder.

```sql
-- This composition is only for the shown single uint256 constructor
SELECT bin || evm_abi_word(42::UINT256) AS init_code
FROM compile(source := 'contract C { constructor(uint256) {} }');
```

## Related functions

- [evm_disassemble](/docs/functions/evm_disassemble.md) — Usually Before
