Skip to main content

EvmServerAccount

An EVM server account managed by the CDP API. Provides async methods for signing messages and transactions.

Constructor

EvmServerAccount(
    evm_server_account_model: EvmServerAccountModel,
    evm_accounts_api: EVMAccountsApi,
    api_clients: ApiClients,
)
This constructor is typically not called directly. Use CdpClient.evm.create_account() instead.

Properties

address

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

name

@property
def name(self) -> str | None:
Get the name of the EVM account.
return
str | None
The name of the EVM 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

sign_message

async def sign_message(
    self,
    signable_message: SignableMessage,
    idempotency_key: str | None = None,
) -> SignedMessage:
Sign an EIP-191 message.
signable_message
SignableMessage
required
The encoded message, ready for signing.
idempotency_key
str | None
Optional idempotency key for safe retryable requests.
return
SignedMessage
The signed message with signature components (r, s, v).

unsafe_sign_hash

async def unsafe_sign_hash(
    self,
    message_hash: Hash32,
    idempotency_key: str | None = None,
) -> SignedMessage:
Sign the hash of a message.
Never sign a hash that you didn’t generate - it can be an arbitrary transaction.
message_hash
Hash32
required
32 byte hash of the message to sign.
idempotency_key
str | None
Optional idempotency key.
return
SignedMessage
The signed message with signature components.

sign_transaction

async def sign_transaction(
    self,
    transaction_dict: TransactionDictType,
    idempotency_key: str | None = None,
) -> SignedTransaction:
Sign a transaction dict.
transaction_dict
TransactionDictType
required
Transaction with all fields specified.
idempotency_key
str | None
Optional idempotency key.
return
SignedTransaction
The signed transaction.

transfer

async def transfer(
    self,
    to: str | BaseAccount | EvmServerAccount | EvmSmartAccount,
    amount: int,
    token: str,
    network: str,
):
Transfer an amount of a token from an account to another account.
to
str | BaseAccount | EvmServerAccount | EvmSmartAccount
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). The cdp module exports a parse_units util to convert to atomic units.
token
str
required
The token to transfer (e.g., “usdc”, “eth”).
network
str
required
The network to transfer the token on (e.g., “base-sepolia”, “base”).
return
TransferResult
The result of the transfer.
# Example: Transfer USDC
from cdp import parse_units

transfer = await sender.transfer(
    to="0x9F663335Cd6Ad02a37B633602E98866CF944124d",
    amount=parse_units("0.01", 6),  # 0.01 USDC
    token="usdc",
    network="base-sepolia",
)

swap

async def swap(
    self,
    swap_options: AccountSwapOptions,
) -> AccountSwapResult:
Execute a token swap.
swap_options
AccountSwapOptions
required
The swap options containing network, tokens, amounts, and optional quote.
return
AccountSwapResult
The result containing the transaction hash.

quote_swap

async def quote_swap(
    self,
    from_token: str,
    to_token: str,
    from_amount: str | int,
    network: str,
    slippage_bps: int | None = None,
    signer_address: str | None = None,
    idempotency_key: str | None = None,
) -> QuoteSwapResult:
Get a quote for swapping tokens.
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%).
signer_address
str | None
The address that will sign the transaction (for smart accounts).
idempotency_key
str | None
Optional idempotency key for safe retryable requests.
return
QuoteSwapResult
The swap quote with transaction data.
# Example: Get swap quote and execute
quote = await account.quote_swap(
    from_token="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",  # USDC
    to_token="0x4200000000000000000000000000000000000006",  # WETH
    from_amount="100000000",  # 100 USDC
    network="base",
)
print(f"Expected output: {quote.to_amount}")

# Execute the quote
result = await account.swap(AccountSwapOptions(swap_quote=quote))

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.

sign_typed_data

async def sign_typed_data(
    self,
    domain: EIP712Domain,
    types: dict[str, Any],
    primary_type: str,
    message: dict[str, Any],
    idempotency_key: str | None = None,
) -> str:
Sign an EVM typed data (EIP-712).
domain
EIP712Domain
required
The domain of the message.
types
dict[str, Any]
required
The types of the message.
primary_type
str
required
The primary type of the message.
message
dict[str, Any]
required
The message to sign.
idempotency_key
str | None
Optional idempotency key.
return
str
The signature.

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 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 account on the network.

send_transaction

async def send_transaction(
    self,
    transaction: str | TransactionRequestEIP1559 | DynamicFeeTransaction,
    network: str,
    idempotency_key: str | None = None,
) -> str:
Send an EVM transaction.
transaction
str | TransactionRequestEIP1559 | DynamicFeeTransaction
required
The transaction to send. This can be either an RLP-encoded transaction to sign and send (as a 0x-prefixed hex string), or an EIP-1559 transaction request object.Use TransactionRequestEIP1559 if you would like Coinbase to manage the nonce and gas parameters.These are the fields that can be contained in the transaction object:
  • to: (Required) The address of the contract or account to send the transaction to.
  • value: (Optional) The amount of ETH, in wei, to send with the transaction.
  • data: (Optional) The data to send with the transaction; only used for contract calls.
  • gas: (Optional) The amount of gas to use for the transaction.
  • nonce: (Optional) The nonce to use for the transaction.
  • maxFeePerGas: (Optional) The maximum fee per gas.
  • maxPriorityFeePerGas: (Optional) The maximum priority fee per gas.
  • accessList: (Optional) The access list to use for the transaction.
network
str
required
The network.
idempotency_key
str | None
Optional idempotency key.
return
str
The transaction hash.

use_spend_permission

async def use_spend_permission(
    self,
    spend_permission: SpendPermissionInput,
    value: int,
    network: str,
) -> str:
Use a spend permission to spend tokens.
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.
return
str
The transaction hash.
# Example: Use spend permission
from cdp import parse_units
from cdp.spend_permissions import SpendPermissionInput

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

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

Build docs developers (and LLMs) love