Overview
The CDP SDK provides comprehensive support for managing EVM (Ethereum Virtual Machine) accounts on Ethereum-compatible blockchains. This includes both server-managed accounts and smart contract accounts.
Account Types
The SDK includes generated types for EVM accounts from the OpenAPI specification:
use cdp_sdk::types::{
EvmAccount,
EndUserEvmAccount,
EndUserEvmSmartAccount,
};
Creating EVM Accounts
Create a Server-Managed Account
Create a new EVM account with optional parameters:
use cdp_sdk::{types, Client};
// Create account with a name
let body = types::CreateEvmAccountBody::builder()
.name(Some("my-evm-account".parse()?));
let response = client
.create_evm_account()
.x_wallet_auth("") // Set by middleware
.x_idempotency_key("unique-request-id")
.body(body)
.send()
.await?;
let account = response.into_inner();
println!("Account address: {}", account.address);
println!("Account name: {:?}", account.name);
Create Request Parameters
Optional human-readable name for the account
Unique key to ensure idempotent request handling (max 128 characters)
Wallet authentication JWT (automatically added by WalletAuth middleware)
Retrieving EVM Accounts
Get Account by Address
Retrieve a specific account using its Ethereum address:
let response = client
.get_evm_account()
.address("0x1234567890123456789012345678901234567890")
.send()
.await?;
let account = response.into_inner();
println!("Account: {:?}", account);
The Ethereum address of the account (0x-prefixed hex string)
Get Account by Name
Retrieve an account using its assigned name:
let response = client
.get_evm_account_by_name()
.name("my-evm-account")
.send()
.await?;
let account = response.into_inner();
The name assigned to the account
Updating EVM Accounts
Update an existing account’s properties:
use cdp_sdk::types;
let update_body = types::UpdateEvmAccountBody::builder()
.name(Some("updated-account-name".parse()?));
let response = client
.update_evm_account()
.address("0x1234567890123456789012345678901234567890")
.body(update_body)
.send()
.await?;
let updated_account = response.into_inner();
Update Parameters
The Ethereum address of the account to update
Listing EVM Accounts
List all EVM accounts with pagination support:
let response = client
.list_evm_accounts()
.page_size(10)
.page_token("next-page-token") // Optional
.send()
.await?;
let accounts_list = response.into_inner();
println!("Found {} accounts", accounts_list.accounts.len());
for account in accounts_list.accounts {
println!(" - {} ({})", account.address, account.name.unwrap_or_default());
}
// Get next page if available
if let Some(next_token) = accounts_list.next_page_token {
let next_response = client
.list_evm_accounts()
.page_size(10)
.page_token(next_token)
.send()
.await?;
}
List Parameters
Number of accounts to return per page (default: 50)
Token for retrieving the next page of results
EVM Smart Accounts
The SDK also supports EVM smart accounts (Account Abstraction):
Create Smart Account
use cdp_sdk::types;
let body = types::AddEndUserEvmSmartAccountBody::builder()
.enable_spend_permissions(true);
let response = client
.add_end_user_evm_smart_account()
.user_id("user-123".parse()?)
.x_wallet_auth("")
.x_idempotency_key("unique-request-id")
.body(body)
.send()
.await?;
let smart_account = response.into_inner().evm_smart_account;
Smart Account Parameters
If true, enables spend permissions for the smart account (default: false)
Response Types
All EVM account responses include comprehensive account information:
The Ethereum address of the account
Optional human-readable name
Timestamp when the account was created
Timestamp when the account was last updated
ABI Types
The SDK includes comprehensive ABI (Application Binary Interface) types for smart contract interactions:
use cdp_sdk::types::{
Abi,
AbiFunction,
AbiParameter,
AbiStateMutability,
};
ABI State Mutability
Function doesn’t read or modify state
Function only reads state (doesn’t modify)
Function modifies state but doesn’t accept Ether
Function can receive Ether
Error Handling
Handle errors appropriately when working with EVM accounts:
match client.create_evm_account()
.x_wallet_auth("")
.x_idempotency_key("request-id")
.body(body)
.send()
.await
{
Ok(response) => {
let account = response.into_inner();
println!("Success: {}", account.address);
}
Err(e) => {
eprintln!("Failed to create account: {}", e);
}
}
See Also