EndUserClient
The EndUserClient class is responsible for CDP API calls for managing end users. An end user is an entity that can own CDP EVM accounts, EVM smart accounts, and/or Solana accounts.
create_end_user
async def create_end_user(
self,
authentication_methods: list[AuthenticationMethod],
user_id: str | None = None,
evm_account: CreateEndUserRequestEvmAccount | None = None,
solana_account: CreateEndUserRequestSolanaAccount | None = None,
) -> EndUserAccount:
Create an end user.
authentication_methods
list[AuthenticationMethod]
required
The list of authentication methods for the end user.
Optional unique identifier for the end user. If not provided, a UUID is generated.
evm_account
CreateEndUserRequestEvmAccount | None
Optional configuration for creating an EVM account for the end user.
solana_account
CreateEndUserRequestSolanaAccount | None
Optional configuration for creating a Solana account for the end user.
The created end user with action methods.
# Example: Create an end user with authentication
from cdp.openapi_client.models.authentication_method import AuthenticationMethod
end_user = await cdp.end_user.create_end_user(
authentication_methods=[
AuthenticationMethod(
type="passkey",
value="[email protected]",
)
],
user_id="user-123",
)
list_end_users
async def list_end_users(
self,
page_size: int | None = None,
page_token: str | None = None,
sort: list[str] | None = None,
) -> ListEndUsersResult:
List end users belonging to the developer’s CDP Project.
The number of end users to return per page.
The token for the desired page of end users.
Sort end users. Defaults to ascending order (oldest first).
A paginated list of end users with action methods.
# Example: List end users with pagination
result = await cdp.end_user.list_end_users(
page_size=10,
)
for user in result.end_users:
print(f"User ID: {user.user_id}")
if result.next_page_token:
next_page = await cdp.end_user.list_end_users(
page_size=10,
page_token=result.next_page_token,
)
validate_access_token
async def validate_access_token(
self,
access_token: str,
):
Validate an end user’s access token.
The access token to validate.
import_end_user
async def import_end_user(
self,
authentication_methods: list[AuthenticationMethod],
private_key: str | bytes,
key_type: Literal["evm", "solana"],
user_id: str | None = None,
encryption_public_key: str | None = None,
) -> EndUserAccount:
Import an existing private key for an end user.
authentication_methods
list[AuthenticationMethod]
required
The list of authentication methods for the end user.
The private key to import:
- For EVM: hex string (with or without 0x prefix)
- For Solana: base58 encoded string or raw bytes (32 or 64 bytes)
key_type
Literal['evm', 'solana']
required
The type of key being imported (“evm” or “solana”).
Optional unique identifier for the end user. If not provided, a UUID is generated.
Optional RSA public key to encrypt the private key. Defaults to the known CDP public key.
The imported end user with action methods.
If the private key format is invalid.
# Example: Import an existing EVM private key
from cdp.openapi_client.models.authentication_method import AuthenticationMethod
end_user = await cdp.end_user.import_end_user(
authentication_methods=[
AuthenticationMethod(
type="passkey",
value="[email protected]",
)
],
private_key="0x1234567890abcdef...",
key_type="evm",
user_id="imported-user-123",
)
add_end_user_evm_account
async def add_end_user_evm_account(
self,
user_id: str,
) -> AddEndUserEvmAccount201Response:
Add an EVM EOA (Externally Owned Account) to an existing end user.
End users can have up to 10 EVM accounts.
The unique identifier of the end user.
return
AddEndUserEvmAccount201Response
The result containing the newly created EVM EOA account.
# Example: Add an EVM account to an end user
response = await cdp.end_user.add_end_user_evm_account(
user_id="user-123",
)
print(f"New account address: {response.address}")
add_end_user_evm_smart_account
async def add_end_user_evm_smart_account(
self,
user_id: str,
enable_spend_permissions: bool,
) -> AddEndUserEvmSmartAccount201Response:
Add an EVM smart account to an existing end user. This also creates a new EVM EOA account to serve as the owner of the smart account.
The unique identifier of the end user.
If true, enables spend permissions for the EVM smart account.
return
AddEndUserEvmSmartAccount201Response
The result containing the newly created EVM smart account.
# Example: Add a smart account with spend permissions
response = await cdp.end_user.add_end_user_evm_smart_account(
user_id="user-123",
enable_spend_permissions=True,
)
print(f"Smart account address: {response.smart_account.address}")
print(f"Owner account address: {response.owner_account.address}")
add_end_user_solana_account
async def add_end_user_solana_account(
self,
user_id: str,
) -> AddEndUserSolanaAccount201Response:
Add a Solana account to an existing end user.
End users can have up to 10 Solana accounts.
The unique identifier of the end user.
return
AddEndUserSolanaAccount201Response
The result containing the newly created Solana account.
# Example: Add a Solana account to an end user
response = await cdp.end_user.add_end_user_solana_account(
user_id="user-123",
)
print(f"New Solana address: {response.address}")
ListEndUsersResult
Result of listing end users.
The token for the next page of end users, if any.
Example Usage
Complete End User Workflow
from cdp import CdpClient
from cdp.openapi_client.models.authentication_method import AuthenticationMethod
async with CdpClient(
api_key_id="your-api-key-id",
api_key_secret="your-api-key-secret",
) as cdp:
# Create an end user with passkey authentication
end_user = await cdp.end_user.create_end_user(
authentication_methods=[
AuthenticationMethod(
type="passkey",
value="[email protected]",
)
],
user_id="alice-123",
)
print(f"Created end user: {end_user.user_id}")
# Add an EVM account
evm_response = await cdp.end_user.add_end_user_evm_account(
user_id=end_user.user_id,
)
print(f"EVM account: {evm_response.address}")
# Add a smart account with spend permissions
smart_response = await cdp.end_user.add_end_user_evm_smart_account(
user_id=end_user.user_id,
enable_spend_permissions=True,
)
print(f"Smart account: {smart_response.smart_account.address}")
# Add a Solana account
solana_response = await cdp.end_user.add_end_user_solana_account(
user_id=end_user.user_id,
)
print(f"Solana account: {solana_response.address}")
# List all end users
result = await cdp.end_user.list_end_users(page_size=10)
for user in result.end_users:
print(f"User: {user.user_id}")
Import Existing Private Key
from cdp import CdpClient
from cdp.openapi_client.models.authentication_method import AuthenticationMethod
async with CdpClient(
api_key_id="your-api-key-id",
api_key_secret="your-api-key-secret",
) as cdp:
# Import an existing EVM private key
end_user = await cdp.end_user.import_end_user(
authentication_methods=[
AuthenticationMethod(
type="passkey",
value="[email protected]",
)
],
private_key="0xabcdef1234567890...",
key_type="evm",
)
print(f"Imported user: {end_user.user_id}")
# Import a Solana private key (base58 encoded)
solana_user = await cdp.end_user.import_end_user(
authentication_methods=[
AuthenticationMethod(
type="passkey",
value="[email protected]",
)
],
private_key="base58_encoded_key",
key_type="solana",
)
print(f"Imported Solana user: {solana_user.user_id}")