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.
The Smart Account address (0x-prefixed hex string).
owners
@property
def owners(self) -> list[BaseAccount]:
Get the account owners.
name
@property
def name(self) -> str | None:
Get the name of the smart account.
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.
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.
The amount of the token to transfer, represented as an atomic unit (e.g. 10000 for 0.01 USDC).
The network to transfer the token on.
The paymaster URL to use for gas sponsorship.
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.
The network to list the token balances for.
The number of token balances to return per page.
The token for the next page of token balances, if any.
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.
The network to request the faucet for.
The token to request the faucet for.
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.
The paymaster URL for gas sponsorship.
Optional data suffix (EIP-8021) to enable transaction attribution.
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.
The hash of the user operation to wait for.
Maximum time to wait in seconds.
Time between checks in seconds.
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.
The hash of the user operation to get.
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).
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.
The contract address of the token to swap from.
The contract address of the token to swap to.
The amount to swap from (in smallest unit).
The network to execute the swap on.
Maximum slippage in basis points (100 = 1%).
Optional paymaster URL for gas sponsorship.
Optional idempotency key for safe retryable requests.
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.
The domain of the typed data.
The types of the typed data.
The primary type of the typed data.
The network to sign the typed data on.
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.
The amount to spend (must not exceed the permission’s allowance).
The network to execute the transaction on.
Optional paymaster URL for gas sponsorship.
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",
)