> ## 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: Specs, parameters and source emission

> Specs, parameters and source emission: 31 exports of the token module of @eco-incorp/sauce, including Address, AddressInput, TokenTarget, TokenOp, SPL_TRANSFER_CHECKED, SPL_APPROVE_CHECKED.

The `token` namespace emits SauceScript for token operations: ERC-20 on an EVM compile target, SPL Token on `svm`. `token.Token` is also installed as the default global `Token`.

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

This page covers `sdk/dist/token/types.d.ts`, `sdk/dist/token/params.d.ts`, `sdk/dist/token/source.d.ts`.

<Note>
  Generated from the type declarations shipped in `@eco-incorp/sauce` 0.99.4. Each entry shows the package authors' JSDoc and declaration for this SDK version. For runtime compatibility and deployed addresses, see [architecture and deployments](/programmable-transactions/sauce/architecture-and-deployments).
</Note>

### `token.Address`

*Type* · `sdk/dist/token/types.d.ts`

A 20-byte EVM address, as an ordinary `0x`-prefixed hex string.

```typescript theme={null}
export type Address = `0x${string}`;
```

### `token.AddressInput`

*Type* · `sdk/dist/token/types.d.ts`

Anything the token normalizers accept for an address-shaped field.

```typescript theme={null}
export type AddressInput = Address | bigint;
```

### `token.TokenTarget`

*Type* · `sdk/dist/token/types.d.ts`

`"evm"` is a target-agnostic alias for the ERC20 arm - the emitted SauceScript text is byte-
identical for `"evm"`/`"v1"`/`"v12"` (only `compile()`'s own `target` option, not this module,
decides which Huff runtime the text lowers against). `"svm"` selects the SPL Token arm.

```typescript theme={null}
export type TokenTarget = "evm" | "v1" | "v12" | "svm";
```

### `token.TokenOp`

*Type* · `sdk/dist/token/types.d.ts`

```typescript theme={null}
export type TokenOp = "transfer" | "approve" | "balanceOf";
```

### `token.SPL_TRANSFER_CHECKED`

*Variable* · `sdk/dist/token/types.d.ts`

SPL Token TransferChecked instruction discriminant.

```typescript theme={null}
SPL_TRANSFER_CHECKED = 12
```

### `token.SPL_APPROVE_CHECKED`

*Variable* · `sdk/dist/token/types.d.ts`

SPL Token ApproveChecked instruction discriminant.

```typescript theme={null}
SPL_APPROVE_CHECKED = 13
```

### `token.SPL_AMOUNT_OFFSET`

*Variable* · `sdk/dist/token/types.d.ts`

Offset of the SPL token account's u64 `amount` field (identical in classic SPL + Token-2022).

```typescript theme={null}
SPL_AMOUNT_OFFSET = 64
```

### `token.MINT_DECIMALS_OFFSET`

*Variable* · `sdk/dist/token/types.d.ts`

Offset of the mint's `decimals` byte (identical in the first 82 bytes of both programs' mints).

```typescript theme={null}
MINT_DECIMALS_OFFSET = 44
```

### `token.SvmTokenRefs`

*Interface* · `sdk/dist/token/types.d.ts`

SVM account refs a token op needs, as caller-named strings resolved at EXECUTION time (the same
contract `svmSettleRefs` establishes) - never resolved addresses baked into the source. Defaults
cover the common single-op case; a multi-op program must pass distinct names per op.

```typescript theme={null}
export interface SvmTokenRefs {
    source: string;
    mint?: string;
    dest?: string;
    delegate?: string;
    owner?: string;
    tokenProgram?: string;
}
```

### `token.SvmTokenProgramInput`

*Type* · `sdk/dist/token/types.d.ts`

The SVM CPI target VALUE - a well-known program id by name, or a raw pubkey as a bigint. Always a
LITERAL: every account identity a program touches is an attach slot, so a caller-supplied identity
belongs in `SvmTokenRefs.tokenProgram` (the ref this value is pinned against), never in the value.

```typescript theme={null}
export type SvmTokenProgramInput = "spl" | "token-2022" | bigint;
```

### `token.TokenTransferSpec`

*Interface* · `sdk/dist/token/types.d.ts`

```typescript theme={null}
export interface TokenTransferSpec {
    token?: AddressInput;
    to?: AddressInput;
    amount: bigint | number | "balance";
    svm?: SvmTokenRefs;
    tokenProgram?: SvmTokenProgramInput;
}
```

### `token.TokenApproveSpec`

*Interface* · `sdk/dist/token/types.d.ts`

```typescript theme={null}
export interface TokenApproveSpec {
    token?: AddressInput;
    spender?: AddressInput;
    amount: bigint | number | "balance";
    svm?: SvmTokenRefs;
    tokenProgram?: SvmTokenProgramInput;
}
```

### `token.TokenBalanceSpec`

*Interface* · `sdk/dist/token/types.d.ts`

```typescript theme={null}
export interface TokenBalanceSpec {
    token?: AddressInput;
    owner?: AddressInput | "self";
    svm?: Pick<SvmTokenRefs, "source">;
}
```

### `token.TokenSpec`

*Type* · `sdk/dist/token/types.d.ts`

```typescript theme={null}
export type TokenSpec = ({
    op: "transfer";
} & TokenTransferSpec) | ({
    op: "approve";
} & TokenApproveSpec) | ({
    op: "balanceOf";
} & TokenBalanceSpec);
```

### `token.isEvmTarget`

*Function* · `sdk/dist/token/params.d.ts`

```typescript theme={null}
export declare function isEvmTarget(target: TokenTarget): boolean;
```

### `token.toAddressBigint`

*Function* · `sdk/dist/token/params.d.ts`

```typescript theme={null}
export declare function toAddressBigint(value: AddressInput, _label: string): bigint;
```

### `token.assertU64Range`

*Function* · `sdk/dist/token/params.d.ts`

Any literal (non-`"balance"`) amount destined for SVM must fit the SPL u64 `amount` field.

```typescript theme={null}
export declare function assertU64Range(amount: bigint, label: string): void;
```

### `token.toAmountBigint`

*Function* · `sdk/dist/token/params.d.ts`

```typescript theme={null}
export declare function toAmountBigint(amount: bigint | number, label: string): bigint;
```

### `token.ownerRef`

*Function* · `sdk/dist/token/params.d.ts`

`owner`/`tokenProgram` default names - shared/reused across ops in one program by design (the
SPL CPI-target intern is meant to dedupe across ops, unlike per-op instance refs).

```typescript theme={null}
export declare function ownerRef(refs: SvmTokenRefs): string;
```

### `token.tokenProgramRef`

*Function* · `sdk/dist/token/params.d.ts`

```typescript theme={null}
export declare function tokenProgramRef(refs: SvmTokenRefs): string;
```

### `token.validateTransferSpec`

*Function* · `sdk/dist/token/params.d.ts`

```typescript theme={null}
export declare function validateTransferSpec(spec: TokenTransferSpec, target: TokenTarget): void;
```

### `token.validateApproveSpec`

*Function* · `sdk/dist/token/params.d.ts`

```typescript theme={null}
export declare function validateApproveSpec(spec: TokenApproveSpec, target: TokenTarget): void;
```

### `token.validateBalanceSpec`

*Function* · `sdk/dist/token/params.d.ts`

```typescript theme={null}
export declare function validateBalanceSpec(spec: TokenBalanceSpec, target: TokenTarget): void;
```

### `token.assertNoDuplicateSvmRefs`

*Function* · `sdk/dist/token/params.d.ts`

Rejects a duplicate SVM instance ref name across DIFFERENT ops in one `Token.program(...)` call - a collision would silently merge two distinct AccountPlan slots. `owner`/`tokenProgram` are
exempt (shared by design).

```typescript theme={null}
export declare function assertNoDuplicateSvmRefs(specs: readonly TokenSpec[]): void;
```

### `token.tokenImportLines`

*Function* · `sdk/dist/token/source.d.ts`

The import lines a `tokenSource(specs, target)` program needs. On an EVM target: `IERC20`, iff
any spec is `transfer`/`approve`/`balanceOf` (always - every op needs the binding). On `svm`:
none (SVM ops use only the built-in `svm.sload`/`svm.call` globals).

```typescript theme={null}
export declare function tokenImportLines(specs: readonly TokenSpec[], target: TokenTarget): readonly string[];
```

### `token.tokenCallStatement`

*Function* · `sdk/dist/token/source.d.ts`

One statement (transfer/approve) or `undefined` (balanceOf has no statement form - see
`tokenExpression`) for `spec` on `target`, for splicing into a larger, hand-written
program. Runs the full per-op/per-target validation. `svmState` threads dedup across multiple
ops in one program (`tokenSource`'s own concern) - omit it to get a fresh, single-op program.

```typescript theme={null}
export declare function tokenCallStatement(spec: TokenSpec, target: TokenTarget, index?: number, svmState?: SvmEmitState): string;
```

### `token.tokenExpression`

*Function* · `sdk/dist/token/source.d.ts`

The expression form of `Token.balanceOf(spec)` - the only op with one. Throws (named) for
`transfer`/`approve`, which have no meaningful expression form.

```typescript theme={null}
export declare function tokenExpression(spec: TokenSpec, target: TokenTarget): string;
```

### `token.tokenAccountRefs`

*Function* · `sdk/dist/token/source.d.ts`

The account-manifest refs a `transfer`/`approve` spec attaches, in order - mirrors
`svmSettleRefs`. Throws for `balanceOf` (a pure read; its only ref is the caller-supplied
`source`) and for an EVM-target spec (no account manifest on that target).

```typescript theme={null}
export declare function tokenAccountRefs(spec: TokenSpec, target: TokenTarget): readonly string[];
```

### `token.tokenSource`

*Function* · `sdk/dist/token/source.d.ts`

A complete, compilable `function main() { ... }` program: one statement per `transfer`/`approve`
spec (in order), plus, if the LAST spec is a `balanceOf`, a trailing `return <expr>;` - because
`Token.program`'s only consumer (`V12Pot.cook`) executes the one program it is handed and wants
its result, if any, as the return value. A `balanceOf` in any OTHER position is spliced as a discarded
expression statement.

```typescript theme={null}
export declare function tokenSource(spec: TokenSpec | readonly TokenSpec[], target: TokenTarget, opts?: TokenSourceOptions): string;
```

### `token.TOKEN_BASE_DIRS`

*Variable* · `sdk/dist/token/source.d.ts`

`baseDirs` for compiling any program `tokenSource`/`tokenCallStatement` produces - resolves the
generated `import { IERC20 } from "./artifacts/IERC20.json"` against this installed package's
dist root. Same value/pattern as `swap/source.ts`'s `SWAP_BASE_DIRS`.

```typescript theme={null}
TOKEN_BASE_DIRS: readonly string[]
```

### `token.TokenSourceOptions`

*Interface* · `sdk/dist/token/source.d.ts`

```typescript theme={null}
export interface TokenSourceOptions {
    functionName?: string;
    imports?: readonly string[];
}
```
