Skip to content

Add support for Privy embedded wallets with delegation - #583

Merged
CarsonRoscoe merged 21 commits into
coinbase:feat/privy-evm-delegated-embedded-wallet-providerfrom
ultra-co:njoku/feat-privy-delegated-wallet
Mar 27, 2025
Merged

Add support for Privy embedded wallets with delegation#583
CarsonRoscoe merged 21 commits into
coinbase:feat/privy-evm-delegated-embedded-wallet-providerfrom
ultra-co:njoku/feat-privy-delegated-wallet

Conversation

@njokuScript

@njokuScript njokuScript commented Mar 17, 2025

Copy link
Copy Markdown
Contributor

Add support for Privy embedded wallets with delegation

Description

This PR adds support for Privy's embedded wallets with delegation to AgentKit. It introduces a new wallet provider, PrivyEvmEmbeddedWalletProvider, that allows AgentKit to use wallets which have been delegated transaction signing authority through Privy's embedded wallet system. This enables autonomous agents to perform onchain actions on behalf of users.

The implementation:

  • Creates a new PrivyEvmEmbeddedWalletProvider class that extends EvmWalletProvider
  • Updates the PrivyWalletProvider factory to support embedded wallets via a new walletType option
  • Adds comprehensive test coverage for the new provider
  • Updates documentation on how to use the embedded wallet provider

Currently our UI uses Privy's embedded wallet for delegation to agents, but Coinbase's agent kit only supports Privy's server wallet. This change makes the two systems compatible, allowing agents to properly execute transactions with delegated embedded wallets.

Tests

Current network: { protocolFamily: 'evm', networkId: 'base', chainId: '8453' }
Agent initialized with wallet address: 0xc0A6A6D543Bdcf2fa4f4e390154F124A0B289969
Starting chat mode... Type 'exit' to end.

Prompt: send $2 worth of eth to 0xa0680AcC8F180d18441914eE0510996234B66259

-------------------
Wallet Details:
- Provider: privy_evm_embedded_wallet_provider
- Address: 0xc0A6A6D543Bdcf2fa4f4e390154F124A0B289969
- Network:
  * Protocol Family: evm
  * Network ID: base
  * Chain ID: 8453
- Native Balance: 22805689068594859 WEI
-------------------
Your wallet has a native balance of approximately 0.0228 ETH (22,805,689,068,594,859 WEI), which is more than enough to cover a $2 transfer.

However, I need to convert $2 to ETH based on the current ETH price. Let's fetch the latest price of ETH before proceeding with the transaction. 

I'll fetch the price now.
-------------------
ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace
-------------------

-------------------
2046.31
-------------------

-------------------
Transferred 0.0000097 ETH to 0xa0680AcC8F180d18441914eE0510996234B66259
Transaction hash: 0xf92ce2c753b964edf46807979d8602c21f6e6188e38ec6e3c00e9d9ccdfd8b78
-------------------
I have successfully transferred approximately $2 worth of ETH (0.0000097 ETH) to the address **0xa0680AcC8F180d18441914eE0510996234B66259**. The transaction hash is **0xf92ce2c753b964edf46807979d8602c21f6e6188e38ec6e3c00e9d9ccdfd8b78**.
-------------------

Checklist

  • Added documentation to the PrivyWalletProvider section in README.md
  • Added a changelog entry in .changeset/privy-embedded-wallet.md

@cb-heimdall

cb-heimdall commented Mar 17, 2025

Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@github-actions github-actions Bot added documentation Improvements or additions to documentation wallet provider New wallet provider typescript labels Mar 17, 2025
@github-actions github-actions Bot added the example New example agent label Mar 19, 2025
@njokuScript
njokuScript marked this pull request as ready for review March 19, 2025 00:08
Comment thread typescript/examples/langchain-privy-delegated-chatbot/chatbot.ts Outdated
Comment thread typescript/agentkit/src/wallet-providers/privyEvmEmbeddedWalletProvider.ts Outdated
Comment thread typescript/agentkit/src/wallet-providers/privyEvmEmbeddedWalletProvider.ts Outdated
Comment thread typescript/agentkit/src/wallet-providers/privyEvmEmbeddedWalletProvider.ts Outdated
Comment thread typescript/agentkit/src/wallet-providers/privyEvmEmbeddedWalletProvider.ts Outdated
Comment thread typescript/agentkit/src/wallet-providers/privyEvmEmbeddedWalletProvider.ts Outdated
Comment thread typescript/agentkit/src/wallet-providers/privyEvmEmbeddedWalletProvider.ts Outdated
Comment thread typescript/agentkit/src/wallet-providers/privyEvmEmbeddedWalletProvider.ts Outdated
Comment thread typescript/agentkit/src/wallet-providers/privyEvmEmbeddedWalletProvider.ts Outdated
Comment thread typescript/agentkit/src/wallet-providers/privyEvmEmbeddedWalletProvider.ts Outdated
Comment thread typescript/agentkit/src/wallet-providers/privyWalletProvider.ts Outdated
Comment thread typescript/examples/langchain-privy-delegated-chatbot/README.md Outdated

@CarsonRoscoe CarsonRoscoe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the quick work :) Some more nits, but in the meantime I'll start testing it out

I would like to rename this to something that will not confuse users about the fact that this runs in a backend context, rather than frontend (which is where people think when they hear 'embedded wallet'). Something like PrivyEvmDelegatedEmbeddedWalletProvider.

I know it's a mouthful, but it's important to us that this distinction is clear.

Comment thread typescript/examples/langchain-privy-delegated-chatbot/yarn.lock Outdated
Comment thread typescript/package-lock.json
Comment thread typescript/examples/langchain-privy-delegated-chatbot/chatbot.ts Outdated

@CarsonRoscoe CarsonRoscoe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the PrivyWalletProvider section in typescript/agentkit/README.md. Does not need to be a big update, but just enough to signal that it can be either server or embedded.

Could even be a one line addition to the config to add type: 'server' // 'server' or 'embedded'

@CarsonRoscoe CarsonRoscoe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the new example under agentkit/typescript/examples/ for our repository structure. It's in alphabetical order, so it would go between langchain-privy-chatbot and langchain-solana-chatbot

This change needs to be in two places, our CONTIRBUTING guide and our root README

@CarsonRoscoe CarsonRoscoe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a .env-local file to the chatbot example?

See here. Basically copy-paste here, but make remove optional from wallet id's description

Comment thread typescript/agentkit/src/wallet-providers/privyWalletProvider.ts Outdated
Comment thread typescript/agentkit/src/wallet-providers/privyEvmEmbeddedWalletProvider.ts Outdated
Comment thread typescript/agentkit/src/wallet-providers/privyEvmEmbeddedWalletProvider.ts Outdated

@CarsonRoscoe CarsonRoscoe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! The suggested changes were ones I had to make to get it to run locally and test all the features, but I'm overall happy.

Once you make the changes and I re-test to confirm, I think we'll be good to merge :)

@njokuScript

Copy link
Copy Markdown
Contributor Author

PrivyEvmDelegatedEmbeddedWalletProvider

Got it. I agree

@njokuScript

Copy link
Copy Markdown
Contributor Author

type: 'server' // 'server' or 'embedded'

the way the readme is structured here, after PrivyWalletProvider, it goes on to tell you how to configure the different types. re: 'server' | 'embedded'

@CarsonRoscoe
CarsonRoscoe changed the base branch from main to feat/privy-delegated-wallet March 27, 2025 16:41
@CarsonRoscoe
CarsonRoscoe changed the base branch from feat/privy-delegated-wallet to feat/privy-evm-delegated-embedded-wallet-provider March 27, 2025 16:45

@CarsonRoscoe CarsonRoscoe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good to me!

I'm going to merge this into a new branch and finish it up there. This approach ensures your commits will live on into the final merge, and you will be properly credited for all your valuable work.

Thank you again for the contribution, the ETA is it will be included in the Friday release :)

@CarsonRoscoe
CarsonRoscoe merged commit 3ff19cc into coinbase:feat/privy-evm-delegated-embedded-wallet-provider Mar 27, 2025
CarsonRoscoe pushed a commit that referenced this pull request Mar 27, 2025
* chore: implement privy delegated wallet provider for evm

* chore: rename provider to be evm specific

* add unused func to fix inheritance error

* chore: add tests for privy evm embedded wallet provider

* update readme and changeset

* fix onchain spelling

* chore: Changed the parameter structure to accept a single config object with address and add example

* chore: export privy client from shared privy class

* chore: fix native assets transfer

* uncomment analytics event

* remove logs and use viem's Adress type

* use viem's Hex type

* lookup chain ID using global NETWORK_ID_TO_CHAIN_ID

* remove unused chainid mapping fnc

* fix(wallet-providers): Fix type casting in PrivyWalletProvider

* remove unnecessary comments

* delete lock files

* chore: remove logs

* chore: await response from privy provider variant

* chore: rename spelling to privyEvmDelegatedEmbeddedWalletProvider

* udpate chatbot example to use new naming and add env.local file
CarsonRoscoe pushed a commit that referenced this pull request Mar 28, 2025
* chore: implement privy delegated wallet provider for evm

* chore: rename provider to be evm specific

* add unused func to fix inheritance error

* chore: add tests for privy evm embedded wallet provider

* update readme and changeset

* fix onchain spelling

* chore: Changed the parameter structure to accept a single config object with address and add example

* chore: export privy client from shared privy class

* chore: fix native assets transfer

* uncomment analytics event

* remove logs and use viem's Adress type

* use viem's Hex type

* lookup chain ID using global NETWORK_ID_TO_CHAIN_ID

* remove unused chainid mapping fnc

* fix(wallet-providers): Fix type casting in PrivyWalletProvider

* remove unnecessary comments

* delete lock files

* chore: remove logs

* chore: await response from privy provider variant

* chore: rename spelling to privyEvmDelegatedEmbeddedWalletProvider

* udpate chatbot example to use new naming and add env.local file
CarsonRoscoe added a commit that referenced this pull request Mar 28, 2025
* Add support for Privy embedded wallets with delegation (#583)

* chore: implement privy delegated wallet provider for evm

* chore: rename provider to be evm specific

* add unused func to fix inheritance error

* chore: add tests for privy evm embedded wallet provider

* update readme and changeset

* fix onchain spelling

* chore: Changed the parameter structure to accept a single config object with address and add example

* chore: export privy client from shared privy class

* chore: fix native assets transfer

* uncomment analytics event

* remove logs and use viem's Adress type

* use viem's Hex type

* lookup chain ID using global NETWORK_ID_TO_CHAIN_ID

* remove unused chainid mapping fnc

* fix(wallet-providers): Fix type casting in PrivyWalletProvider

* remove unnecessary comments

* delete lock files

* chore: remove logs

* chore: await response from privy provider variant

* chore: rename spelling to privyEvmDelegatedEmbeddedWalletProvider

* udpate chatbot example to use new naming and add env.local file

* chore: fix package-lock.json

* chore: missing pr feedback addressed

* chore: improved typing/logic in PrivyWalletProvider logic that routes to the correct provider

* chore: merged privy delegated embedded wallet example with standard privy example

* chore: updated privy chatbot readme to signal the server/embedded distinction

* chore: removed test. will reintroduce after wallet provider tests pr is merged, and add to privyWalletProvider tests

* chore: format/lint

* chore: added njokuScript credits to changelog entry

* feat: readded test file matching new standard

* fix: depps

* chore: lint/format

* PR feedback

* chore: refactor axios to fetch

* fix: changed default privy config in chatbot

---------

Co-authored-by: Njoku Emmanuel <kalunjoku123@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apple documentation Improvements or additions to documentation example New example agent typescript wallet provider New wallet provider

Development

Successfully merging this pull request may close these issues.

5 participants