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

# token: Token API

> Token API: the declaration and description of each of the 6 exports of @eco-incorp/sauce.

The `token` namespace emits SauceScript for token operations: ERC-20 on an EVM compile target, SPL Token on `svm`. It is TypeScript that writes SauceScript for a host program; a SauceScript program imports the [`@sauce/token`](https://docs.eco.com/sauce-libraries/token) library instead. `token.Token.transfer({ token, to, amount }).toSauceScript("evm")` returns an object whose `source` is a program `routes.compileSauceProgram` compiles. `token.Token` is also the root export `Token`.

```typescript theme={null}
import { token } from "@eco-incorp/sauce";
```

Generated from the type declarations of `@eco-incorp/sauce`.

### `token.TokenSauceScript`

*Interface* · `@eco-incorp/sauce`

```typescript theme={null}
export interface TokenSauceScript {
    readonly imports: readonly string[];
    readonly statement: string;
    readonly source: string;
    readonly accountRefs?: readonly string[];
}
```

### `token.TokenCall`

*Interface* · `@eco-incorp/sauce`

```typescript theme={null}
export interface TokenCall {
    readonly spec: TokenSpec;
    source(target: TokenTarget): string;
    statement(target: TokenTarget): string;
    expression(target: TokenTarget): string;
    toSauceScript(target: TokenTarget): TokenSauceScript;
    toCall(): {
        readonly target: `0x${string}`;
        readonly data: Hex;
        readonly value: bigint;
    };
    accountRefs(): readonly string[];
}
```

### `token.TokenBinding`

*Interface* · `@eco-incorp/sauce`

What `Token(<addr>)` yields **inside a route body** - the wrapper form, not the runtime API.

Route-body calls are positional (`Token(a).approve(spender, amt)`) where the runtime
\[`TokenApi`] takes a spec object, because the body is compiled to Sauce bytecode rather than
executed: `token-rewrite.ts#rewriteTokenFactory` lowers each write to `@sauce/token`'s function
of the same name, which has OpenZeppelin `SafeERC20` semantics, and each read to `IERC20.at`,
before the compiler sees it. These signatures are what let a **typed closure** body typecheck on
the way there. The writes return nothing: they revert the program unless the token accepted
them. Nothing calls these at run time, which is why they live here rather than on `TokenApi`.

```typescript theme={null}
export interface TokenBinding {
    transfer(to: AddressInput, amount: bigint): void;
    approve(spender: AddressInput, amount: bigint): void;
    transferFrom(from: AddressInput, to: AddressInput, amount: bigint): void;
    balanceOf(owner: AddressInput): bigint;
}
```

### `token.TokenFactory`

*Interface* · `@eco-incorp/sauce`

The call signature the package root's `Token` export carries, intersected onto \[`TokenApi`] by
`gen-route-globals.mjs` - the same way each chain accessor is `ChainGlobals[...] & ChainContracts`.

Deliberately NOT on `TokenApi` itself: the runtime `Token` value is a frozen object and is not
callable, so typing it as callable would promise something that throws. It describes what is
legal in a route BODY, where the call is rewritten before compiling and never survives to run.

```typescript theme={null}
export interface TokenFactory {
    (address: AddressInput): TokenBinding;
}
```

### `token.TokenApi`

*Interface* · `@eco-incorp/sauce`

```typescript theme={null}
export interface TokenApi {
    transfer(spec: TokenTransferSpec): TokenCall;
    approve(spec: TokenApproveSpec): TokenCall;
    balanceOf(spec: TokenBalanceSpec): TokenCall;
    program(specs: readonly TokenSpec[], opts: {
        target: TokenTarget;
    }): string;
    readonly ata: typeof ata;
    readonly TOKEN_PROGRAM: bigint;
    readonly TOKEN_2022_PROGRAM: bigint;
    readonly ERC20ABI: typeof ERC20ABI;
    readonly SPL_TRANSFER_CHECKED: number;
    readonly SPL_APPROVE_CHECKED: number;
    readonly SPL_AMOUNT_OFFSET: number;
    readonly MINT_DECIMALS_OFFSET: number;
}
```

### `token.Token`

*Variable* · `@eco-incorp/sauce`

The universal token interface - ERC20 on an EVM compile target, SPL Token on `svm`. Re-exported from the package root as `Token`;
also available as the named export `token.Token`.

```typescript theme={null}
Token: TokenApi
```


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