A representation of a Wallet. Wallets come with a single default Address, but can expand to have a set of Addresses, each of which can hold a balance of one or more Assets. Wallets can create new Addresses, list their addresses, list their balances, and transfer Assets to other Addresses. Wallets should be created through User.createWallet or User.importWallet. Wallets should be created using Wallet.create, imported using Wallet.import, or fetched using Wallet.fetch. Existing wallets can be imported with a seed using Wallet.import. Wallets backed by a Server Signer can be fetched with Wallet.fetch and used for signing operations immediately.

Properties

addressPathPrefix: "m/44'/60'/0'/0" = "m/44'/60'/0'/0"
addresses: WalletAddress[] = []
master?: HDKey
model: Wallet
seed?: string
MAX_ADDRESSES: number = 20

Methods

  • Returns a WalletAddress object for the given AddressModel.

    Parameters

    • addressModel: Address

      The AddressModel to build the WalletAddress from.

    • index: number

      The index of the AddressModel.

    Returns WalletAddress

    The WalletAddress object.

  • Returns whether the Wallet has a seed with which to derive keys and sign transactions.

    Returns boolean

    Whether the Wallet has a seed with which to derive keys and sign transactions.

  • Get the claimable balance for the supplied asset.

    Parameters

    • asset_id: string

      The asset to check claimable balance for.

    • mode: StakeOptionsMode = StakeOptionsMode.DEFAULT

      The staking mode. Defaults to DEFAULT.

    • options: {
          [key: string]: string;
      } = {}

      Additional options for getting the claimable balance.

      • [key: string]: string

    Returns Promise<Decimal>

    The claimable balance.

    Throws

    if the default address is not found.

  • Creates an attestation for the Address currently being created.

    Parameters

    • key: HDKey

      The key of the Wallet.

    Returns string

    The attestation.

  • Creates a staking operation to claim stake, signs it, and broadcasts it on the blockchain.

    Parameters

    • amount: Amount

      The amount for the staking operation.

    • assetId: string

      The asset for the staking operation.

    • mode: StakeOptionsMode = StakeOptionsMode.DEFAULT

      The staking mode. Defaults to DEFAULT.

    • options: {
          [key: string]: string;
      } = {}

      Additional options such as setting the mode for the staking action.

      • [key: string]: string
    • timeoutSeconds: number = 60

      The amount to wait for the transaction to complete when broadcasted.

    • intervalSeconds: number = 0.2

      The amount to check each time for a successful broadcast.

    Returns Promise<StakingOperation>

    The staking operation after it's completed fully.

    Throws

    if the default address is not found.

  • Creates a Payload Signature.

    Parameters

    • unsignedPayload: string

      The Unsigned Payload to sign.

    Returns Promise<PayloadSignature>

    A promise that resolves to the Payload Signature object.

    Throws

    if the API request to create a Payload Signature fails.

    Throws

    if the default address is not found.

  • Creates a staking operation to stake, signs it, and broadcasts it on the blockchain.

    Parameters

    • amount: Amount

      The amount for the staking operation.

    • assetId: string

      The asset for the staking operation.

    • mode: StakeOptionsMode = StakeOptionsMode.DEFAULT

      The staking mode. Defaults to DEFAULT.

    • options: {
          [key: string]: string;
      } = {}

      Additional options such as setting the mode for the staking action.

      • [key: string]: string
    • timeoutSeconds: number = 60

      The amount to wait for the transaction to complete when broadcasted.

    • intervalSeconds: number = 0.2

      The amount to check each time for a successful broadcast.

    Returns Promise<StakingOperation>

    The staking operation after it's completed fully.

    Throws

    if the default address is not found.

  • Trades the given amount of the given Asset for another Asset. Currently only the default address is used to source the Trade.

    Parameters

    Returns Promise<Trade>

    The created Trade object.

    Throws

    If the default address is not found.

    Throws

    If the private key is not loaded, or if the asset IDs are unsupported, or if there are insufficient funds.

  • Transfers the given amount of the given Asset to the given address. Only same-Network Transfers are supported. Currently only the default_address is used to source the Transfer.

    Parameters

    Returns Promise<Transfer>

    The created Transfer object.

    Throws

    if the API request to create a Transfer fails.

    Throws

    if the API request to broadcast a Transfer fails.

  • Creates a staking operation to unstake, signs it, and broadcasts it on the blockchain.

    Parameters

    • amount: Amount

      The amount for the staking operation.

    • assetId: string

      The asset for the staking operation.

    • mode: StakeOptionsMode = StakeOptionsMode.DEFAULT

      The staking mode. Defaults to DEFAULT.

    • options: {
          [key: string]: string;
      } = {}

      Additional options such as setting the mode for the staking action.

      • [key: string]: string
    • timeoutSeconds: number = 60

      The amount to wait for the transaction to complete when broadcasted.

    • intervalSeconds: number = 0.2

      The amount to check each time for a successful broadcast.

    Returns Promise<StakingOperation>

    The staking operation after it's completed successfully.

    Throws

    if the default address is not found.

  • Creates a Webhook for a wallet, monitors all wallet addresses for onchain events.

    Parameters

    • notificationUri: string

      The URI to which the webhook notifications will be sent.

    Returns Promise<Webhook>

    The newly created webhook instance.

  • Deploys an ERC1155 token contract.

    Parameters

    Returns Promise<SmartContract>

    A Promise that resolves to the deployed SmartContract object.

    Throws

    If the private key is not loaded when not using server signer.

  • Deploys an ERC721 token contract.

    Parameters

    Returns Promise<SmartContract>

    A Promise that resolves to the deployed SmartContract object.

    Throws

    If the private key is not loaded when not using server signer.

  • Deploys an ERC20 token contract.

    Parameters

    Returns Promise<SmartContract>

    A Promise that resolves to the deployed SmartContract object.

    Throws

    If the private key is not loaded when not using server signer.

  • Derives a key for an already registered Address in the Wallet.

    Parameters

    • index: number

      The index of the Address to derive.

    Returns HDKey

    The derived key.

    Throws

    • If the key derivation fails.
  • Requests funds from the faucet for the Wallet's default address and returns the faucet transaction. This is only supported on testnet networks.

    Parameters

    • Optional assetId: string

      The ID of the Asset to request from the faucet.

    Returns Promise<FaucetTransaction>

    The successful faucet transaction

    Throws

    If the default address is not found.

    Throws

    If the request fails.

  • Returns the WalletAddress with the given ID.

    Parameters

    • addressId: string

      The ID of the WalletAddress to retrieve.

    Returns Promise<undefined | WalletAddress>

    The WalletAddress.

  • Returns the balance of the provided Asset. Balances are aggregated across all Addresses in the Wallet.

    Parameters

    • assetId: string

      The ID of the Asset to retrieve the balance for.

    Returns Promise<Decimal>

    The balance of the Asset.

  • Gets the key for encrypting seed data.

    For EC keys (PEM format), it uses crypto.diffieHellman. For Ed25519 keys (assumed to be a base64-encoded 64-byte string), it converts the secret key to an X25519 key using ed2curve.

    Returns Buffer

    The encryption key.

  • Loads the seed data from the given file.

    Parameters

    • filePath: string

      The path of the file to load the seed data from

    Returns Record<string, SeedData>

    The seed data

  • Lists the historical staking balances for the address.

    Parameters

    • assetId: string

      The asset ID.

    • startTime: string = ...

      The start time.

    • endTime: string = ...

      The end time.

    Returns Promise<StakingBalance[]>

    The staking balances.

    Throws

    if the default address is not found.

  • Returns the list of balances of this Wallet. Balances are aggregated across all Addresses in the Wallet.

    Returns Promise<BalanceMap>

    The list of balances. The key is the Asset ID, and the value is the balance.

  • Loads the seed of the Wallet from the given file.

    Parameters

    • filePath: string

      The path of the file to load the seed from

    Returns Promise<string>

    A string indicating the success of the operation

    Deprecated

    Use loadSeedFromFile() instead

  • Loads the seed of the Wallet from the given file.

    Parameters

    • filePath: string

      The path of the file to load the seed from

    Returns Promise<string>

    A string indicating the success of the operation

  • Get the pending claimable balance for the supplied asset.

    Parameters

    • asset_id: string

      The asset to check pending claimable balance for.

    • mode: StakeOptionsMode = StakeOptionsMode.DEFAULT

      The staking mode. Defaults to DEFAULT.

    • options: {
          [key: string]: string;
      } = {}

      Additional options for getting the pending claimable balance.

      • [key: string]: string

    Returns Promise<Decimal>

    The pending claimable balance.

    Throws

    if the default address is not found.

  • Get a quote for funding the wallet from your Coinbase platform account.

    Parameters

    Returns Promise<FundQuote>

    The fund quote object

    Throws

    If the default address does not exist

  • Reloads the Wallet model with the latest data from the server.

    Returns Promise<void>

    Throws

    if the API request to get a Wallet fails.

  • Saves the seed of the Wallet to the given file.

    Parameters

    • filePath: string

      The path of the file to save the seed to

    • encrypt: boolean = false

      Whether the seed information persisted to the local file system should be encrypted or not. Data is unencrypted by default.

    Returns string

    A string indicating the success of the operation

    Deprecated

    Use saveSeedToFile() instead

    Throws

    If the Wallet does not have a seed

  • Saves the seed of the Wallet to the given file. Wallets whose seeds are saved this way can be rehydrated using load_seed. A single file can be used for multiple Wallet seeds. This is an insecure method of storing Wallet seeds and should only be used for development purposes.

    Parameters

    • filePath: string

      The path of the file to save the seed to

    • encrypt: boolean = false

      Whether the seed information persisted to the local file system should be encrypted or not. Data is unencrypted by default.

    Returns string

    A string indicating the success of the operation

    Throws

    If the Wallet does not have a seed

  • Sets the master node for the given seed, if valid. If the seed is undefined it will set the master node using a random seed.

    Parameters

    • seed: undefined | string

      The seed to use for the Wallet.

    Returns undefined | HDKey

    The master node for the given seed.

  • Set the seed for the Wallet.

    Parameters

    • seed: string

      The seed to use for the Wallet. Expects a 32-byte hexadecimal with no 0x prefix.

    Returns void

    Throws

    If the seed is empty.

    Throws

    If the seed is already set.

  • Get the stakeable balance for the supplied asset.

    Parameters

    • asset_id: string

      The asset to check the stakeable balance for.

    • mode: StakeOptionsMode = StakeOptionsMode.DEFAULT

      The staking mode. Defaults to DEFAULT.

    • options: {
          [key: string]: string;
      } = {}

      Additional options for getting the stakeable balance.

      • [key: string]: string

    Returns Promise<Decimal>

    The stakeable balance.

    Throws

    if the default address is not found.

  • Lists the staking rewards for the address.

    Parameters

    • assetId: string

      The asset ID.

    • startTime: string = ...

      The start time.

    • endTime: string = ...

      The end time.

    • format: StakingRewardFormat = StakingRewardFormat.USD

      The format to return the rewards in. (usd, native). Defaults to usd.

    Returns Promise<StakingReward[]>

    The staking rewards.

    Throws

    if the default address is not found.

  • Returns a String representation of the Wallet.

    Returns string

    a String representation of the Wallet

  • Get the unstakeable balance for the supplied asset.

    Parameters

    • asset_id: string

      The asset to check the unstakeable balance for.

    • mode: StakeOptionsMode = StakeOptionsMode.DEFAULT

      The staking mode. Defaults to DEFAULT.

    • options: {
          [key: string]: string;
      } = {}

      Additional options for getting the unstakeable balance.

      • [key: string]: string

    Returns Promise<Decimal>

    The unstakeable balance.

    Throws

    if the default address is not found.

  • Validates the seed and address models passed to the constructor.

    Parameters

    • seed: undefined | string

      The seed to use for the Wallet

    Returns void

  • Waits until the ServerSigner has created a seed for the Wallet.

    Parameters

    • walletId: string

      The ID of the Wallet that is awaiting seed creation.

    • intervalSeconds: number = 0.2

      The interval at which to poll the CDPService, in seconds.

    • timeoutSeconds: number = 20

      The maximum amount of time to wait for the ServerSigner to create a seed, in seconds.

    Returns Promise<void>

    Throws

    if the API request to get a Wallet fails.

    Throws

    if the ServerSigner times out.

  • Creates a new Wallet with a random seed.

    Parameters

    Returns Promise<Wallet>

    A promise that resolves with the new Wallet object.

    Constructs

    Wallet

    Throws

    If the model or client is not provided.

    Throws

    • If address derivation or caching fails.

    Throws

    • If the request fails.
  • Creates a new Wallet with the given seed.

    Parameters

    Returns Promise<Wallet>

    A promise that resolves with the new Wallet object.

    Throws

    If the model or client is not provided.

    Throws

    • If address derivation or caching fails.

    Throws

    • If the request fails.
  • Fetches a Wallet by its ID. The returned wallet can be immediately used for signing operations if backed by a server signer. If the wallet is not backed by a server signer, the wallet's seed will need to be set before it can be used for signing operations.

    Parameters

    • wallet_id: string

      The ID of the Wallet to fetch

    Returns Promise<Wallet>

    The fetched Wallet

  • Loads an existing CDP Wallet using a wallet data object or mnemonic seed phrase.

    Parameters

    • data: WalletData | MnemonicSeedPhrase

      The data used to import the wallet:

      • If WalletData: Must contain walletId (or wallet_id) and seed. Allows for the loading of an existing CDP wallet into CDP.
      • If MnemonicSeedPhrase: Must contain a valid BIP-39 mnemonic phrase (12, 15, 18, 21, or 24 words). Allows for the import of an external wallet into CDP as a 1-of-1 wallet.
    • networkId: string = Coinbase.networks.BaseSepolia

      the ID of the blockchain network. Defaults to 'base-sepolia'.

    Returns Promise<Wallet>

    A Promise that resolves to the loaded Wallet instance

    Throws

    If the data format is invalid.

    Throws

    If the seed is not provided.

    Throws

    If the mnemonic seed phrase is invalid.

  • Returns a new Wallet object. Do not use this method directly. Instead, use one of:

    • Wallet.create (Create a new Wallet),
    • Wallet.import (Import a Wallet with seed),
    • Wallet.fetch (fetch a Wallet by ID w/o seed, useful for server signer wallets).

    Parameters

    • model: Wallet

      The underlying Wallet model object

    • Optional seed: string

      The seed to use for the Wallet. Expects a 32-byte hexadecimal with no 0x prefix. If null or undefined, a new seed will be generated. If the empty string, no seed is generated, and the Wallet will be instantiated without a seed and its corresponding private keys.

    Returns Wallet

    A promise that resolves with the new Wallet object.

    Constructs

    Wallet

    Throws

    If the model or client is not provided.

    Throws

    • If address derivation or caching fails.

    Throws

    • If the request fails.