Skip to content

useCompileContract

Primitive for compiling Sophia smart contract source code.

Import

typescript
import { useCompileContract } from '@growae/reactive-solid'

Usage

tsx
import { useCompileContract } from '@growae/reactive-solid'

function CompileForm() {
  const compileContract = useCompileContract()

  return (
    <div>
      <button
        onClick={() =>
          compileContract.mutate({ sourceCode, onCompiler: compiler })
        }
        disabled={compileContract.isPending}
      >
        Compile
      </button>
      <Show when={compileContract.data}>
        <p>Bytecode: {compileContract.data?.bytecode}</p>
        <p>Contract: {(compileContract.data?.aci as any)?.contract?.name}</p>
      </Show>
    </div>
  )
}

Parameters

See compileContract Parameters.

Key parameters:

ParameterTypeDefaultDescription
sourceCodestringRequired. Sophia source code to compile.
fileSystemRecord<string, string>Optional. Map of included file paths to their contents.
onCompilerCompilerBaseRequired. Compiler instance to use.

aci vs rawAci

  • Use compileContract.data?.aci to read the contract name and function list for UI rendering.
  • Use compileContract.data?.rawAci as the aci parameter when calling useDeployContract — it is the full array expected by the SDK.

Action