Skip to content

useCompileContract

Hook for compiling Sophia smart contract source code.

Import

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

Usage

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

function CompileForm() {
  const { mutate: compileContract, isPending, data } = useCompileContract()

  return (
    <div>
      <button
        onClick={() =>
          compileContract({ sourceCode, onCompiler: compiler })
        }
        disabled={isPending}
      >
        Compile
      </button>
      {data && <p>Bytecode: {data.bytecode}</p>}
    </div>
  )
}

Return Type

See TanStack Query mutation docs for full return type.

data

See compileContract Return Type.

Parameters

See compileContract Parameters for all available options.

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.

mutation

See TanStack Query mutation docs for mutation options.

Action