Skip to main content

Overview

The EvmServerAccount is a server-managed Ethereum account that provides signing capabilities and blockchain interaction methods. It’s compatible with Viem and supports all standard Ethereum operations.

Type Definition

type EvmServerAccount = {
  address: Address;
  name?: string;
  type: "evm-server";
  policies?: string[];
  sign: (parameters: { hash: Hash }) => Promise<Hex>;
  signMessage: (parameters: { message: SignableMessage }) => Promise<Hex>;
  signTransaction: (transaction: TransactionSerializable) => Promise<Hex>;
  signTypedData: <typedData, primaryType>(
    parameters: TypedDataDefinition<typedData, primaryType>
  ) => Promise<Hex>;
  transfer: (options: TransferOptions) => Promise<TransactionResult>;
  listTokenBalances: (options: Omit<ListTokenBalancesOptions, "address">) => Promise<ListTokenBalancesResult>;
  requestFaucet: (options: Omit<RequestFaucetOptions, "address">) => Promise<RequestFaucetResult>;
  sendTransaction: (options: Omit<SendTransactionOptions, "address">) => Promise<TransactionResult>;
  quoteSwap: (options: AccountQuoteSwapOptions) => Promise<AccountQuoteSwapResult>;
  swap: (options: AccountSwapOptions) => Promise<AccountSwapResult>;
  useSpendPermission: (options: UseSpendPermissionOptions) => Promise<TransactionResult>;
  useNetwork: <Network>(network: Network) => Promise<NetworkScopedEvmServerAccount<Network>>;
};

Properties

address
Address
required
The Ethereum address of the account (0x-prefixed hex string).
name
string
Optional name for the server account.
type
'evm-server'
required
Indicates this is a server-managed account.
policies
string[]
Array of Policy IDs that apply to the account.

Methods

sign

Signs a message hash and returns the signature.
parameters
object
required
signature
Hex
The signature as a hex string.
const signature = await account.sign({
  hash: "0x1234567890123456789012345678901234567890123456789012345678901234"
});

signMessage

Signs an EIP-191 message and returns the signature.
parameters
object
required
signature
Hex
The signature as a hex string.
const signature = await account.signMessage({
  message: "Hello, world!"
});

signTransaction

Signs a transaction and returns the signed transaction.
transaction
TransactionSerializable
required
The transaction to sign (Viem transaction object).
signedTransaction
Hex
The signed transaction as a hex string.
import { parseEther } from "viem";

const signedTx = await account.signTransaction({
  to: "0x4252e0c9A3da5A2700e7d91cb50aEf522D0C6Fe8",
  value: parseEther("0.000001"),
  chainId: 84532,
});

signTypedData

Signs EIP-712 typed data and returns the signature.
parameters
TypedDataDefinition
required
The typed data to sign (EIP-712 structured data).
signature
Hex
The signature as a hex string.
const signature = await account.signTypedData({
  domain: {
    name: "Permit2",
    chainId: 1,
    verifyingContract: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
  },
  types: {
    PermitTransferFrom: [
      { name: "permitted", type: "TokenPermissions" },
      { name: "spender", type: "address" },
    ],
    TokenPermissions: [
      { name: "token", type: "address" },
      { name: "amount", type: "uint256" },
    ],
  },
  primaryType: "PermitTransferFrom",
  message: {
    permitted: {
      token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      amount: "1000000",
    },
    spender: "0xFfFfFfFFfFFfFFfFFfFFFFFffFFFffffFfFFFfFf",
  },
});

transfer

Transfers native tokens or ERC-20 tokens to a recipient.
options
TransferOptions
required
transactionHash
Hex
The transaction hash.
import { parseEther } from "viem";

// Transfer native ETH
const result = await account.transfer({
  network: "base-sepolia",
  to: "0x4252e0c9A3da5A2700e7d91cb50aEf522D0C6Fe8",
  amount: parseEther("0.001"),
});

// Transfer ERC-20 token
const result = await account.transfer({
  network: "base-sepolia",
  to: "0x4252e0c9A3da5A2700e7d91cb50aEf522D0C6Fe8",
  amount: 1000000n, // 1 USDC
  token: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
});

listTokenBalances

Lists token balances for the account on a specific network.
options
object
required
balances
TokenBalance[]
Array of token balance objects.
nextPageToken
string
Token for fetching the next page.
const { balances } = await account.listTokenBalances({
  network: "base-sepolia",
});

balances.forEach(balance => {
  console.log(`${balance.token.symbol}: ${balance.amount}`);
});

requestFaucet

Requests testnet funds from a faucet.
options
object
required
transactionHash
Hex
The transaction hash of the faucet transfer.
const result = await account.requestFaucet({
  network: "base-sepolia",
  token: "eth",
});

sendTransaction

Sends a transaction to the network.
options
object
required
transactionHash
Hex
The transaction hash.
import { parseEther, serializeTransaction } from "viem";

const result = await account.sendTransaction({
  network: "base-sepolia",
  transaction: {
    to: "0x4252e0c9A3da5A2700e7d91cb50aEf522D0C6Fe8",
    value: parseEther("0.000001"),
  },
});

quoteSwap

Gets a quote for swapping tokens.
options
AccountQuoteSwapOptions
required
quote
SwapQuote
The swap quote with pricing information.
import { parseEther } from "viem";

const quote = await account.quoteSwap({
  network: "base",
  fromToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
  toToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
  fromAmount: parseEther("1"),
});

swap

Executes a token swap.
options
AccountSwapOptions
required
Swap options (can accept a quote from quoteSwap).
transactionHash
Hex
The transaction hash of the swap.
// Using a quote
const quote = await account.quoteSwap({ ... });
const result = await account.swap(quote);

// Direct swap
const result = await account.swap({
  network: "base",
  fromToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
  toToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  fromAmount: parseEther("1"),
});

useSpendPermission

Uses a spend permission to transfer tokens.
options
UseSpendPermissionOptions
required
Options for using the spend permission.
transactionHash
Hex
The transaction hash.
const result = await account.useSpendPermission({
  network: "base-sepolia",
  spendPermission: {
    account: account.address,
    spender: "0x...",
    token: "0x...",
    allowance: 1000000n,
    period: 86400n,
    start: BigInt(Math.floor(Date.now() / 1000)),
    end: BigInt(Math.floor(Date.now() / 1000) + 86400),
  },
});

useNetwork

Returns a network-scoped account with type-safe methods for that network.
network
string
required
The network name or RPC URL.
NetworkScopedEvmServerAccount
NetworkScopedEvmServerAccount
A network-scoped account instance.
// Type-safe network-scoped account
const baseAccount = await account.useNetwork("base-sepolia");

// Now all methods are scoped to base-sepolia
const result = await baseAccount.transfer({
  to: "0x4252e0c9A3da5A2700e7d91cb50aEf522D0C6Fe8",
  amount: parseEther("0.001"),
});

Creating an Account

Accounts are created through the CdpClient:
import { CdpClient } from "@coinbase/cdp-sdk";

const cdp = new CdpClient();
const account = await cdp.evm.createAccount();

Build docs developers (and LLMs) love