> ## Documentation Index
> Fetch the complete documentation index at: https://docs.li.fi/llms.txt
> Use this file to discover all available pages before exploring further.

# core.call

> Call a smart contract function, optionally spending a token resource

`core.call` calls a contract function that no higher-level op wraps, such as a vault redeem, a reward claim or a custom entry point. You give it a `target` contract and a human-readable `functionSignature`; it ABI-encodes the call from the bound arguments. Optionally it spends a resource (`resource`) and grants approvals for the call (`approvals`).

`target` can be any contract on the flow's chain. Composer keeps no allowlist of call targets, so check the address yourself: the call runs from the execution proxy, with any approvals you grant it.

A call that spends no resource travels on the wire as `core.invoke`. The SDK sends `core.invoke` whenever you omit `resource`. It takes the same `target`, `functionSignature`, `callType` and `args`, but has no input port and no `approvals`. If you write flow JSON by hand, use `core.invoke` for a call that spends nothing.

Only two return shapes are accepted: a signature that returns `uint256` exposes the value on `.result` as a handle, and a signature with no return clause exposes nothing. Any other return type fails the compile. To track a returned amount as a resource, pass `.result` to `core.asResource`.

Before writing a direct call, check whether [`lifi.zap`](https://docs.li.fi/composer/composer-api/ops/lifi-zap) or [`lifi.swap`](https://docs.li.fi/composer/composer-api/ops/lifi-swap) covers the action; they encode the protocol call for you. For pre-encoded calldata use `core.rawCall`; for a read at execution time use `core.staticCall`; for a read at compile time, baked into the transaction as a constant, use `core.peek`.

## Ports

| Port | Kind | Meaning |
| - | - | - |
| `input` | input resource | The tokens the call spends. In the SDK, pass it as `resource`; a call can also spend nothing. |
| `result` | output handle (`uint256`), optional | The function's return value, when its signature returns `uint256`. |

## Config

| Field | Type | Required | Meaning |
| - | - | - | - |
| `target` | address | yes | The contract to call. |
| `functionSignature` | string | yes | A human-readable signature, such as `'function redeem(uint256 shares, address receiver, address owner) returns (uint256)'`. It returns `uint256` or nothing; any other return type fails the compile. |
| `callType` | `'Call' \| 'ValueCall'` | no | `'ValueCall'` for a payable function that receives the native coin. |
| `approvals` | `{ spender }[]` | no | Allowances the proxy grants on the spent token before the call, for a contract that pulls with `transferFrom`. |

Bind the function's arguments by parameter name in `bind`, as in the example below.

## Example

Redeem ERC-4626 vault shares back to the underlying USDC:

```ts theme={"system"}
import { createComposeSdk, materialisers, resources } from '@lifi/composer-sdk';

// Steakhouse USDC, an ERC-4626 vault on Ethereum mainnet
const VAULT = '0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB';
const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';

const sdk = createComposeSdk({
  baseUrl: 'https://composer.li.quest',
  apiKey: process.env.LIFI_API_KEY!,
});

const builder = sdk.flow(1, {
  name: 'redeem-from-vault',
  inputs: { shares: resources.erc20(VAULT, 1) },
});

const redeemResult = builder.core.call('redeem', {
  resource: builder.inputs.shares,
  bind: {
    shares: builder.inputs.shares,
    receiver: builder.context.executionAddress,
    owner: builder.context.executionAddress,
  },
  config: {
    target: VAULT,
    functionSignature:
      'function redeem(uint256 shares, address receiver, address owner) returns (uint256)',
    approvals: [{ spender: VAULT }],
  },
});

// Graduate the uint256 return value into a tracked resource.
builder.core.asResource('underlying', {
  bind: { handle: redeemResult.result },
  config: { resource: resources.erc20(USDC, 1) },
});

await builder.compile({
  signer: '0xYourSignerAddress',
  inputs: {
    shares: materialisers.directDeposit({ amount: '1000000000000000000' }), // 1 share (18 decimals)
  },
  sweepTo: builder.context.sender,
});
```

See [`callContract.ts`](https://github.com/lifinance/composer-sdk-examples/blob/main/examples/callContract.ts) for more, including a call that spends no tokens and `ValueCall` for payable functions.

## Errors

| Error | Cause | Fix |
| - | - | - |
| `decode_error` (400) | `functionSignature` returns a type other than `uint256`; the config schema rejects it. | Use a signature that returns `uint256` or nothing. |
| `simulation_revert` (422) | The target contract reverted in simulation. | Read `err.details` for the decoded revert; check the arguments, the approval and the amount. |
| `verification_error` (500) | The request to verify the compiled program failed. | Retry, then contact LI.FI support. |
| `validation_error` with `forbidden_operation` | `core.call` in a standard destination flow. | Make the destination flow exact; see [Exact destination flows](https://docs.li.fi/composer/composer-api/ops/continuation-settle.md#exact-destination-flows). |

A verification result of `allVerified: false` does not fail the compile.

## Related

* [`core.asResource`](https://docs.li.fi/composer/composer-api/ops): track a returned amount as a resource.
* [`lifi.zap`](https://docs.li.fi/composer/composer-api/ops/lifi-zap): protocol calls the routing catalog already covers.
* [Pay cross-chain](https://docs.li.fi/composer/composer-api/recipes/pay-cross-chain.md): replace its transfers with a `core.call` to your payment contract.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.