diff --git a/content/tutorials/build-with-ai/agent-wallets.mdx b/content/tutorials/build-with-ai/agent-wallets.mdx index b2e03edad..0ce9fe449 100644 --- a/content/tutorials/build-with-ai/agent-wallets.mdx +++ b/content/tutorials/build-with-ai/agent-wallets.mdx @@ -1,43 +1,277 @@ --- title: Agent Wallets -description: Give your AI agent a secure wallet it can use from the Alchemy CLI without exposing private keys. -subtitle: Wallets that allow your agent to send tokens, swap, bridge, call contracts and check transaction status. +description: Give an agent an approved Alchemy wallet session for onchain actions through the Alchemy CLI. +subtitle: Use Agent Wallets to send tokens, call contracts, swap, bridge, sponsor gas, and check status from the Alchemy CLI. slug: docs/agent-wallets --- -Agent Wallets give your AI agent a real onchain wallet it can use with the [Alchemy CLI](docs/alchemy-cli) to perform onchain actions. +Agent Wallets give an agent an approved CLI session for onchain actions. The agent can use wallet-aware Alchemy CLI commands, but it does not receive or handle the wallet private key. -Built with Privy embedded wallets, your agent will never see the wallet's private key. You approve wallet access, and you can revoke it at any time. +The session is approved in the Alchemy Dashboard, expires automatically, and can be revoked from the Dashboard or with `alchemy wallet disconnect`. -## Get Started - -Paste this prompt into your AI agent: - -```bash -Install the latest Alchemy CLI with `npm i -g @alchemy/cli@latest`, then help me log in and create a wallet. -``` - -Your agent installs the CLI, authenticates, and connects an Agent Wallet. - -## Use cases +## Capabilities - - Check balances, quote and execute swaps, bridge to another chain, and deposit into a protocol — all in a single agent workflow. + + Send native tokens or ERC-20s, execute contract calls, manage ERC-20 approvals, + swap on EVM mainnets, and bridge between EVM mainnets. - - Fund test wallets, deploy contracts, call contract methods, and automate repetitive dev tasks without leaving the CLI. + + Send SOL or SPL tokens, run dry runs, handle associated token accounts, and use + session signing for supported CLI flows. - - Send payments, move assets between wallets, and rebalance across chains as part of operational or finance workflows. + + Request EVM gas sponsorship or Solana fee sponsorship with a policy ID. - - Bridge assets to where they're needed, then act — swap, deposit, or call contracts on the destination chain. + + Approve sessions in the Dashboard, inspect the active session, and revoke + access from the CLI or Dashboard. + + + **Chains:** EVM wallet operations run on supported Alchemy wallet networks. + Solana sends run on supported Solana networks. Swaps and bridges are EVM + mainnet-only. + + **EVM sends:** `alchemy evm send` supports native token and ERC-20 sends. ENS + recipients work where the selected network/client can resolve them. + + **Contract writes:** `alchemy evm contract call` supports state-changing EVM + calls with inline signatures, ABI files, JSON args, and optional ETH value. + + **Approvals:** `alchemy evm approve` supports ERC-20 approve, reset, and + revoke flows. Unlimited approvals require confirmation or `--yes`. + + **Swaps:** `alchemy evm swap quote` and `alchemy evm swap execute` support + same-chain EVM mainnet swaps with slippage controls. + + **Bridges:** `alchemy xchain bridge quote` and `alchemy xchain bridge execute` + support EVM mainnet bridges from `-n, --network` to `--to-network`. + + **Status:** `alchemy evm status` checks smart-wallet call IDs and EVM + transaction hashes. `alchemy solana status` checks Solana signatures. + + + A session can include `evm.signMessage`, `evm.signTypedData`, + `evm.signAuthorization`, `evm.prepareCalls`, `evm.sendCalls`, and + `solana.signTransaction`. + + The session signer does not support direct raw EVM transaction signing. Use + CLI commands that execute through Alchemy smart-wallet calls. + + Gas and fee sponsorship policies control transaction fees. They are not + wallet spend limits. + + + Use these commands when an agent needs the current wallet contract: + + ```bash + alchemy --json --no-interactive wallet status --verify + alchemy --json --no-interactive agent-prompt --scope wallet + alchemy evm network list + alchemy solana network list + ``` + + For the latest published CLI surface, use: + + ```bash + npx -y @alchemy/cli@latest --json --no-interactive agent-prompt --scope wallet + ``` + + + +## Connect a session + +Install the CLI, log in, and start a Dashboard approval flow: + +```bash +npm i -g @alchemy/cli@latest +alchemy auth +alchemy wallet connect --mode session --instance-name codex-terminal +``` + +Verify the approved session before running a state-changing workflow: + +```bash +alchemy --json --no-interactive wallet status --verify +``` + +The response includes the active signer, session expiry, chain-specific session metadata, backend status, and enabled signer capabilities. + +## Examples + + + + This workflow assumes you already approved a session. It checks funding, + previews a send, broadcasts it, and checks status. + + ```bash + alchemy --json --no-interactive wallet address + alchemy --json --no-interactive evm data balance -n base-mainnet + + alchemy --json --no-interactive evm send 0.001 \ + -n base-mainnet \ + --dry-run + + alchemy --json --no-interactive evm send 0.001 \ + -n base-mainnet + + alchemy --json --no-interactive evm status -n base-mainnet + ``` + + For sponsored gas, pass a Gas Manager policy: + + ```bash + alchemy --json --no-interactive evm send 0.001 \ + -n base-mainnet \ + --gas-sponsored \ + --gas-policy-id + ``` + + + + This workflow assumes you already approved a session. It checks funding, + previews a send, broadcasts it, and checks status. + + ```bash + alchemy --json --no-interactive wallet address + alchemy --json --no-interactive solana rpc getBalance -n solana-mainnet + + alchemy --json --no-interactive solana send 0.01 \ + -n solana-mainnet \ + --dry-run + + alchemy --json --no-interactive solana send 0.01 \ + -n solana-mainnet + + alchemy --json --no-interactive solana status -n solana-mainnet + ``` + + For sponsored fees, pass a Solana fee policy: + + ```bash + alchemy --json --no-interactive solana send 0.01 \ + -n solana-mainnet \ + --fee-sponsored \ + --fee-policy-id + ``` + + Add `--token ` for SPL tokens. + + + +Run `alchemy --json --no-interactive wallet disconnect` when the session is no longer needed. + +## Machine-readable contract + +Use the live CLI output as the source of truth for agents and skills: + +```bash +npx -y @alchemy/cli@latest --json --no-interactive agent-prompt --scope wallet +``` + +Use the installed CLI when the agent needs to inspect the current machine's configured wallet: + +```bash +alchemy --json --no-interactive agent-prompt --scope wallet +alchemy --json --no-interactive wallet status --verify +``` + + + Include this in an agent skill or system prompt when the agent cannot call + `agent-prompt` at runtime. + + ```json + { + "alchemyAgentWallets": { + "sourceOfTruth": { + "latestCli": "npx -y @alchemy/cli@latest --json --no-interactive agent-prompt --scope wallet", + "installedCli": "alchemy --json --no-interactive agent-prompt --scope wallet", + "sessionStatus": "alchemy --json --no-interactive wallet status --verify" + }, + "session": { + "approval": "dashboard", + "privateKeyExposure": "never_exposed_to_agent", + "revocation": ["alchemy wallet disconnect", "dashboard"], + "expiryField": "expiresAt", + "capabilities": [ + "evm.signMessage", + "evm.signTypedData", + "evm.signAuthorization", + "evm.prepareCalls", + "evm.sendCalls", + "solana.signTransaction" + ] + }, + "evm": { + "operations": [ + "native_send", + "erc20_send", + "contract_call", + "erc20_approve_reset_revoke", + "swap_quote", + "swap_execute", + "bridge_quote", + "bridge_execute", + "status" + ], + "sponsorshipFlags": ["--gas-sponsored", "--gas-policy-id "], + "directRawTransactionSigning": false, + "limits": ["swaps_evm_mainnet_only", "bridges_evm_mainnet_only"] + }, + "solana": { + "operations": ["sol_send", "spl_token_send", "status"], + "sponsorshipFlags": ["--fee-sponsored", "--fee-policy-id "] + }, + "agentRules": [ + "Use --json --no-interactive in automation.", + "Run wallet status --verify before state-changing wallet actions.", + "Run balance, allowance, or quote checks before spending.", + "Use --dry-run where available before broadcast.", + "Treat sponsorship policies as fee controls, not wallet spend limits.", + "Disconnect or revoke the session after the workflow." + ] + } + } + ``` + + +## Operational details + + + + Use the [Agent Wallets dashboard](https://dashboard.alchemy.com/products/agent-wallet/evm-wallet) + to create wallets, approve terminal sessions, fund wallets through onramps, + send from the wallet, and revoke sessions. + + + EVM session actions execute through Alchemy smart-wallet calls such as + `wallet_prepareCalls` and `wallet_sendCalls`. The CLI uses those calls for + nonce handling, preflight behavior, call IDs, status polling, batch-call + support where the command uses it, and optional paymaster capabilities. + + Solana session actions sign transactions for supported CLI flows such as SOL + and SPL token sends. + + + Use a local wallet only when you intentionally want local key material: + + ```bash + alchemy wallet connect --mode local + alchemy wallet connect --mode local --import ./evm-private-key.txt + alchemy wallet use local + ``` + + If both a session signer and a local EVM signer are configured, the CLI + defaults to the session signer and prints a warning. + + + ## Next steps * [Alchemy CLI](docs/alchemy-cli) * [Alchemy CLI wallets and signing](docs/alchemy-cli#wallets-and-signing) +* [Alchemy Agent Skills](docs/alchemy-agent-skills) * [Alchemy Dashboard Agent Wallets](https://dashboard.alchemy.com/products/agent-wallet/evm-wallet) diff --git a/content/tutorials/build-with-ai/alchemy-cli.mdx b/content/tutorials/build-with-ai/alchemy-cli.mdx index 697cfa882..140bcf1c7 100644 --- a/content/tutorials/build-with-ai/alchemy-cli.mdx +++ b/content/tutorials/build-with-ai/alchemy-cli.mdx @@ -188,15 +188,15 @@ Most wallet-signed EVM commands accept `--signer session|local` to override the ### Wallets and signing -Use `alchemy wallet` to connect the signer used by onchain actions. EVM commands can use an [Agent Wallet session](docs/agent-wallets) approved through the Alchemy Dashboard or a local private key. The `session` signer refers to an Agent Wallet session, not an arbitrary browser wallet connection. Solana transaction commands currently use a local Solana wallet. +Use `alchemy wallet` to connect the signer used by onchain actions. EVM commands can use an [Agent Wallet session](docs/agent-wallets) approved through the Alchemy Dashboard or a local private key. Solana send commands can use an Agent Wallet session or a local Solana wallet. The `session` signer refers to an Agent Wallet session, not an arbitrary browser wallet connection. Create, view, and revoke Agent Wallet sessions in the [Agent Wallets dashboard](https://dashboard.alchemy.com/products/agent-wallet/evm-wallet). | Command | Description | |---|---| -| `alchemy wallet connect` | Connect a wallet. Use `--mode session` for an Agent Wallet session or `--mode local` for a local wallet. Local mode supports `--chain evm\|solana\|both` and defaults to both. | -| `alchemy wallet connect --mode local --chain evm --import ` | Import a local EVM private key file | -| `alchemy wallet connect --mode local --chain solana` | Create or configure a local Solana wallet | +| `alchemy wallet connect` | Connect a wallet. Use `--mode session` for an Agent Wallet session or `--mode local` for local wallets. Session mode requests EVM and Solana capabilities. Local mode creates both EVM and Solana wallets. | +| `alchemy wallet connect --mode session --instance-name ` | Name the CLI instance shown during Dashboard approval | +| `alchemy wallet connect --mode local --import ` | Import a local EVM private key file | | `alchemy wallet status` | Show Agent Wallet session, local EVM, local Solana, and active signer status. Add `--verify` to check the backend session. | | `alchemy wallet address` | Display configured wallet addresses | | `alchemy wallet qr` | Display an EVM or Solana wallet address as a QR code | @@ -205,17 +205,17 @@ Create, view, and revoke Agent Wallet sessions in the [Agent Wallets dashboard]( ### Solana -Solana transaction commands use a local Solana wallet. Use `--fee-sponsored` and `--fee-policy-id ` on supported Solana actions to request fee sponsorship. +Solana send commands can use an Agent Wallet session or a local Solana wallet. Use `--fee-sponsored` and `--fee-policy-id ` on supported Solana actions to request fee sponsorship. ```bash -alchemy wallet connect --mode local --chain solana +alchemy wallet connect --mode session alchemy solana send 0.1 -n solana-mainnet alchemy solana status ``` | Command | Description | |---|---| -| `alchemy solana send ` | Send native SOL. SPL token transfers are not yet supported. | +| `alchemy solana send ` | Send native SOL. Add `--token ` for SPL token transfers. | | `alchemy solana delegate approve --token-account --mint --delegate --amount --decimals ` | Approve an SPL token delegate | | `alchemy solana delegate revoke --token-account ` | Revoke an SPL token delegate | | `alchemy solana status [id]` | Check a Solana transaction signature; reads from stdin when omitted |