# abi_encode_packed

Encodes scalar values with Solidity's packed ABI rules. The result has no selector, offsets, lengths, or 32-byte padding.

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

- Kind: scalar function
- Category: [Contracts and ABI](/docs/category/contracts-and-abi.md)
- Tags: ABI

Encodes scalar values with Solidity's packed ABI rules. The result has no selector, offsets, lengths, or 32-byte padding.

## Overload 1: abi_encode_packed(JSON, ...args)

```sql
abi_encode_packed(JSON, ...args)
```

Uses a constant JSON type list to encode the corresponding scalar values in order. A literal NULL type list returns NULL; arrays and tuples are unsupported.

- Kind: scalar
- Execution context: Offline
- Behavior: Abi Packed Encode
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Bind Time Types
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Requirements

- foldable_type_list
- supported_scalar_types_only

### Risks

- packed_encoding_collisions
- arrays_and_tuples_unsupported
- product_semantics:null_type_list_short_circuits

### Inputs

- `types` (JSON; required; positional) — Constant JSON array of Solidity ABI scalar types, with one type for each value.
- `values` (ANY; positional; variadic) — One SQL value per type in the types array. Supported types are address, bool, uintN, intN, bytesN, bytes, and string; arrays and tuples are not supported.

### Returns

Packed ABI bytes

Returns the Solidity packed encoding as BYTES.

- `packed_bytes` (BYTES)

Packed ABI bytes. Returns the Solidity packed encoding as BYTES.

### Examples

_Local SQL · Local_

```sql
-- Encode a Uniswap V3-style path segment: tokenIn + fee + tokenOut
SELECT abi_encode_packed(
  '["address","uint24","address"]'::JSON,
  '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'::ADDRESS, -- Ethereum mainnet WETH
  500,
  '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'::ADDRESS -- Ethereum mainnet USDC
);
```

## Guidance

### Use packed encoding safely

Packed values are not self-describing. Different type and value sequences can produce identical bytes, so only hash packed data when the protocol defines an unambiguous layout.

- Array and tuple packed encoding is currently unsupported.
- Use abi_encode_packed for Uniswap V3 path segments: tokenIn + uint24 fee + tokenOut.
- Use keccak256(abi_encode_packed(...)) for Solidity-style packed hashing.
- Do not use packed encoding for normal contract calldata; use encode_function_data instead.

```sql
SELECT abi_encode_packed(
  '["address","uint24","address"]'::JSON,
  '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'::ADDRESS, -- Ethereum mainnet WETH
  500,
  '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'::ADDRESS -- Ethereum mainnet USDC
) AS v3_path_segment;
```

### Choose the right ABI primitive

Choose by byte framing and direction: selector construction, standard arguments, calldata, packed bytes, raw words, calldata decoding, and return-data decoding are distinct operations.

- function_selector hashes already-canonical signature text exactly; function_selector_json builds a canonical signature from one JSON ABI fragment first.
- encode_function_args emits selector-free standard ABI arguments; encode_function_data prefixes those same bytes with the 4-byte selector.
- abi_encode_packed concatenates compact scalar encodings without standard ABI offsets, lengths, or 32-byte padding; evm_abi_word always emits exactly one padded 32-byte word.
- decode_function_data consumes and validates selector-prefixed calldata inputs; call_decode consumes selector-free function return bytes.

```sql
SELECT
  function_selector('transfer(address,uint256)') AS selector,
  encode_function_data(
    '[{"type":"function","name":"transfer","inputs":[{"type":"address"},{"type":"uint256"}]}]'::JSON,
    'transfer(address,uint256)',
    '0x000000000000000000000000000000000000dEaD'::ADDRESS,
    1::UINT256
  ) AS calldata;
```

## Related functions

- [encode_function_data](/docs/functions/encode_function_data.md) — Alternative
- [encode_function_args](/docs/functions/encode_function_args.md) — See Also
- [evm_abi_word](/docs/functions/evm_abi_word.md) — Alternative
- [keccak256](/docs/functions/keccak256.md) — Usually Before
