# execute_contract

Selects an ABI function, encodes its arguments, and builds one step for ordered, non-atomic PROGRAM execution.

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

- Kind: scalar function
- Category: [Simulation](/docs/category/simulation.md)
- Tags: Program Compiler, Simulate

Selects an ABI function, encodes its arguments, and builds one step for ordered, non-atomic PROGRAM execution.

## Overload 1: execute_contract(ADDRESS, ADDRESS, UINT256, UBIGINT, JSON, VARCHAR, ...args)

```sql
execute_contract(ADDRESS, ADDRESS, UINT256, UBIGINT, JSON, VARCHAR, ...args)
```

Selects an ABI function, encodes its arguments, and builds one step for ordered, non-atomic PROGRAM execution.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `sender` (ADDRESS; required; positional) — Account exposed as the call sender.
- `target` (ADDRESS; required; positional) — Contract called by the step.
- `value` (UINT256; required; positional) — Exact UINT256 native-token value, in Wei, sent by the call.
- `gas_limit` (UBIGINT; required; positional) — UBIGINT gas limit; values greater than INT64_MAX are rejected.
- `abi` (JSON; required; positional) — Non-NULL JSON ABI used to select a function and encode calldata.
- `function_name` (VARCHAR; required; positional) — Function name, canonical signature, or supported selector literal resolved against the ABI and arguments.
- `function_args` (ANY; positional; variadic) — One non-NULL SQL value per Solidity input, in ABI order. Incompatible values and ambiguous overloads fail.

### Returns

ABI call STEP

Returns a STEP with encoded calldata and zero gas price and empty access-list and blob-hash context.

- `step` (STEP)

ABI call STEP. Returns a STEP with encoded calldata and zero gas price and empty access-list and blob-hash context.

### Examples

_Local SQL · Local_

```sql
WITH actors AS (
  SELECT
    '0x1000000000000000000000000000000000000001'::ADDRESS AS sender,
    '0x2000000000000000000000000000000000000002'::ADDRESS AS writer,
    '0x3000000000000000000000000000000000000003'::ADDRESS AS second_target
),
step_values AS (
  SELECT [
    execute_call(
      sender,
      writer,
      '0x000000000000000000000000000000000000000000000000000000000000002a'::BYTES,
      1::UINT256,
      100000::UBIGINT
    ),
    execute_contract(
      sender,
      second_target,
      0::UINT256,
      100000::UBIGINT,
      '[{"type":"function","name":"set","inputs":[{"name":"value","type":"uint256"}],"outputs":[]}]'::JSON,
      'set'::VARCHAR,
      7::UINT256
    )
  ] AS steps
  FROM actors
),
authored AS (
  SELECT steps, program(steps) AS program
  FROM step_values
)
SELECT
  len(steps)::INTEGER AS step_count,
  'raw,abi'::VARCHAR AS step_order,
  program IS NOT NULL AS runnable
FROM authored;
-- => [{"step_count":2,"step_order":"raw,abi","runnable":"true"}]
```

## Overload 2: execute_contract(ADDRESS, ADDRESS, UINT256, UBIGINT, CALL_CONTEXT, JSON, VARCHAR, ...args)

```sql
execute_contract(ADDRESS, ADDRESS, UINT256, UBIGINT, CALL_CONTEXT, JSON, VARCHAR, ...args)
```

Selects and ABI-encodes one contract call step with explicit CALL_CONTEXT.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `sender` (ADDRESS; required; positional) — Account exposed as the call sender.
- `target` (ADDRESS; required; positional) — Contract called by the step.
- `value` (UINT256; required; positional) — Exact UINT256 native-token value, in Wei, sent by the call.
- `gas_limit` (UBIGINT; required; positional) — UBIGINT gas limit; values greater than INT64_MAX are rejected.
- `context` (CALL_CONTEXT; required; positional) — Non-NULL CALL_CONTEXT supplying gas price, access list, and blob versioned hashes.
- `abi` (JSON; required; positional) — Non-NULL JSON ABI used to select a function and encode calldata.
- `function_name` (VARCHAR; required; positional) — Function name, canonical signature, or supported selector literal resolved against the ABI and arguments.
- `function_args` (ANY; positional; variadic) — One non-NULL SQL value per Solidity input, in ABI order. Incompatible values and ambiguous overloads fail.

### Returns

Contextual ABI call STEP

Returns an ABI-encoded STEP carrying the supplied CALL_CONTEXT.

- `step` (STEP)

Contextual ABI call STEP. Returns an ABI-encoded STEP carrying the supplied CALL_CONTEXT.

### Examples

_Local SQL · Local_

```sql
WITH actors AS (
  SELECT
    '0x1000000000000000000000000000000000000001'::ADDRESS AS sender,
    '0x2000000000000000000000000000000000000002'::ADDRESS AS writer,
    '0x3000000000000000000000000000000000000003'::ADDRESS AS second_target
),
inputs AS (
  SELECT
    *,
    call_context(
      1::UINT256,
      [{
        address: writer,
        storage_keys: [
          '0x0000000000000000000000000000000000000000000000000000000000000000'::BYTES32
        ]
      }],
      []::BYTES32[]
    ) AS context
  FROM actors
),
step_values AS (
  SELECT [
    execute_call(
      sender,
      writer,
      '0x000000000000000000000000000000000000000000000000000000000000002a'::BYTES,
      1::UINT256,
      100000::UBIGINT,
      context
    ),
    execute_contract(
      sender,
      second_target,
      0::UINT256,
      100000::UBIGINT,
      context,
      '[{"type":"function","name":"set","inputs":[{"name":"value","type":"uint256"}],"outputs":[]}]'::JSON,
      'set'::VARCHAR,
      7::UINT256
    )
  ] AS steps
  FROM inputs
),
authored AS (
  SELECT steps, program(steps) AS program
  FROM step_values
)
SELECT
  len(steps)::INTEGER AS step_count,
  'raw,abi'::VARCHAR AS step_order,
  program IS NOT NULL AS runnable
FROM authored;
-- => [{"step_count":2,"step_order":"raw,abi","runnable":"true"}]
```

## Guidance

### ABI validation

Construction fails for malformed ABI, NULL arguments, missing or incompatible functions, ambiguous overloads, argument-count mismatches, or values that cannot be ABI-encoded.

### PROGRAM execution

PROGRAM executes steps in list order without atomic rollback and stops after the first unsuccessful step.

## Related functions

- [assume_native_balance](/docs/functions/assume_native_balance.md) — See Also
- [call_context](/docs/functions/call_context.md) — See Also
- [execute_call](/docs/functions/execute_call.md) — See Also
- [program](/docs/functions/program.md) — See Also
- [observe](/docs/functions/observe.md) — See Also
- [run](/docs/functions/run.md) — See Also
