Creates a new CDP EVM account.
Optional
options: CreateServerAccountOptions = {}Optional parameters for creating the account.
Options for creating an EVM server account.
A promise that resolves to the newly created account.
Creates a new CDP EVM smart account.
Parameters for creating the smart account.
Options for creating an EVM smart account.
Optional
idempotencyKey?: stringThe idempotency key.
The owner of the account.
A promise that resolves to the newly created smart account.
const account = await cdp.evm.createAccount();
const smartAccount = await cdp.evm.createSmartAccount({
owner: account,
});
// See https://viem.sh/docs/accounts/local/privateKeyToAccount
const privateKey = generatePrivateKey();
const account = privateKeyToAccount(privateKey);
const smartAccount = await client.evm.createSmartAccount({
owner: account,
});
const idempotencyKey = uuidv4();
// First call
await cdp.evm.createSmartAccount({
owner: account,
idempotencyKey,
});
// Second call with the same idempotency key will return the same smart account
await cdp.evm.createSmartAccount({
owner: account,
idempotencyKey,
Gets a CDP EVM account.
Parameters for getting the account.
Either address
or name
must be provided.
If both are provided, lookup will be done by address
and name
will be ignored.
Options for getting an EVM account.
A promise that resolves to the account.
Gets a CDP EVM smart account.
Parameters for getting the smart account.
Options for getting an EVM smart account.
The address of the account.
The owner of the account.
A promise that resolves to the smart account.
Gets a user operation for a smart account by user operation hash.
Parameters for getting the user operation.
Options for getting a user operation.
The smart account.
The user operation hash.
A promise that resolves to the user operation.
Lists CDP EVM accounts.
Optional
options: ListServerAccountsOptions = {}Optional parameters for listing the accounts.
Options for listing EVM accounts.
A promise that resolves to an array of accounts, and a token to paginate through the accounts.
Lists CDP EVM smart accounts.
Parameters for listing the smart accounts.
Options for listing EVM smart accounts.
A promise that resolves to an array of smart accounts, and a token to paginate through the smart accounts.
Lists CDP EVM token balances.
Parameters for listing the token balances.
Options for listing EVM token balances.
The address of the account.
The network.
Optional
pageSize?: numberThe page size to paginate through the token balances.
Optional
pageToken?: stringThe page token to paginate through the token balances.
A promise that resolves to an array of token balances, and a token to paginate through the token balances.
const tokenBalances = await cdp.evm.listTokenBalances({
address: "0x1234567890123456789012345678901234567890",
network: "base-sepolia",
});
With pagination
let page = await cdp.evm.listTokenBalances({
address: "0x1234567890123456789012345678901234567890",
network: "base-sepolia",
});
while (page.nextPageToken) {
page = await cdp.evm.listTokenBalances({
address: "0x1234567890123456789012345678901234567890",
network: "base-sepolia",
pageToken: page.nextPageToken,
});
Prepares a user operation for a smart account.
Parameters for preparing the user operation.
Options for preparing a user operation.
The calls.
The network.
Optional
paymasterUrl?: stringThe paymaster URL.
The smart account.
A promise that resolves to the user operation hash.
Requests funds from an EVM faucet.
Parameters for requesting funds from the EVM faucet.
Options for requesting funds from an EVM faucet.
A promise that resolves to the transaction hash.
Signs an EVM transaction and sends it to the specified network using the Coinbase API. This method handles nonce management and gas estimation automatically.
Configuration options for sending the transaction.
A promise that resolves to the transaction hash.
Sending an RLP-encoded transaction
import { parseEther, serializeTransaction } from "viem";
import { baseSepolia } from "viem/chains";
const { transactionHash } = await cdp.evm.sendTransaction({
address: account.address,
transaction: serializeTransaction({
to: "0x4252e0c9A3da5A2700e7d91cb50aEf522D0C6Fe8",
value: parseEther("0.000001"),
chainId: baseSepolia.id,
// Fields below are optional, CDP API will populate them if omitted.
// nonce
// maxPriorityFeePerGas
// maxFeePerGas
// gas
}),
network: "base-sepolia",
});
Sending an EIP-1559 transaction request object
const { transactionHash } = await cdp.evm.sendTransaction({
address: account.address,
transaction: {
to: "0x4252e0c9A3da5A2700e7d91cb50aEf522D0C6Fe8",
value: parseEther("0.000001"),
// Fields below are optional, CDP API will populate them if omitted.
// nonce
// maxPriorityFeePerGas
// maxFeePerGas
// gas
},
network: "base-sepolia",
});
Sends a user operation.
Parameters for sending the user operation.
Options for sending a user operation.
The calls.
Optional
idempotencyKey?: stringThe idempotency key.
The network.
Optional
paymasterUrl?: stringThe paymaster URL.
The smart account.
A promise that resolves to an object containing the smart account address, the user operation hash, and the status of the user operation.
Signs an EVM hash.
Parameters for signing the hash.
Options for signing an EVM hash.
A promise that resolves to the signature.
Signs an EVM message.
Parameters for signing the message.
Options for signing an EVM message.
A promise that resolves to the signature.
Signs an EVM transaction.
Configuration options for signing the transaction.
A promise that resolves to the signature.
import { parseEther, serializeTransaction } from "viem";
import { baseSepolia } from "viem/chains";
// Create a new EVM server account to sign with
const ethAccount = await cdp.createEvmServerAccount({});
const serializedTx = serializeTransaction(
{
chainId: baseSepolia.id,
data: "0x",
to: "0x4252e0c9A3da5A2700e7d91cb50aEf522D0C6Fe8",
type: "eip1559",
value: parseEther("0.000001"),
},
);
const signature = await cdp.evm.signTransaction({
address: ethAccount.address,
transaction: serializedTx,
});
Waits for a user operation to complete or fail.
Parameters for waiting for the user operation.
Options for waiting for a user operation.
The smart account address.
The user operation hash.
Optional
waitOptions?: WaitOptionsThe wait options.
A promise that resolves to the transaction receipt.
// Send a user operation and get the user operation hash
const { userOpHash } = await cdp.evm.sendUserOperation({
smartAccount,
network: "base-sepolia",
calls: [
{
to: "0x0000000000000000000000000000000000000000",
value: parseEther("0.000001"),
data: "0x",
},
],
});
// Wait for the user operation to complete or fail
const result = await cdp.evm.waitForUserOperation({
smartAccountAddress: smartAccount.address,
userOpHash: userOp.userOpHash,
});
The namespace containing all EVM methods.