Skip to main content

EvmSmartAccount

A class representing an EVM smart account with support for user operations (ERC-4337 account abstraction).

Constructor

EvmSmartAccount(
    address: str,
    owner: BaseAccount,
    name: str | None = None,
    policies: list[str] | None = None,
    api_clients: ApiClients | None = None,
)
This constructor is typically not called directly. Use CdpClient.evm.create_smart_account() instead.

Properties

address

@property
def address(self) -> str:
Get the Smart Account address.
return
str
The Smart Account address (0x-prefixed hex string).

owners

@property
def owners(self) -> list[BaseAccount]:
Get the account owners.
return
list[BaseAccount]
List of owner accounts.

name

@property
def name(self) -> str | None:
Get the name of the smart account.
return
str | None
The name of the smart account, or None if not set.

policies

@property
def policies(self) -> list[str] | None:
Gets the list of policies that apply to this account.
return
list[str] | None
The list of Policy IDs.

Methods

transfer

async def transfer(
    self,
    to: str | BaseAccount,
    amount: int,
    token: str,
    network: str,
    paymaster_url: str | None = None,
):
Transfer an amount of a token from the smart account to another account.
to
str | BaseAccount
required
The account or 0x-prefixed address to transfer the token to.
amount
int
required
The amount of the token to transfer, represented as an atomic unit (e.g. 10000 for 0.01 USDC).
token
str
required
The token to transfer.
network
str
required
The network to transfer the token on.
paymaster_url
str | None
The paymaster URL to use for gas sponsorship.
return
TransferResult
The result of the transfer.
# Example: Transfer with paymaster
from cdp import parse_units

transfer = await smart_account.transfer(
    to="0x9F663335Cd6Ad02a37B633602E98866CF944124d",
    amount=parse_units("0.01", 6),
    token="usdc",
    network="base-sepolia",
    paymaster_url="https://paymaster.example.com",
)

list_token_balances

async def list_token_balances(
    self,
    network: str,
    page_size: int | None = None,
    page_token: str | None = None,
) -> ListTokenBalancesResult:
List the token balances for the smart account on the given network.
network
str
required
The network to list the token balances for.
page_size
int | None
The number of token balances to return per page.
page_token
str | None
The token for the next page of token balances, if any.
return
ListTokenBalancesResult
The token balances for the smart account on the network.

request_faucet

async def request_faucet(
    self,
    network: str,
    token: str,
) -> str:
Request a token from the faucet.
network
str
required
The network to request the faucet for.
token
str
required
The token to request the faucet for.
return
str
The transaction hash of the faucet request.

send_user_operation

async def send_user_operation(
    self,
    calls: list[ContractCall],
    network: str,
    paymaster_url: str | None = None,
    data_suffix: str | None = None,
) -> EvmUserOperationModel:
Send a user operation for the smart account.
calls
list[ContractCall]
required
The calls to send.
network
str
required
The network.
paymaster_url
str | None
The paymaster URL for gas sponsorship.
data_suffix
str | None
Optional data suffix (EIP-8021) to enable transaction attribution.
return
EvmUserOperationModel
The user operation model.

wait_for_user_operation

async def wait_for_user_operation(
    self,
    user_op_hash: str,
    timeout_seconds: float = 20,
    interval_seconds: float = 0.2,
) -> EvmUserOperationModel:
Wait for a user operation to be processed.
user_op_hash
str
required
The hash of the user operation to wait for.
timeout_seconds
float
default:"20"
Maximum time to wait in seconds.
interval_seconds
float
default:"0.2"
Time between checks in seconds.
return
EvmUserOperationModel
The user operation model.

get_user_operation

async def get_user_operation(
    self,
    user_op_hash: str,
) -> EvmUserOperationModel:
Get a user operation for the smart account by hash.
user_op_hash
str
required
The hash of the user operation to get.
return
EvmUserOperationModel
The user operation model.

swap

async def swap(
    self,
    options: SmartAccountSwapOptions,
) -> SmartAccountSwapResult:
Execute a token swap via user operation.
options
SmartAccountSwapOptions
required
SmartAccountSwapOptions with either swap_quote OR inline parameters (network, from_token, to_token, from_amount).
return
SmartAccountSwapResult
The user operation result containing:
  • user_op_hash: The user operation hash
  • smart_account_address: The smart account address
  • status: The operation status
# Example: Using pre-created swap quote
from cdp.actions.evm.swap.types import SmartAccountSwapOptions

# First create a quote
quote = await smart_account.quote_swap(
    from_token="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",  # USDC
    to_token="0x4200000000000000000000000000000000000006",  # WETH
    from_amount="100000000",  # 100 USDC
    network="base",
)

# Then execute the swap
result = await smart_account.swap(
    SmartAccountSwapOptions(
        swap_quote=quote,
        idempotency_key="..."
    )
)

# Example: Using inline parameters
result = await smart_account.swap(
    SmartAccountSwapOptions(
        network="base",
        from_token="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
        to_token="0x4200000000000000000000000000000000000006",
        from_amount="100000000",
        slippage_bps=100,
    )
)

quote_swap

async def quote_swap(
    self,
    from_token: str,
    to_token: str,
    from_amount: str | int,
    network: str,
    slippage_bps: int | None = None,
    paymaster_url: str | None = None,
    idempotency_key: str | None = None,
) -> QuoteSwapResult:
Get a quote for swapping tokens with a smart account.
from_token
str
required
The contract address of the token to swap from.
to_token
str
required
The contract address of the token to swap to.
from_amount
str | int
required
The amount to swap from (in smallest unit).
network
str
required
The network to execute the swap on.
slippage_bps
int | None
default:"100"
Maximum slippage in basis points (100 = 1%).
paymaster_url
str | None
Optional paymaster URL for gas sponsorship.
idempotency_key
str | None
Optional idempotency key for safe retryable requests.
return
QuoteSwapResult
The swap quote with transaction data.

sign_typed_data

async def sign_typed_data(
    self,
    domain: EIP712Domain,
    types: dict[str, Any],
    primary_type: str,
    message: dict[str, Any],
    network: str,
) -> str:
Sign a typed data object with the smart account.
domain
EIP712Domain
required
The domain of the typed data.
types
dict[str, Any]
required
The types of the typed data.
primary_type
str
required
The primary type of the typed data.
message
dict[str, Any]
required
The message to sign.
network
str
required
The network to sign the typed data on.
return
str
The signature of the typed data.

use_spend_permission

async def use_spend_permission(
    self,
    spend_permission: SpendPermissionInput,
    value: int,
    network: str,
    paymaster_url: str | None = None,
) -> EvmUserOperationModel:
Use a spend permission to spend tokens via user operation.
spend_permission
SpendPermissionInput
required
The spend permission object containing authorization details.
value
int
required
The amount to spend (must not exceed the permission’s allowance).
network
str
required
The network to execute the transaction on.
paymaster_url
str | None
Optional paymaster URL for gas sponsorship.
return
EvmUserOperation
The user operation result.
# Example: Use spend permission with smart account
from cdp import parse_units
from cdp.spend_permissions import SpendPermissionInput

spend_permission = SpendPermissionInput(
    account="0x1234...",
    spender=smart_account.address,
    token="usdc",
    allowance=parse_units("0.01", 6),
    period=86400,
    start=0,
    end=281474976710655,
)

result = await smart_account.use_spend_permission(
    spend_permission=spend_permission,
    value=parse_units("0.005", 6),
    network="base-sepolia",
)

Build docs developers (and LLMs) love