Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions typescript/.changeset/privy-evm-embedded-wallet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@coinbase/agentkit": minor
---

Added support for Privy Evm embedded wallets with delegation. (Thanks @njokuScript!)

This change introduces a new wallet provider, `PrivyEvmDelegatedEmbeddedWalletProvider`, which allows AgentKit to use Privy's embedded wallets that have been delegated to a server. This enables autonomous agents to perform onchain actions on behalf of users who have delegated transaction signing authority to the agent.

Key changes:
- Add `PrivyEvmDelegatedEmbeddedWalletProvider` class extending the `EvmWalletProvider` base class
- Update the `PrivyWalletProvider` factory to support embedded wallets via a new `walletType` option
58 changes: 51 additions & 7 deletions typescript/agentkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -646,24 +646,61 @@ const walletProvider = new ViemWalletProvider(client, {

### PrivyWalletProvider

The `PrivyWalletProvider` is a wallet provider that uses [Privy Server Wallets](https://docs.privy.io/guide/server-wallets/). This implementation extends the `ViemWalletProvider`.
The `PrivyWalletProvider` is a wallet provider that uses [Privy Server Wallets](https://docs.privy.io/guide/server-wallets/) or [Privy Embedded Wallets](https://docs.privy.io/guide/embedded-wallets/). This implementation extends the `EvmWalletProvider`.

#### Server Wallet Configuration

```typescript
import { PrivyWalletProvider, PrivyWalletConfig } from "@coinbase/agentkit";
import { PrivyWalletProvider } from "@coinbase/agentkit";

// Configure Wallet Provider
const config: PrivyWalletConfig = {
// Configure Server Wallet Provider
const config = {
appId: "PRIVY_APP_ID",
appSecret: "PRIVY_APP_SECRET",
chainId: "84532", // base-sepolia
walletId: "PRIVY_WALLET_ID", // optional, otherwise a new wallet will be created
authorizationPrivateKey: PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY, // optional, required if your account is using authorization keys
authorizationKeyId: PRIVY_WALLET_AUTHORIZATION_KEY_ID, // optional, only required to create a new wallet if walletId is not provided
authorizationPrivateKey: "PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY", // optional, required if your account is using authorization keys
authorizationKeyId: "PRIVY_WALLET_AUTHORIZATION_KEY_ID", // optional, only required to create a new wallet if walletId is not provided
};

const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
```

#### Delegated Embedded Wallet Configuration

You can also use Privy's embedded wallets with delegation for agent actions. This allows your agent to use wallets that have been delegated transaction signing authority by users.

```typescript
import { PrivyWalletProvider } from "@coinbase/agentkit";

// Configure Embedded Wallet Provider
const config = {
appId: "PRIVY_APP_ID",
appSecret: "PRIVY_APP_SECRET",
authorizationPrivateKey: "PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY",
walletId: "PRIVY_DELEGATED_WALLET_ID", // The ID of the wallet that was delegated to your server
networkId: "base-mainnet", // or any supported network
walletType: "embedded" // Specify "embedded" to use the embedded wallet provider
};

const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
```

### Prerequisites

Before using this wallet provider, you need to:

1. Set up Privy in your application
2. Enable server delegated actions
3. Have users delegate permissions to your server
4. Obtain the delegated wallet ID

For more information on setting up Privy and enabling delegated actions, see [Privy's documentation](https://docs.privy.io/guide/embedded/server-delegated-actions).

### Supported Operations

The `PrivyEvmDelegatedEmbeddedWalletProvider` supports all standard wallet operations including transaction signing, message signing, and native transfers, using the wallet that was delegated to your server.

#### Authorization Keys

Privy offers the option to use authorization keys to secure your server wallets.
Expand All @@ -679,12 +716,19 @@ The `PrivyWalletProvider` can export wallet information by calling the `exportWa
```typescript
const walletData = await walletProvider.exportWallet();

// walletData will be in the following format:
// For server wallets, walletData will be in the following format:
{
walletId: string;
authorizationKey: string | undefined;
chainId: string | undefined;
}

// For embedded wallets, walletData will be in the following format:
{
walletId: string;
networkId: string;
chainId: string | undefined;
}
```

### SmartWalletProvider
Expand Down
1 change: 1 addition & 0 deletions typescript/agentkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@solana/spl-token": "^0.4.12",
"@solana/web3.js": "^1.98.0",
"bs58": "^4.0.1",
"canonicalize": "^2.1.0",
"decimal.js": "^10.5.0",
"ethers": "^6.13.5",
"md5": "^2.3.0",
Expand Down
1 change: 1 addition & 0 deletions typescript/agentkit/src/wallet-providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from "./solanaKeypairWalletProvider";
export * from "./privyWalletProvider";
export * from "./privyEvmWalletProvider";
export * from "./privySvmWalletProvider";
export * from "./privyEvmDelegatedEmbeddedWalletProvider";
Loading