# usePeltier Hook

For advanced integrations where you need direct access to the peltier context without using the pre-built widget. Returns the API URL, the publishable key, and the implementation address from the nearest `PeltierProvider`.

```typescript
// usePeltier.ts
import { usePeltier } from '@peltier/react'

function CustomDeposit() {
  const { apiUrl, implementationAddress } = usePeltier()

  // Use apiUrl to call session endpoints directly
  // Use implementationAddress for EIP-7702 authorization

  const createSession = async () => {
    const res = await fetch(`${apiUrl}/sessions`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        burner_address: burnerAddress,
        eip7702_auth: signedAuth,
        destination_address: destAddress,
        destination_chain: 8453,
      }),
    })
    return res.json()
  }

  // ...
}
```

## Return Value

| Field | Type | Description |
| --- | --- | --- |
| `apiUrl` | string | Backend API base URL from the provider |
| `publishableKey` | string | Merchant publishable key from the provider (`pk_test_…` / `pk_live_…`); its prefix encodes the environment |
| `implementationAddress` | `` `0x${string}` `` | PeltierDelegate contract address for EIP-7702 auth signing (the provider's default) |

## EIP-7702 Authorization

When building a custom integration, you need to generate the EIP-7702 authorization yourself. The authorization delegates the burner EOA's code to the PeltierDelegate contract, allowing the relayer to call `execute()` on the burner as if it were the contract.

```typescript
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'

const privateKey = generatePrivateKey()
const burner = privateKeyToAccount(privateKey)

// chainId: 0 means valid on ALL chains
const auth = await burner.signAuthorization({
  contractAddress: implementationAddress,
  chainId: 0,  // wildcard -- works on any chain
  nonce: 0,
})

// auth = { address, chainId, nonce, r, s, yParity }
```

Setting `chainId: 0` is critical. It means the user's single signature authorizes sweep execution on *any* supported chain, so regardless of which chain they deposit on, the relayer can act.
