-
Notifications
You must be signed in to change notification settings - Fork 150
feat: add projectId configuration, revokeDelegationForEndUser, and end user API's to TypeScript SDK #624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sammccord
merged 5 commits into
main
from
sammccord/cdpsdk-2350-add-revokedelegation-to-cdp-sdk
Mar 30, 2026
Merged
feat: add projectId configuration, revokeDelegationForEndUser, and end user API's to TypeScript SDK #624
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9fe6cc1
feat(CDPSDK-2351): create/revoke delegation + endusers api, examples
sammccord 66a75ce
chore: add disclaimer to examples
sammccord f5e81be
chore: changeset
sammccord 81e9e9e
chore: add delegated routing comment
sammccord e183324
test: add requireProjectId error tests for end user delegation operat…
sammccord File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
examples/typescript/end-users/createEvmEip7702Delegation.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Usage: pnpm tsx end-users/createEvmEip7702Delegation.ts <USER_UUID> | ||
|
|
||
| import { CdpClient } from "@coinbase/cdp-sdk"; | ||
| import "dotenv/config"; | ||
|
|
||
| const userId = process.argv[2]; | ||
| if (!userId) { | ||
| console.error( | ||
| "Usage: pnpm tsx end-users/createEvmEip7702Delegation.ts <USER_UUID>" | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const cdp = new CdpClient(); | ||
|
|
||
| try { | ||
| const endUser = await cdp.endUser.getEndUser({ userId }); | ||
|
|
||
| console.log("EVM address:", endUser.evmAccountObjects[0]?.address); | ||
|
|
||
| // Create an EIP-7702 delegation using the client method (developer calls on behalf of end user) | ||
| const result = await cdp.endUser.createEvmEip7702Delegation({ | ||
| userId: endUser.userId, | ||
| address: endUser.evmAccountObjects[0].address, | ||
| network: "base-sepolia", | ||
| enableSpendPermissions: true, | ||
| }); | ||
|
|
||
| console.log( | ||
| "Delegation operation ID (via client):", | ||
| result.delegationOperationId | ||
| ); | ||
|
|
||
| // Alternatively, create directly on the EndUserAccount (auto-picks first EVM address) | ||
| const result2 = await endUser.createEvmEip7702Delegation({ | ||
| network: "base-sepolia", | ||
| enableSpendPermissions: true, | ||
| }); | ||
|
|
||
| console.log( | ||
| "Delegation operation ID (via account):", | ||
| result2.delegationOperationId | ||
| ); | ||
| } catch (error) { | ||
| console.error("Error: ", (error as { errorMessage: string }).errorMessage); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Usage: pnpm tsx end-users/revokeDelegation.ts <USER_UUID> | ||
|
|
||
| import { CdpClient } from "@coinbase/cdp-sdk"; | ||
| import "dotenv/config"; | ||
|
|
||
| const userId = process.argv[2]; | ||
| if (!userId) { | ||
| console.error("Usage: pnpm tsx end-users/revokeDelegation.ts <USER_UUID>"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const cdp = new CdpClient(); | ||
|
|
||
| try { | ||
| const endUser = await cdp.endUser.getEndUser({ userId }); | ||
|
|
||
| // Revoke all active delegations for the end user using the client method | ||
| await cdp.endUser.revokeDelegationForEndUser({ | ||
| userId: endUser.userId, | ||
| }); | ||
|
|
||
| console.log("Revoked delegation for end user via client method"); | ||
|
|
||
| // Alternatively, revoke delegation directly on the EndUserAccount object | ||
| await endUser.revokeDelegation(); | ||
|
|
||
| console.log("Revoked delegation for end user via account method"); | ||
| } catch (error) { | ||
| console.error("Error: ", (error as { errorMessage: string }).errorMessage); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Usage: pnpm tsx end-users/sendEvmAsset.ts <USER_UUID> | ||
| // Note: This example requires the end user to have an active delegation on their | ||
| // account that allows the developer to sign on their behalf. | ||
|
|
||
| import { CdpClient } from "@coinbase/cdp-sdk"; | ||
| import "dotenv/config"; | ||
|
|
||
| const userId = process.argv[2]; | ||
| if (!userId) { | ||
| console.error("Usage: pnpm tsx end-users/sendEvmAsset.ts <USER_UUID>"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const cdp = new CdpClient(); | ||
|
|
||
| try { | ||
| const endUser = await cdp.endUser.getEndUser({ userId }); | ||
|
|
||
| console.log("EVM address:", endUser.evmAccountObjects[0]?.address); | ||
|
|
||
| // Send USDC using the client method (developer calls on behalf of end user) | ||
| const result = await cdp.endUser.sendEvmAsset({ | ||
| userId: endUser.userId, | ||
| address: endUser.evmAccountObjects[0].address, | ||
| asset: "usdc", | ||
| to: "0x0000000000000000000000000000000000000001", // recipient address | ||
| amount: "1000000", // 1 USDC (6 decimals) | ||
| network: "base-sepolia", | ||
| }); | ||
|
|
||
| console.log("Transaction hash (via client):", result.transactionHash); | ||
|
|
||
| // Alternatively, send directly on the EndUserAccount (auto-picks first EVM address) | ||
| const result2 = await endUser.sendEvmAsset({ | ||
| asset: "usdc", | ||
| to: "0x0000000000000000000000000000000000000001", | ||
| amount: "1000000", | ||
| network: "base-sepolia", | ||
| }); | ||
|
|
||
| console.log("Transaction hash (via account):", result2.transactionHash); | ||
| } catch (error) { | ||
| console.error("Error: ", (error as { errorMessage: string }).errorMessage); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Usage: pnpm tsx end-users/sendEvmTransaction.ts <USER_UUID> | ||
| // Note: This example requires the end user to have an active delegation on their | ||
| // account that allows the developer to sign on their behalf. | ||
|
|
||
| import { CdpClient } from "@coinbase/cdp-sdk"; | ||
| import "dotenv/config"; | ||
|
|
||
| const userId = process.argv[2]; | ||
| if (!userId) { | ||
| console.error("Usage: pnpm tsx end-users/sendEvmTransaction.ts <USER_UUID>"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const cdp = new CdpClient(); | ||
|
|
||
| try { | ||
| const endUser = await cdp.endUser.getEndUser({ userId }); | ||
|
|
||
| console.log("EVM address:", endUser.evmAccountObjects[0]?.address); | ||
|
|
||
| // Send an EVM transaction using the client method (developer calls on behalf of end user) | ||
| const result = await cdp.endUser.sendEvmTransaction({ | ||
| userId: endUser.userId, | ||
| address: endUser.evmAccountObjects[0].address, | ||
| transaction: "0x02...", // RLP-serialized EIP-1559 transaction | ||
| network: "base-sepolia", | ||
| }); | ||
|
|
||
| console.log("Transaction hash (via client):", result.transactionHash); | ||
|
|
||
| // Alternatively, send directly on the EndUserAccount (auto-picks first EVM address) | ||
| const result2 = await endUser.sendEvmTransaction({ | ||
| transaction: "0x02...", | ||
| network: "base-sepolia", | ||
| }); | ||
|
|
||
| console.log("Transaction hash (via account):", result2.transactionHash); | ||
| } catch (error) { | ||
| console.error("Error: ", (error as { errorMessage: string }).errorMessage); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Usage: pnpm tsx end-users/sendUserOperation.ts <USER_UUID> | ||
| // Note: This example requires the end user to have an active delegation on their | ||
| // account that allows the developer to sign on their behalf. | ||
|
|
||
| import { CdpClient } from "@coinbase/cdp-sdk"; | ||
| import "dotenv/config"; | ||
|
|
||
| const userId = process.argv[2]; | ||
| if (!userId) { | ||
| console.error("Usage: pnpm tsx end-users/sendUserOperation.ts <USER_UUID>"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const cdp = new CdpClient(); | ||
|
|
||
| try { | ||
| const endUser = await cdp.endUser.getEndUser({ userId }); | ||
|
|
||
| if (!endUser.evmSmartAccountObjects?.length) { | ||
| console.error("End user has no smart account. Create one first."); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log("Smart account address:", endUser.evmSmartAccountObjects[0]?.address); | ||
|
|
||
| // Send a user operation using the client method. | ||
| // User operations can batch multiple calls in a single transaction. | ||
| const result = await cdp.endUser.sendUserOperation({ | ||
| userId: endUser.userId, | ||
| address: endUser.evmSmartAccountObjects[0].address, | ||
| network: "base-sepolia", | ||
| calls: [ | ||
| { | ||
| to: "0x0000000000000000000000000000000000000000", | ||
| value: "0", | ||
| data: "0x", | ||
| }, | ||
| ], | ||
| useCdpPaymaster: true, // CDP sponsors the gas | ||
| }); | ||
|
|
||
| console.log("User operation hash (via client):", result.userOpHash); | ||
|
|
||
| // Alternatively, send directly on the EndUserAccount (auto-picks first smart account) | ||
| const result2 = await endUser.sendUserOperation({ | ||
| network: "base-sepolia", | ||
| calls: [ | ||
| { | ||
| to: "0x0000000000000000000000000000000000000000", | ||
| value: "0", | ||
| data: "0x", | ||
| }, | ||
| ], | ||
| useCdpPaymaster: true, | ||
| }); | ||
|
|
||
| console.log("User operation hash (via account):", result2.userOpHash); | ||
| } catch (error) { | ||
| console.error("Error: ", (error as { errorMessage: string }).errorMessage); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Usage: pnpm tsx end-users/signEvmHash.ts <USER_UUID> | ||
| // Note: This example requires the end user to have an active delegation on their | ||
| // account that allows the developer to sign on their behalf. | ||
|
|
||
| import { CdpClient } from "@coinbase/cdp-sdk"; | ||
| import "dotenv/config"; | ||
|
|
||
| const userId = process.argv[2]; | ||
| if (!userId) { | ||
| console.error("Usage: pnpm tsx end-users/signEvmHash.ts <USER_UUID>"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const cdp = new CdpClient(); | ||
|
|
||
| try { | ||
| const endUser = await cdp.endUser.getEndUser({ userId }); | ||
|
|
||
| console.log("EVM address:", endUser.evmAccountObjects[0]?.address); | ||
|
|
||
| // Sign an EVM hash using the client method (developer calls on behalf of end user) | ||
| const result = await cdp.endUser.signEvmHash({ | ||
| userId: endUser.userId, | ||
| hash: "0x0000000000000000000000000000000000000000000000000000000000000001", | ||
| address: endUser.evmAccountObjects[0].address, | ||
| }); | ||
|
|
||
| console.log("Signature (via client):", result.signature); | ||
|
|
||
| // Alternatively, sign directly on the EndUserAccount (auto-picks first EVM address) | ||
| const result2 = await endUser.signEvmHash({ | ||
| hash: "0x0000000000000000000000000000000000000000000000000000000000000002", | ||
| }); | ||
|
|
||
| console.log("Signature (via account):", result2.signature); | ||
| } catch (error) { | ||
| console.error("Error: ", error); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Usage: pnpm tsx end-users/signSolanaMessage.ts <USER_UUID> | ||
| // Note: This example requires the end user to have an active delegation on their | ||
| // account that allows the developer to sign on their behalf. | ||
|
|
||
| import { CdpClient } from "@coinbase/cdp-sdk"; | ||
| import "dotenv/config"; | ||
|
|
||
| const userId = process.argv[2]; | ||
| if (!userId) { | ||
| console.error("Usage: pnpm tsx end-users/signSolanaMessage.ts <USER_UUID>"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const cdp = new CdpClient(); | ||
|
|
||
| try { | ||
| const endUser = await cdp.endUser.getEndUser({ userId }); | ||
|
|
||
| console.log("Solana address:", endUser.solanaAccountObjects[0]?.address); | ||
|
|
||
| // Sign a Solana message using the client method (developer calls on behalf of end user) | ||
| const result = await cdp.endUser.signSolanaMessage({ | ||
| userId: endUser.userId, | ||
| address: endUser.solanaAccountObjects[0].address, | ||
| message: Buffer.from("Hello, World!").toString("base64"), | ||
| }); | ||
|
|
||
| console.log("Signature (via client):", result.signature); | ||
|
|
||
| // Alternatively, sign directly on the EndUserAccount (auto-picks first Solana address) | ||
| const result2 = await endUser.signSolanaMessage({ | ||
| message: Buffer.from("Hello again!").toString("base64"), | ||
| }); | ||
|
|
||
| console.log("Signature (via account):", result2.signature); | ||
| } catch (error) { | ||
| console.error("Error: ", (error as { errorMessage: string }).errorMessage); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes the user has granted delegation to the developer, right? Would be good to document that in the script instructions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
documented at the top