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.

Example

Skipped External Service

1
SELECT
2
fully_qualified_name,
3
json_extract_string(method_identifiers, '$."value()"') AS value_selector,
4
concat('0x', lower(hex(source_hash))) AS source_hash
5
FROM compile(
6
'// SPDX-License-Identifier: MIT
7
pragma solidity 0.8.35;
8
contract ConstructorValue {
9
uint256 public value;
10
constructor(uint256 value_) { value = value_; }
11
}
12
',
13
'solidity',
14
compiler_version := '0.8.35',
15
optimizer := true,
16
optimizer_runs := 200,
17
evm_version := 'cancun',
18
via_ir := false,
19
warnings_as_errors := true,
20
metadata_hash := 'none',
21
append_cbor := false
22
);
23
-- => [{"fully_qualified_name":"<stdin>:ConstructorValue","value_selector":"3fa4f245","source_hash":"0xee9a6f021cdc9c8d8fea96975a53bfc954d83bb28e3c67b1d3e598ecfbf6612d"}]
Notebook ready in readonly mode.

API reference

Exact signatures with descriptions, requirements, inputs, returns, and examples.

compile(VARCHAR, VARCHAR) #

Compiles smart contract source with explicit language selection.

Inputs

NameTypeUseDefault
sourceVARCHAR

Solidity or Vyper source text.

positional or named
languageVARCHAR

Supported values are `solidity` and `vyper`.

optionalpositional or named'solidity'
evm_versionVARCHAR

Target revision forwarded to either compile endpoint; for example `cancun`.

optionalnamed
compiler_versionVARCHAR

Overrides `compiler` when both are supplied. Forwarded for Solidity but not Vyper.

optionalnamed
optimizerBOOLEAN

Named Solidity setting. Current service-side `options.settings` merging can override it.

optionalnamedtrue
Showing fewer

Result columns

NameType
successBOOLEAN

Whether this artifact compiled successfully

nameVARCHAR

Contract name

source_unitVARCHAR

Compiler source unit path

fully_qualified_nameVARCHAR

Source-unit-qualified contract name

languageVARCHAR

Source language

Showing fewer

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.

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.

Local SQL

1
-- This composition is only for the shown single uint256 constructor
2
SELECT bin || evm_abi_word(42::UINT256) AS init_code
3
FROM compile(source := 'contract C { constructor(uint256) {} }');
Notebook ready in readonly mode.

Additional overloads

Show 3 more overloads
compile(VARCHAR) #

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

Inputs

NameTypeUseDefault
sourceVARCHAR

Solidity source sent to the configured external compile service.

positional or named
evm_versionVARCHAR

Target revision forwarded to either compile endpoint; for example `cancun`.

optionalnamed
compiler_versionVARCHAR

Overrides `compiler` when both are supplied. Forwarded for Solidity but not Vyper.

optionalnamed
optimizerBOOLEAN

Named Solidity setting. Current service-side `options.settings` merging can override it.

optionalnamedtrue
optimizer_runsBIGINT

Named Solidity optimizer run count. Current service-side `options.settings` merging can override it.

optionalnamed200
Showing fewer

Result columns

NameType
successBOOLEAN

Whether this artifact compiled successfully

nameVARCHAR

Contract name

source_unitVARCHAR

Compiler source unit path

fully_qualified_nameVARCHAR

Source-unit-qualified contract name

languageVARCHAR

Source language

Showing fewer

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.

Overload examples

Local SQL

1
WITH artifact AS (
2
SELECT *
3
FROM compile(
4
'// SPDX-License-Identifier: MIT
5
pragma solidity 0.8.35;
6
contract ConstructorValue {
7
uint256 public value;
8
constructor(uint256 value_) { value = value_; }
9
}
10
'::VARCHAR,
11
compiler_version := '0.8.35',
12
optimizer := true,
13
optimizer_runs := 200,
14
evm_version := 'cancun',
15
via_ir := false,
16
warnings_as_errors := true,
17
metadata_hash := 'none',
18
append_cbor := false
19
)
20
)
21
SELECT
22
concat('0x', lower(hex(creation_code_hash))) AS creation_code_hash,
23
concat('0x', lower(hex(runtime_code_hash))) AS runtime_code_hash,
24
creation_code_hash = keccak256(bin) AS creation_hash_matches,
25
runtime_code_hash = keccak256(bin_runtime) AS runtime_hash_matches
26
FROM artifact;
27
-- => [{"creation_code_hash":"0xb2fc248ee82883b2b704cc6afece267ec9a4b455c0b86cc7aa195ba203228073","runtime_code_hash":"0x2afe39d222c1f56d8437884a4a024cc85fbbb04db2e09fb133c8b0f6525ef33f","creation_hash_matches":"true","runtime_hash_matches":"true"}]
compile(VARCHAR, VARCHAR, JSON) #

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

Inputs

NameTypeUseDefault
sourceVARCHAR

Solidity or Vyper source text.

positional or named
languageVARCHAR

Supported values are `solidity` and `vyper`.

optionalpositional or named'solidity'
optionsJSON

Advanced JSON compiler options. Named `options` overrides this positional value.

positional or named
evm_versionVARCHAR

Target revision forwarded to either compile endpoint; for example `cancun`.

optionalnamed
compiler_versionVARCHAR

Overrides `compiler` when both are supplied. Forwarded for Solidity but not Vyper.

optionalnamed
Showing fewer

Result columns

NameType
successBOOLEAN

Whether this artifact compiled successfully

nameVARCHAR

Contract name

source_unitVARCHAR

Compiler source unit path

fully_qualified_nameVARCHAR

Source-unit-qualified contract name

languageVARCHAR

Source language

Showing fewer

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.

Overload examples

Local SQL

1
SELECT
2
length(bin) AS creation_bytes,
3
length(bin_runtime) AS runtime_bytes,
4
metadata IS NULL AS metadata_omitted,
5
storage_layout IS NULL AS storage_layout_omitted,
6
transient_storage_layout IS NULL AS transient_layout_omitted
7
FROM compile(
8
'// SPDX-License-Identifier: MIT
9
pragma solidity 0.8.35;
10
contract ConstructorValue {
11
uint256 public value;
12
constructor(uint256 value_) { value = value_; }
13
}
14
',
15
'solidity',
16
'{"settings":{"optimizer":{"enabled":true,"runs":200},"evmVersion":"cancun","viaIR":false,"metadata":{"bytecodeHash":"none","appendCBOR":false}}}'::JSON,
17
compiler_version := '0.8.35',
18
warnings_as_errors := true,
19
output := 'abi,bin,bin-runtime'
20
);
21
-- => [{"creation_bytes":147,"runtime_bytes":67,"metadata_omitted":"true","storage_layout_omitted":"true","transient_layout_omitted":"true"}]
compile() #

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

Inputs

NameTypeUseDefault
sourceVARCHAR

Solidity or Vyper source sent to the configured service. Overrides positional source; whitespace is preserved for `source_hash`.

optionalnamed
evm_versionVARCHAR

Target revision forwarded to either compile endpoint; for example `cancun`.

optionalnamed
compiler_versionVARCHAR

Overrides `compiler` when both are supplied. Forwarded for Solidity but not Vyper.

optionalnamed
optimizerBOOLEAN

Named Solidity setting. Current service-side `options.settings` merging can override it.

optionalnamedtrue
optimizer_runsBIGINT

Named Solidity optimizer run count. Current service-side `options.settings` merging can override it.

optionalnamed200
Showing fewer

Result columns

NameType
successBOOLEAN

Whether this artifact compiled successfully

nameVARCHAR

Contract name

source_unitVARCHAR

Compiler source unit path

fully_qualified_nameVARCHAR

Source-unit-qualified contract name

languageVARCHAR

Source language

Showing fewer

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.

Overload examples

Local SQL

1
SELECT
2
compiler,
3
compiler_version,
4
evm_version,
5
optimizer,
6
optimizer_runs,
7
length(bin) AS creation_bytes,
8
length(bin_runtime) AS runtime_bytes
9
FROM compile(
10
source := '// SPDX-License-Identifier: MIT
11
pragma solidity 0.8.35;
12
contract ConstructorValue {
13
uint256 public value;
14
constructor(uint256 value_) { value = value_; }
15
}
16
',
17
language := 'solidity',
18
compiler := 'ignored-by-compiler-version',
19
compiler_version := '0.8.35',
20
optimizer := true,
21
optimizer_runs := 200,
22
evm_version := 'cancun',
23
via_ir := false,
24
warnings_as_errors := true,
25
metadata_hash := 'none',
26
append_cbor := false,
27
output_selection := 'default'
28
);
29
-- => [{"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}]

Related functions

Category and tags

Tag
Api