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

# Smart Accounts

> Smart accounts, ZeroDev, session keys, and gas management

## What are Smart Accounts?

Smart accounts are **smart contract wallets** with gasless transactions, session keys, and programmable permissions. In Giza, every user gets a smart account -- this is the deposit address for agent-managed funds.

Unlike regular wallets (EOAs - Externally Owned Accounts), smart accounts:

* Are smart contracts, not just private key pairs
* Can execute logic and have programmable rules
* Enable gasless transactions through paymasters
* Support session keys for delegated permissions
* Can batch multiple transactions together

## Architecture

```mermaid theme={null}
graph LR
    A[User's Origin Wallet<br/>EOA or Smart Wallet] -->|controls| B[Smart Account<br/>Contract]
    B -->|grants| C[Session Keys]
    C -->|used by| D[Giza Agent]
    D -->|executes| E[DeFi Protocols]
```

## ZeroDev Integration

Giza smart accounts are powered by **[ZeroDev](https://zerodev.app/)**, an account abstraction infrastructure provider.

<AccordionGroup>
  <Accordion title="ERC-4337 Compliant">
    Follows the official Ethereum account abstraction standard for maximum compatibility and security.
  </Accordion>

  <Accordion title="Production-Proven">
    Widely deployed across many applications and managing significant assets on-chain.
  </Accordion>

  <Accordion title="Gasless Transactions">
    Agents can execute rebalancing without users paying gas for each transaction.
  </Accordion>

  <Accordion title="Session Keys">
    Time-bound delegated permissions that work well for autonomous agents.
  </Accordion>
</AccordionGroup>

## Deterministic Addresses

Smart accounts are **deterministic** - the same origin wallet always generates the same smart account address.

This means:

* Safe to call `giza.createAgent(eoa)` multiple times
* Users get the same address across sessions
* No risk of losing funds to a "new" address

<Card title="API Reference" icon="code" href="/sdk-reference/agent/overview">
  See createAgent() for implementation details
</Card>

## Smart Account Lifecycle

```mermaid theme={null}
graph TD
    A[Origin Wallet] -->|giza.createAgent| B[Smart Account Created]
    B -->|User deposits| C[Smart Account Funded]
    C -->|agent.activate| D[Session Keys Granted]
    D -->|Agent manages| E[Active Optimization]
    E -->|agent.withdraw / agent.deactivate| F[Session Keys Revoked]
    F -->|re-activate| D
```

### States

1. **Created**: Smart account exists on-chain but empty
2. **Funded**: User has deposited tokens
3. **Active**: Agent has session key permissions, actively managing
4. **Deactivated**: Permissions revoked, agent no longer managing

## Backend Wallet

The `backendWallet` is a Giza-controlled wallet that:

* Holds session keys to execute transactions
* Acts on behalf of the smart account (with limited permissions)
* Pays gas fees for agent operations
* Is revocable at any time by the user

<Note>
  The backend wallet never controls user funds directly.
  It only has permission to call specific functions on specific contracts.
</Note>

## Session Keys & Permissions

When an agent is activated, the smart account grants **session keys** to the backend wallet with specific permissions:

### Permission Structure

| Permission Type    | Description                                        |
| ------------------ | -------------------------------------------------- |
| Approved Targets   | Specific protocol contracts (Aave, Compound, etc.) |
| Approved Functions | supply, withdraw, transfer, etc.                   |
| Transaction Limits | Max amounts per transaction                        |

### Security Guarantees

<AccordionGroup>
  <Accordion title="Limited Scope">
    Session keys can ONLY:

    * Call approved protocol contracts
    * Execute approved functions (deposit, withdraw, swap)
    * Within approved time windows
    * Up to specified limits
  </Accordion>

  <Accordion title="Revocable">
    Users can deactivate agents at any time, immediately revoking all session key permissions.
  </Accordion>

  <Accordion title="Non-Custodial">
    Users always retain ultimate control via their origin wallet. Giza never has custody of funds.
  </Accordion>
</AccordionGroup>

## Gas Management

Smart accounts give users **gasless transactions**:

```mermaid theme={null}
graph LR
    A[Agent Decides to Rebalance] --> B[Backend Wallet Signs Tx]
    B --> C[Paymaster Pays Gas]
    C --> D[Smart Account Executes]
    D --> E[Protocol Interaction]

    F[User] -.pays nothing.-> D
```

How it works:

1. Agent determines optimal rebalancing is needed
2. Backend wallet crafts and signs the transaction
3. Giza's paymaster sponsors the gas fee
4. Smart account executes the transaction
5. User pays nothing for the rebalancing operation

Gas costs are:

* Covered by Giza during active management
* Factored into the performance fee structure
* Optimized through transaction batching

## Troubleshooting

<AccordionGroup>
  <Accordion title="Smart account creation fails">
    Check:

    * Origin wallet is a valid Ethereum address (0x + 40 hex chars)
    * Chain is supported
    * API credentials are correct
  </Accordion>

  <Accordion title="Can't find existing smart account">
    Make sure:

    * You're using the same EOA as when it was created
    * You're querying the correct chain
    * The smart account was actually created (check blockchain explorer)
  </Accordion>

  <Accordion title="Deposits not showing up">
    Verify:

    * Transaction was sent to correct `smartAccountAddress`
    * Transaction confirmed on-chain (check explorer)
    * You're checking the right chain
    * Agent was activated after deposit
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Architecture Overview" icon="building" href="/developers/architecture/overview">
    Agent lifecycle and system components
  </Card>

  <Card title="SDK Reference" icon="code" href="/sdk-reference/agent/overview">
    Complete smart account API documentation
  </Card>

  <Card title="Quickstart" icon="rocket" href="/developers/quickstart">
    Full integration tutorial
  </Card>

  <Card title="Troubleshooting" icon="wrench" href="/developers/troubleshooting">
    Common issues and solutions
  </Card>
</CardGroup>
